-
Notifications
You must be signed in to change notification settings - Fork 59
214 lines (192 loc) · 7.8 KB
/
PR-checks.yml
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: on PR
# This workflow is triggered on pull requests to the repository.
# It runs a job to check for broken links in the files changed in the PR against the online built webpage, and against the files on the PR branch.
# It checks for spelling errors in the files changed in the PR.
# It builds the static site and checks the size of the built site.
on:
pull_request
jobs:
build:
name: 📦 Build
runs-on: ubuntu-latest
outputs:
html_lychee_exited: ${{ steps.stringify.outputs.lychee_exited }}
html_lychee_file: ${{ steps.stringify.outputs.lychee_file }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- run: pip install nbconvert packaging
- name: Convert Jupyter notebooks
run: |
shopt -s globstar
jupyter-nbconvert --to markdown **/*.ipynb --ExtractOutputPreprocessor.enabled=False
shopt -u globstar
shell: bash
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install vuepress
run: yarn global add vuepress
- name: Install package.json
run: yarn
- name: Build static site with vuepress
# alias for vuepress build src defined in package.json
run: yarn build
- name: Get size of files in dist
shell: bash
run: |
du -ah src/.vuepress/dist
- name: 'Get built html files'
id: html-files
run: |
html_files=$(find src/.vuepress/dist -name '*.html')
html_files="${html_files//$'\n'/ }"
html_files="${html_files//$'\r'/ }"
echo $html_files
echo "all_html_files=${html_files}" >> $GITHUB_OUTPUT
- name: 'Check Links'
id: lychee
uses: lycheeverse/[email protected]
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
args: -v -n -a 403,503,429,200 -i -b 'src/.vuepress/dist' --exclude-mail --include-verbatim -- ${{ steps.html-files.outputs.all_html_files }}
output: ./lychee/htmlfiles.md
jobSummary: true
- name: 'Outputs as strings'
id: stringify
run: |
EXIT_CODE_STRING="$( printf '%d' "${{ env.lychee_exit_code }}" )"
echo "lychee_exited=${EXIT_CODE_STRING}" >> $GITHUB_OUTPUT
MD_OUT="$( cat ./lychee/htmlfiles.md )"
MD_OUT="${MD_OUT//'%'/'%25'}"
MD_OUT="${MD_OUT//$'\n'/'%0A'}"
MD_OUT="${MD_OUT//$'\r'/'%0D'}"
echo "text<<EOF" >> $GITHUB_OUTPUT
echo "$MD_OUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "lychee_file=${MD_OUT}" >> $GITHUB_OUTPUT
check_links_on_pr_files_online:
runs-on: ubuntu-latest
name: 🌍 Test (.md/ipynb) changed-files for broken links
outputs:
lychee_exited: ${{ steps.stringify.outputs.lychee_exited }}
lychee_file: ${{ steps.stringify.outputs.lychee_file }}
steps:
# Compares the default generated "test merge commit" by Github of the PR branch into the base branch
- uses: actions/checkout@v3
with:
fetch-depth: 2
# Gets a list of files from the PR with a git status of Added (A) or Modified (M) | (via outputs.all_changed_files)
- name: 'Get a list of changed files to process(Only html/md/ipynb files)'
id: get-changed-files
uses: tj-actions/changed-files@v34
with:
files: |
**/*.md
**/*.ipynb
separator: ','
# lychee-action requires pre-processing for file paths with spaces (boundary quotes added in lychee-action input):
- name: 'Quote wrap paths to support spaces'
id: changed-files
run: |
QUOTE_WRAPPED="$( sed "s/,/' '/g" <<< '${{ steps.get-changed-files.outputs.all_changed_files }}' )"
echo "all_changed_files=${QUOTE_WRAPPED}" >> $GITHUB_OUTPUT
- name: 'Check Links'
id: lychee
uses: lycheeverse/[email protected]
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
args: -v -n -a 403,503,429,200 -i -b 'https://docs.pupil-labs.com/' --exclude-mail --include-verbatim -- '${{ steps.changed-files.outputs.all_changed_files }}'
output: ./lychee/results.md
jobSummary: true
- name: 'Outputs as strings'
id: stringify
run: |
EXIT_CODE_STRING="$( printf '%d' "${{ env.lychee_exit_code }}" )"
echo "lychee_exited=${EXIT_CODE_STRING}" >> $GITHUB_OUTPUT
MD_OUT="$( cat ./lychee/results.md )"
MD_OUT="${MD_OUT//'%'/'%25'}"
MD_OUT="${MD_OUT//$'\n'/'%0A'}"
MD_OUT="${MD_OUT//$'\r'/'%0D'}"
echo "text<<EOF" >> $GITHUB_OUTPUT
echo "$MD_OUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "lychee_file=${MD_OUT}" >> $GITHUB_OUTPUT
check_failed_links_using_new_branch_url:
if: contains(['2'],${{ needs.check_links_on_pr_files_online.outputs.lychee_exited }})
runs-on: ubuntu-latest
name: 🐙 Test failed links using branch url
needs: [check_links_on_pr_files_online, build]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v6
- name: 'Get branch url'
id: git-branch-name
run: |
url="https://github.com/"
url+=${{github.repository}}
url+="/tree/"
url+=${{ steps.branch-name.outputs.current_branch }}
url+="/src/"
echo "branch_name=${url}" >> $GITHUB_OUTPUT
- name: 'Get broken URLs from results.md'
id: get-broken-urls
run: |
broken_urls=""
if [ ${{ needs.check_links_on_pr_files_online.outputs.lychee_exited }} == 2 ]
then
broken_urls+="${{ needs.check_links_on_pr_files_online.outputs.lychee_file }}"
fi
if [ ${{ needs.build.outputs.html_lychee_exited }} == 2 ]
then
broken_urls+="${{ needs.build.outputs.html_lychee_file }}"
fi
broken_urls=$(echo "$broken_urls" | sed "s/%25/%/g")
body=$(echo "$broken_urls" | sed "s/%0A/$'\n'/g")
broken_urls=$(echo "$broken_urls" | sed "s/%0D/$'\r'/g")
broken_urls=$(echo "$broken_urls" | sed "s/https:\/\/docs.pupil-labs.com\///g")
echo ${broken_urls}
mkdir -p temp
echo ${broken_urls} > temp/broken_urls.md
- name: 'Test again these broken links with the new branch url'
id: lychee
uses: lycheeverse/[email protected]
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
args: -v -n -a 403,503,429,200 -i -b '${{ steps.git-branch-name.outputs.branch_name }}' --exclude-mail --include-verbatim temp/broken_urls.md
output: ./lychee/results_final.md
jobSummary: true
fail: true
check_spelling:
name: ✍️ Check spelling
runs-on: ubuntu-latest
outputs:
fail_spelling: ${{ steps.fail.outputs.fail_spelling }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: 'Check Grammar'
id: cspell
uses: streetsidesoftware/cspell-action@v2
with:
files: |
**/*.{md,html,ipynb}
strict: false
verbose: true
- name: 'Fail if spelling errors are found'
id: fail
if: steps.cspell.outputs.number_of_issues > 0
run: |
echo "fail_spelling="Spelling errors found" >> $GITHUB_OUTPUT
exit 1