-
Notifications
You must be signed in to change notification settings - Fork 19
259 lines (219 loc) · 7.52 KB
/
Copy pathworkflow_actions.yml
File metadata and controls
259 lines (219 loc) · 7.52 KB
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
name: CI/CD Pipeline
on:
release:
types: [published]
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
force_radas_rebuild:
description: "Regenerate radas_dir and overwrite the cached data (use when a dependency bump changed radas output and regression tests fail)"
type: boolean
default: false
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# --- JOB 1: GENERATE RADAS DATA ---
radas:
name: Generate Radas Data
runs-on: ubuntu-latest
permissions:
contents: read
actions: write # allow deleting the cache entry on a forced rebuild
outputs:
cache-key: ${{ steps.radas-key.outputs.key }}
steps:
- uses: actions/checkout@v6
- name: Install Poetry
run: pipx install "poetry>=2,<3"
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: 'poetry'
- name: Install dependencies
run: poetry install
# The radas output depends on the radas package version and
# radas_config.yaml, so key the cache on those rather than the whole
# poetry.lock (which busts on every unrelated dependency bump).
# N.b. it is possible that bumping some dependencies could change the
# radas result enough to affect the regression result. You might need
# manually regenerate the radas_dir in this case.
- name: Compute radas cache key
id: radas-key
run: |
radas_version=$(grep -A1 '^name = "radas"$' poetry.lock | grep '^version' | sed -E 's/.*"(.*)".*/\1/')
echo "key=radas-v${radas_version//!/-}-${{ hashFiles('radas_config.yaml') }}" >> "$GITHUB_OUTPUT"
# On a manual run with force_radas_rebuild, delete any existing cache
# entry for this key so the freshly generated data is saved in its place
# (actions/cache will not overwrite an existing key otherwise).
- name: Delete existing radas cache
if: ${{ github.event_name == 'workflow_dispatch' && inputs.force_radas_rebuild }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh cache delete "${{ steps.radas-key.outputs.key }}" --repo "${{ github.repository }}" \
|| echo "No existing cache for this key; fresh data will be generated."
- name: Cache radas results
id: radas-cache
uses: actions/cache@v5
with:
path: ./radas_dir
key: ${{ steps.radas-key.outputs.key }}
- name: Make radas data
if: steps.radas-cache.outputs.cache-hit != 'true'
run: poetry run radas -c radas_config.yaml
- name: Upload radas artifacts
uses: actions/upload-artifact@v7
with:
name: radas_dir
path: ./radas_dir
retention-days: 30
# --- JOB 2: TEST ---
# The heavy work: unit tests, regression tests and the packaged smoke test,
# run across the supported Python versions. Needs the radas data.
test:
name: Test (Python ${{ matrix.python-version }})
needs: radas
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.12', '3.13', '3.14']
steps:
- uses: actions/checkout@v6
- name: Install Poetry
run: pipx install "poetry>=2,<3"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Restore radas data
uses: actions/cache/restore@v5
id: radas-restore
with:
path: ./radas_dir
key: ${{ needs.radas.outputs.cache-key }}
- name: Verify Cache
if: steps.radas-restore.outputs.cache-hit != 'true'
run: exit 1
- name: Run Tests
env:
MPLBACKEND: Agg
run: poetry run pytest tests --nbmake example_cases -m "not docs"
- name: Regression Tests
env:
MPLBACKEND: Agg
run: |
poetry run python tests/utils/regression_results.py
poetry run pytest --no-cov tests/test_regression_against_cases.py
- name: Upload regression results on failure
uses: actions/upload-artifact@v7
if: failure()
with:
name: regression_results-${{ matrix.python-version }}
path: tests/regression_results
- name: Smoke test package
env:
MPLBACKEND: Agg
run: |
poetry build -f wheel
python -m venv test_env
source test_env/bin/activate
pip install dist/*.whl
mkdir tmp_dir && cd tmp_dir
popcon ../example_cases/SPARC_PRD -d radas_dir WORKING_DIR/../radas_dir
# --- JOB 3: LINT ---
# pre-commit (ruff, mypy, variable-consistency check). Independent of the
# radas data, so it runs in parallel with everything else for fast feedback.
lint:
name: Lint (pre-commit)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Poetry
run: pipx install "poetry>=2,<3"
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Pre-commit checks
run: poetry run pre-commit run --show-diff-on-failure --color=always --all-files
# --- JOB 4: DOCUMENTATION ---
# Sphinx build (warnings as errors), doctests and linkcheck. Notebooks are
# not executed (nbsphinx_execute = "never"), so this is independent of the
# radas data and runs in parallel with everything else.
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pandoc
- name: Install Poetry
run: pipx install "poetry>=2,<3"
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Documentation tests
run: |
cd docs
poetry run sphinx-build --keep-going -Wnb html . _build/
poetry run make doctest
poetry run make linkcheck
# --- JOB 5: PREPARE RELEASE ---
build_release:
name: Build Release
if: startsWith(github.ref, 'refs/tags')
needs: [test, lint, docs]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Poetry
run: pipx install "poetry>=2,<3"
- name: Build distributions
run: poetry build
- name: Upload PyPI artifacts
uses: actions/upload-artifact@v7
with:
name: pypi-build
path: ./dist
retention-days: 1
# --- JOB 6: PUBLISH ---
publish:
name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags')
needs: build_release
runs-on: ubuntu-latest
environment:
name: pypi-publish
url: https://pypi.org/project/cfspopcon/
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v8
with:
name: pypi-build
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/