-
Notifications
You must be signed in to change notification settings - Fork 1
277 lines (227 loc) · 10.2 KB
/
tests.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# This workflow will install Python dependencies and run tests
# For more information see:
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: tests
on: # yamllint disable-line rule:truthy
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
inputs:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
poetry-version: ["1.8.2"]
node_version: ["lts/*"]
steps:
# Setup
- name: Check out source repository
uses: actions/checkout@v4
- name: Set up poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install Python dependencies
run: poetry install --with daq,web,ana,dev
# File filters
- name: Paths changes filter
uses: dorny/paths-filter@v3
id: filter
with:
list-files: shell
filters: |
poetry:
# Do not run poetry check and lock if just the pyproject.toml file changes
# - added|modified: '**/pyproject.toml'
- added|modified: '**/poetry.lock'
python:
- added|modified: '**.py'
- added|modified: '**.ipynb'
python_alone:
- added|modified: '**.py'
javascript:
- added|modified: '**.js'
html:
- added|modified: '**.html'
prettier:
- added|modified: '**.html'
- added|modified: '**.css'
- added|modified: '**.scss'
- added|modified: '**.json'
# prettier-plugin-toml is not being properly installed on the actions runner,
# lint toml files locally
# - added|modified: '**.toml'
yaml:
- added|modified: '**.yaml'
- added|modified: '**.yml'
makefile:
- added|modified: '**/Makefile'
- added|modified: '**/makefile'
markdown:
- added|modified: '**.md'
tex:
- added|modified: '**.tex'
rst:
- added|modified: '**.rst'
any:
- added|modified: '**'
- name: Free disk space
uses: jlumbroso/free-disk-space@main
with:
# This might remove tools that are actually needed, if set to "true" but frees about 6 GB
tool-cache: false
# Does not break anything, and saves a lot of space, but runs slowly,
# do not use unless necessary, i.e. when running poetry checks.
large-packages: ${{steps.filter.outputs.poetry}}
# Needed by any dockerized GitHub action
docker-images: false
# Gets the poetry cache back
swap-storage: false
# These will be cleaned
android: true
dotnet: true
haskell: true
# Filtered setup
- name: Install Node
if: steps.filter.outputs.javascript == 'true' || steps.filter.outputs.prettier == 'true'
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
check-latest: true
- name: Install Node dependencies
if: steps.filter.outputs.javascript == 'true' || steps.filter.outputs.prettier == 'true'
run: sudo npm install --global standard@latest prettier@latest
# Use "success() || failure()" to run a step even if a previous step fails
# https://stackoverflow.com/a/58859404
# Python
- name: poetry
if: (success() || failure()) && steps.filter.outputs.poetry == 'true'
run: poetry check && poetry lock --no-update
- name: isort
if: (success() || failure()) && steps.filter.outputs.python == 'true'
run: poetry run isort ${{ steps.filter.outputs.python_files }}
- name: pyupgrade
if: (success() || failure()) && steps.filter.outputs.python == 'true'
run: poetry run pyupgrade ${{ steps.filter.outputs.python_files }}
- name: black
if: (success() || failure()) && steps.filter.outputs.python == 'true'
run: poetry run black --check --diff ${{ steps.filter.outputs.python_files }}
- name: blacken-docs
if: (success() || failure()) && (steps.filter.outputs.python == 'true' || steps.filter.outputs.markdown == 'true' || steps.filter.outputs.rst == 'true' || steps.filter.outputs.tex == 'true') # yamllint disable-line rule:line-length
run: poetry run blacken-docs --line-length=100 --target-version=py311 ${{ steps.filter.outputs.python_files }} ${{ steps.filter.outputs.markdown_files }} ${{ steps.filter.outputs.rst_files }} ${{ steps.filter.outputs.tex_files }} # yamllint disable-line rule:line-length
- name: flake8
if: (success() || failure()) && steps.filter.outputs.python == 'true'
run: |
echo "::group::version and plugins"
poetry run flake8 --version
echo "::endgroup::"
poetry run flake8 --format github ${{ steps.filter.outputs.python_files }}
# Disable: flake8-markdown does not use the pyproject.toml config correctly
# - name: flake8-markdown
# if: (success() || failure()) && steps.filter.outputs.markdown == 'true'
# run: poetry run flake8-markdown ${{ steps.filter.outputs.markdown_files }}
# https://pylint.pycqa.org/en/latest/user_guide/usage/output.html
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message
# yamllint disable rule:line-length
- name: pylint
if: (success() || failure()) && steps.filter.outputs.python_alone == 'true'
run: |
poetry run pylint --msg-template='::error file={path},line={line},endLine={end_line},col={column},endColumn={end_column},title={symbol} ({msg_id})::{obj}: {msg}' ${{ steps.filter.outputs.python_alone_files }}
# yamllint enable rule:line-length
- name: mypy
if: (success() || failure()) && steps.filter.outputs.python == 'true'
run: poetry run mypy ${{ steps.filter.outputs.python_files }}
- name: bandit
if: (success() || failure()) && steps.filter.outputs.python == 'true'
run: poetry run bandit -r ${{ steps.filter.outputs.python_files }}
- name: vulture
if: (success() || failure()) && steps.filter.outputs.python == 'true'
run: poetry run vulture . # Needs to run on whole package
- name: deptry
if: (success() || failure()) && steps.filter.outputs.python == 'true'
run: poetry run deptry . # Runs on whole package
# Javascript
- name: standard
if: (success() || failure()) && steps.filter.outputs.javascript == 'true'
run: standard ${{ steps.filter.outputs.javascript_files }}
# HTML
- name: html5validator
if: (success() || failure()) && steps.filter.outputs.html == 'true'
uses: Cyb3r-Jak3/html5validator-action@master # blocklint: pragma
with:
config: .dev_config/.html5validator.yaml
# only configurable to run on paths, so just run on whole package
# Prettier: HTML CSS SCSS JSON (TOML plugin broken in GitHub actions)
- name: prettier
if: (success() || failure()) && steps.filter.outputs.prettier == 'true'
id: prettier
run: prettier --ignore-path .dev_config/.prettierignore --ignore-path .gitignore --config .dev_config/.prettierrc.yaml --check ${{ steps.filter.outputs.prettier_files }} # yamllint disable-line rule:line-length
# YAML
- name: yamllint
if: (success() || failure()) && steps.filter.outputs.yaml == 'true'
run: poetry run yamllint --format github -c .dev_config/.yamllint.yaml --strict ${{ steps.filter.outputs.yaml_files }} # yamllint disable-line rule:line-length
# Makefile
- name: checkmake
if: (success() || failure()) && steps.filter.outputs.makefile == 'true'
uses: Uno-Takashi/checkmake-action@main # Can not pass multiple files
# Shell scripts - no extension to filter on, always run
- name: shellcheck shfmt checkbashisms
if: success() || failure()
uses: luizm/action-sh-checker@master # blocklint: pragma
env:
SHFMT_OPTS: -bn -ci -sr -s -d
with:
sh_checker_checkbashisms_enable: true
# Markdown
- name: markdownlint
if: (success() || failure()) && steps.filter.outputs.markdown == 'true'
uses: nosborn/[email protected]
with:
files: ${{ steps.filter.outputs.markdown_files }}
dot: true
config_file: .dev_config/.markdownlint.yaml
ignore_files: LICENSE.md
# All files
- name: detect-secrets
if: success() || failure()
run: poetry run detect-secrets-hook --exclude-lines 'integrity='
- name: blocklint
if: success() || failure()
run: poetry run blocklint --skip-files=poetry.lock --max-issue-threshold=1
- name: typos
if: success() || failure()
uses: crate-ci/[email protected]
with:
config: pyproject.toml
- name: Trailing spaces
if: (success() || failure()) && steps.filter.outputs.any == 'true'
run: |
TRAILING_SPACES=$(grep -rInH ' $' ${{ steps.filter.outputs.any_files }} || true)
if [[ $TRAILING_SPACES ]]; then
echo "::error Trailing spaces found, please remove them::"
echo "$TRAILING_SPACES"
false
else
echo "No trailing spaces found."
true
fi
- name: DEV noqa via tmp file
if: (success() || failure()) && steps.filter.outputs.any == 'true'
run: |
TMP_FIND_NOQA_COMMENTS=$(shell mktemp /tmp/find_noqa_comments.XXXXXX); \
echo TMP_FIND_NOQA_COMMENTS || true; \
echo $TMP_FIND_NOQA_COMMENTS || true; \
echo $$TMP_FIND_NOQA_COMMENTS || true; \