-
Notifications
You must be signed in to change notification settings - Fork 185
256 lines (217 loc) · 9.47 KB
/
repo_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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
on:
workflow_dispatch:
pull_request:
merge_group:
types:
- checks_requested
name: "Basic content checks"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
links:
runs-on: ubuntu-latest
name: "Check links"
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Convert reStructuredText files to Markdown
run: |
pip install "rst-to-myst[sphinx]==0.4.0"
find docs/sphinx/ -type f -name "*.rst" -print0 | xargs -0 rst2myst convert --raise-on-warning
- name: Check links in Markdown files
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-verbose-mode: "yes"
config-file: ".github/workflows/config/md_link_check_config.json"
license_headers:
name: Check license headers
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: apache/skywalking-eyes/[email protected]
with:
config: .licenserc.yaml
token: '' # with the appropriate permission license eye can add comments on the PR
filters:
name: Filter files to check
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
json: ${{ steps.files.outputs.json }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: ${{ (github.event_name == 'pull_request' && '0') || '1' }}
- id: files
run: |
if ${{ github.event_name == 'pull_request' }}; then
diff_base=${{ github.event.pull_request.base.sha }}
git rev-list HEAD..$diff_base # fails the step if something went wrong
list_files="git diff --diff-filter=d --name-only $diff_base --"
echo "## Changed Files" >> $GITHUB_STEP_SUMMARY
echo "The following files contain changes:" >> $GITHUB_STEP_SUMMARY
for file in `$list_files`; do
echo "$file" >> $GITHUB_STEP_SUMMARY
done
else
list_files="git ls-files"
fi
json="{\"files\":{}, \"patterns\":{}}"
function create_output {
json=`echo $json | jq ".patterns |= . + {"$1":[]}"`
for pattern in $2; do
pattern=\'$pattern\'
json=`echo $json | jq ".patterns.$1 |= . + [\"$pattern\"]"`
done
json=`echo $json | jq ".files |= . + {"$1":[]}"`
for file in `echo $2 | xargs $list_files`; do
file=\'$file\'
json=`echo $json | jq ".files.$1 |= . + [\"$file\"]"`
done
}
create_output cxx '*.cpp *.h *.hpp :!:test :!:targettests :!:tpls :!:**/nlopt-src/*'
create_output cxx_headers '*.h *.hpp :!:test :!:targettests :!:tpls :!:**/nlopt-src/*'
create_output cxx_examples 'docs/sphinx/examples/**/*.cpp' 'docs/sphinx/applications/cpp/*.cpp' 'docs/sphinx/targets/cpp/*.cpp'
create_output python '*.py :!:python/tests :!:test :!:targettests :!:tpls :!:docs/sphinx/conf.py'
create_output markdown '*.md :!:tpls'
create_output rst '*.rst :!:tpls :!:docs/sphinx/_templates/**/*.rst'
echo "json=$(echo $json)" >> $GITHUB_OUTPUT
formatting:
name: Check code formatting
runs-on: ubuntu-latest
needs: filters
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: C++
run: |
echo "## C++ Formatting" >> $GITHUB_STEP_SUMMARY
files=(${{ join(fromJSON(needs.filters.outputs.json).files.cxx, ' ') }})
if [ "${#files[@]}" -gt "0" ]; then
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main"
sudo apt-get update && sudo apt-get install -y --no-install-recommends clang-format-16
echo ${files[@]} | xargs clang-format-16 -i
echo ${{ join(fromJSON(needs.filters.outputs.json).patterns.cxx, ' ') }} \
| xargs git diff --diff-filter=d -- > /tmp/clang-format.patch
else
echo "No files to check." >> $GITHUB_STEP_SUMMARY
exit 0
fi
if [ -s /tmp/clang-format.patch ]; then
echo "The following formatting changes need to be applied:" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat /tmp/clang-format.patch >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "Totally checked ${#files[@]} files. All files are formatted as expected." >> $GITHUB_STEP_SUMMARY
fi
- name: Python
run: |
echo "## Python Formatting" >> $GITHUB_STEP_SUMMARY
files=(${{ join(fromJSON(needs.filters.outputs.json).files.python, ' ') }})
if [ "${#files[@]}" -gt "0" ]; then
pip install yapf
echo ${files[@]} | xargs yapf --style google --recursive -i
echo ${{ join(fromJSON(needs.filters.outputs.json).patterns.python, ' ') }} \
| xargs git diff --diff-filter=d -- > /tmp/yapf.patch
else
echo "No files to check." >> $GITHUB_STEP_SUMMARY
exit 0
fi
if [ -s /tmp/yapf.patch ]; then
echo "The following formatting changes need to be applied:" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat /tmp/yapf.patch >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "Totally checked ${#files[@]} files. All files are formatted as expected." >> $GITHUB_STEP_SUMMARY
fi
- name: Markdown
uses: nosborn/[email protected]
with:
files: .
config_file: '.github/workflows/config/md_lint_config.yml'
spelling:
name: Check spelling
runs-on: ubuntu-latest
needs: filters
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Check spelling allowlist
run: |
for file in `ls .github/workflows/config/spelling_allowlist*.txt`; do
sorted_allowlist=`cat $file | sort`
if [ "$sorted_allowlist" != "$(cat $file)" ]; then
echo "Expecting spelling allowlist in $file to be sorted."
exit 1
fi
done
- name: "Markdown files"
uses: rojopolis/[email protected]
with:
config_path: '.github/workflows/config/spellcheck_config.yml'
output_file: markdown_spellcheck.txt
task_name: markdown
source_files: ${{ join(fromJSON(needs.filters.outputs.json).files.markdown, ' ') || '*.nonexistent' }}
- name: "reStructuredText files"
uses: rojopolis/[email protected]
with:
config_path: '.github/workflows/config/spellcheck_config.yml'
output_file: rst_spellcheck.txt
task_name: rst
source_files: ${{ join(fromJSON(needs.filters.outputs.json).files.rst, ' ') || '*.nonexistent' }}
- name: "C++ files (headers)"
uses: rojopolis/[email protected]
with:
config_path: '.github/workflows/config/spellcheck_config.yml'
output_file: cxx_headers_spellcheck.txt
task_name: cxx_headers
source_files: ${{ join(fromJSON(needs.filters.outputs.json).files.cxx_headers, ' ') || '*.nonexistent' }}
- name: "C++ files (examples)"
uses: rojopolis/[email protected]
with:
config_path: '.github/workflows/config/spellcheck_config.yml'
output_file: cxx_examples_spellcheck.txt
task_name: cxx_examples
source_files: ${{ join(fromJSON(needs.filters.outputs.json).files.cxx_examples, ' ') || '*.nonexistent' }}
- name: "Python files"
uses: rojopolis/[email protected]
with:
config_path: '.github/workflows/config/spellcheck_config.yml'
output_file: python_spellcheck.txt
task_name: python
source_files: ${{ join(fromJSON(needs.filters.outputs.json).files.python, ' ') || '*.nonexistent' }}
- name: Create summary
run: |
function create_summary {
status=`cat $2_spellcheck.txt | grep "Spelling check" | cut -d ' ' -f 3 | tr -d '!'`
if [ "$status" == "passed" ]; then echo 0; else echo 1; fi
echo "## $1 Check" >> $GITHUB_STEP_SUMMARY
echo "Spell check ${status}." >> $GITHUB_STEP_SUMMARY
echo "Output for $1 files:" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat $2_spellcheck.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
}
md_status=`create_summary Markdown markdown`
rst_status=`create_summary reStructuredText rst`
cxx_h_status=`create_summary "C++ Headers" cxx_headers`
cxx_ex_status=`create_summary "C++ Examples" cxx_examples`
py_status=`create_summary Python python`
if [ ! "$md_status" -eq 0 ]; then exit 1; fi
if [ ! "$rst_status" -eq 0 ]; then exit 2; fi
if [ ! "$cxx_h_status" -eq 0 ]; then exit 3; fi
if [ ! "$cxx_ex_status" -eq 0 ]; then exit 4; fi
if [ ! "$py_status" -eq 0 ]; then exit 5; fi