-
Notifications
You must be signed in to change notification settings - Fork 8
185 lines (175 loc) · 6.67 KB
/
static_analyses.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
name: Static Analyses
on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
merge_group:
types: [checks_requested]
# Cancel old static analyses if new pushes are added to the branch
concurrency:
group: ${{ github.workflow }}-${{ github.action.number }}
cancel-in-progress: true
jobs:
Indentation:
name: Clang Formatting Check
runs-on: ubuntu-latest
container:
image: ghcr.io/gyselax/gyselalibxx_env
options: --user 1001
steps:
- uses: actions/checkout@v4
- shell: bash
run: |
./bin/indent -td
Markdown:
name: Markdown format check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Get Python dependencies
run: |
pip install numpy
- name: Check files
id: markdown
continue-on-error: true
shell: bash
run: |
MARKDOWN_FILES=$(find . -name "*.md" -not -path "./vendor/*")
MARKDOWN_FILES="$MARKDOWN_FILES $(find ./vendor/sll/ -name '*.md')"
echo $MARKDOWN_FILES
python3 ci_tools/markdown_linter.py ${MARKDOWN_FILES}
echo "EXIT_CODE=$?" >> $GITHUB_OUTPUT
- name: Check error code
shell: python
run: |
assert ${{ steps.markdown.outputs.EXIT_CODE }} in (0, 2)
Python:
name: Python Best Practices
runs-on: ubuntu-latest
container:
image: ghcr.io/gyselax/gyselalibxx_env
options: --user 1001
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run pylint
run: |
pylint $(find tests -iname *.py)
pylint $(find doc -iname *.py)
pylint $(find ci_tools -iname *.py)
shell: bash
env:
PYTHONPATH: ./post-process/PythonScripts
- name: Run filtered pylint
run: |
# Find all files with no extension or a .py extension in post-process/PythonScripts/
POST_PROCESS_PYTHON_FILES=$(find post-process/PythonScripts/ -type f ! -name "*.*"; find post-process/PythonScripts -iname *.py)
# Get pylint errors without failing
pylint ${POST_PROCESS_PYTHON_FILES} > post_process_errors.txt || true
# Filter errors on changed files
for f in $(git diff ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }} --name-only)
do
grep $f post_process_errors.txt || true
done | tee filtered_errors.txt
# Raise an error if post-process in filtered errors
! grep "post-process" filtered_errors.txt >/dev/null
shell: bash
env:
PYTHONPATH: ./post-process/PythonScripts
Documentation:
name: Documentation check
runs-on: ubuntu-latest
container:
image: ghcr.io/gyselax/gyselalibxx_env
options: --user 1001
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Make documenation
run: |
# Make docs
cmake -DGYSELALIBXX_COMPILE_SOURCE=OFF -DGYSELALIBXX_BUILD_DOCUMENTATION=ON -B build -S .
cmake --build build --target doc
shell: bash
- name: Check for new errors
run: |
# Get files which have changed in this merge request
git diff ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}..${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha }} --no-indent-heuristic --unified=0 --output=pull_diff.txt --no-color
# Filter documentation messages to only complain about modified files
python3 ci_tools/check_documentation.py pull_diff.txt build/docs/doxygen.log
git diff ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}..${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha }} --no-indent-heuristic --unified=0 --output=pull_new_files.txt --no-color --diff-filter=A
python3 ci_tools/check_readme_presence.py pull_new_files.txt
shell: bash
cppcheck_static_analysis_errors:
name: CppCheck static analysis errors
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- uses: ./.github/actions/linux_static_analysis_install
- uses: ./.github/actions/python-static-analysis-setup
- uses: ./.github/actions/test_filter
with:
base_sha: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
trigger_type: ${{ github.event_name }}
- run: |
python3 ci_tools/gyselalib_static_analysis.py ${CHANGED_FILES} --errors-only
cppcheck_static_analysis_warnings:
name: CppCheck static analysis warnings
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- uses: ./.github/actions/linux_static_analysis_install
- uses: ./.github/actions/python-static-analysis-setup
- uses: ./.github/actions/test_filter
with:
base_sha: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
trigger_type: ${{ github.event_name }}
- run: |
python3 ci_tools/gyselalib_static_analysis.py ${CHANGED_FILES}
cmake_static_analysis:
name: CMake static analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- run: |
python3 ci_tools/cmake_checker.py
set_draft_failing:
runs-on: ubuntu-latest
needs: [Indentation, Markdown, Python, Documentation, cppcheck_static_analysis_errors, cmake_static_analysis]
if: github.event_name == 'pull_request' && failure()
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Set PR to draft to avoid unnecessary runs
run: |
isDraft=$(gh pr view ${{ github.event.pull_request.number }} --json isDraft | jq ."isDraft")
if [[ "${isDraft}" != "true" ]]
then
gh pr ready ${{ github.event.pull_request.number }} --undo
gh pr comment ${{ github.event.pull_request.number }} -b "This PR is failing tests so it has been put back into draft. Please remove the draft status when the tests pass."
gh pr edit ${{ github.event.pull_request.number }} --remove-label "Ready to review"
fi
shell: bash
env:
GH_TOKEN: ${{ github.token }}