-
Notifications
You must be signed in to change notification settings - Fork 1.8k
145 lines (130 loc) · 5.33 KB
/
doc-tests.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Lint (Docs)
run-name: Lint (Docs)
on:
pull_request:
merge_group:
jobs:
changes:
name: Check for relevant changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
changed: ${{ steps.changes.outputs.changed }}
changed_files: ${{ steps.changes.outputs.changed_files }}
steps:
- name: Checkout
if: ${{ github.event_name == 'merge_group' }}
uses: actions/checkout@v4
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changes
with:
base: ${{ github.event.pull_request.base.ref || github.event.merge_group.base_ref }}
ref: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }}
list-files: csv
filters: |
changed:
- '.github/workflows/doc-tests.yaml'
- 'CHANGELOG.md'
- 'docs/**'
- 'examples/**'
doc-tests:
name: Lint (Docs)
needs: changes
if: ${{ !startsWith(github.head_ref, 'dependabot/') && needs.changes.outputs.changed == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: "gravitational/docs"
path: "docs"
# Cache node_modules. Unlike the example in the actions/cache repo, this
# caches the node_modules directory instead of the yarn cache. This is
# because yarn needs to build fresh packages even when it copies files
# from the yarn cache into node_modules.
# See:
# https://github.com/actions/cache/blob/main/examples.md#node---yarn
- uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: '${{ github.workspace }}/docs/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles(format('{0}/docs/yarn.lock', github.workspace)) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install docs site dependencies
working-directory: docs
if: ${{ steps.yarn-cache.outputs.cache-hit != 'true' }}
# Prevent occasional `yarn install` executions that run indefinitely
timeout-minutes: 10
run: yarn install
- name: Prepare docs site configuration
# The environment we use for linting the docs differs from the one we
# use for the live docs site in that we only test a single version of
# the content.
#
# To do this, we replace the three submodules we use for building the
# live docs site with a single submodule, pointing to the
# gravitational/teleport branch we are linting.
#
# The docs engine expects a config.json file at the root of the
# gravitational/docs clone that associates directories with git
# submodules. By default, these directories represent versioned branches
# of gravitational/teleport. We override this in order to build only a
# single version of the docs.
run: |
if [ $GITHUB_EVENT_NAME = "pull_request" ]; then
BRANCH=$GITHUB_HEAD_REF;
elif [ $GITHUB_EVENT_NAME = "merge_group" ]; then
# GitHub populates $GITHUB_REF with:
# refs/heads/gh-readonly-queue/<base branch>/pr-<PR number>-<SHA>
#
# We strip the "refs/heads/" prefix so we can check out the branch.
BRANCH=$(echo $GITHUB_REF | sed -E "s|refs/heads/(.*)|\1|")
else
echo "Unexpected event name: $GITHUB_EVENT_NAME";
exit 1;
fi
cd $GITHUB_WORKSPACE/docs
echo "" > .gitmodules
rm -rf content/*
cd content
# Add a submodule at docs/content/teleport
git submodule add --force -b $BRANCH -- https://github.com/gravitational/teleport
cd $GITHUB_WORKSPACE/docs
echo "{\"versions\": [{\"name\": \"teleport\", \"branch\": \"$BRANCH\", \"deprecated\": false}]}" > $GITHUB_WORKSPACE/docs/config.json
yarn build-node
- name: Check spelling
run: cd $GITHUB_WORKSPACE/docs && yarn spellcheck content/teleport
- name: Lint the docs
run: cd $GITHUB_WORKSPACE/docs && yarn markdown-lint
- name: Test the docs build
working-directory: docs
run: yarn build
stylecheck:
name: Lint docs prose style
runs-on: ubuntu-latest
needs: changes
if: ${{ !startsWith(github.head_ref, 'dependabot/') && needs.changes.outputs.changed == 'true' && github.event_name == 'pull_request' }}
permissions:
pull-requests: read
steps:
- name: Check out the teleport repo
uses: actions/checkout@v4
with:
repository: "gravitational/teleport"
- name: Run the linter
uses: errata-ai/vale-action@d89dee975228ae261d22c15adcd03578634d429c # v2.1.1
with:
version: 2.30.0
# Take the comma-separated list of files returned by the "Check for
# relevant changes" job.
separator: ","
files: ${{ needs.changes.outputs.changed_files }}
# Restrict the linter to lines modified/added by a PR, not entire
# changed files.
filter_mode: added
fail_on_error: true
vale_flags: "--config=docs/.vale.ini"