-
Notifications
You must be signed in to change notification settings - Fork 99
334 lines (318 loc) · 12.3 KB
/
workflow.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
name: OpenFisca France
on:
push:
pull_request:
types: [opened, reopened]
env:
DEFAULT_PYTHON_VERSION: '3.10.6'
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: ["ubuntu-20.04"] # On peut ajouter "macos-latest" si besoin
python-version: ["3.9.9", "3.10.6"]
openfisca-dependencies: [minimal, maximal]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache build
id: restore-build
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-${{ matrix.os }}-${{ matrix.openfisca-dependencies }}
restore-keys: | # in case of a cache miss (systematically unless the same commit is built repeatedly), the keys below will be used to restore dependencies from previous builds, and the cache will be stored at the end of the job, making up-to-date dependencies available for all jobs of the workflow; see more at https://docs.github.com/en/actions/advanced-guides/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ matrix.os }}
build-${{ env.pythonLocation }}-${{ matrix.os }}
- name: Build package
run: make build
- name: Minimal version
if: matrix.openfisca-dependencies == 'minimal'
run: | # Installs the OpenFisca dependencies minimal version from pyproject.toml
pip install $(python ${GITHUB_WORKSPACE}/.github/get_minimal_version.py)
- name: Cache release
id: restore-release
uses: actions/cache@v4
with:
path: dist
key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-${{ matrix.os }}-${{ matrix.openfisca-dependencies }}
build-and-test-conda:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache build
uses: actions/cache@v4
with:
path: ./conda-bld
key: build-conda-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
enableCrossOsArchive: true
- name: set version
run: |
python3 .github/pyproject_version.py --replace True
- name: Build conda package
uses: prefix-dev/[email protected]
with:
build-args: --channel openfisca --channel conda-forge --output-dir ./conda-bld
recipe-path: .conda/recipe.yaml
upload-artifact: false
- name: Setup conda
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: openfisca
miniforge-version: latest
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
use-mamba: true
channels: conda-forge,defaults
- name: Install package
shell: pwsh
run: mamba install --channel ./conda-bld --channel openfisca openfisca-france
- name: Test openfisca-france conda package
shell: pwsh
run: openfisca test tests/formulas/irpp.yaml
lint-files:
runs-on: ubuntu-20.04
strategy:
matrix:
dependencies-version: [maximal]
needs: [ build ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all the tags
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Cache build
id: restore-build
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-ubuntu-20.04-${{ matrix.dependencies-version }}
- run: make check-syntax-errors
- run: make check-style
- name: Lint Python files
run: "${GITHUB_WORKSPACE}/.github/lint-changed-python-files.sh"
- name: Lint YAML tests
run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh"
test-python:
runs-on: ${{ matrix.os }}
needs: [ build ]
strategy:
fail-fast: true
matrix:
os: [ "ubuntu-20.04" ] # On peut ajouter "macos-latest" si besoin
python-version: ["3.9.9", "3.10.6"]
openfisca-dependencies: [minimal, maximal]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache build
id: restore-build
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-${{ matrix.os }}-${{ matrix.openfisca-dependencies }}
- run: |
shopt -s globstar
openfisca test --country-package openfisca_france tests/**/*.py
if: matrix.openfisca-dependencies != 'minimal' || matrix.python-version != '3.9.9'
test-path-length:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Test max path length
run: make check-path-length
test-yaml:
runs-on: ubuntu-20.04
needs: [ build ]
strategy:
fail-fast: false
matrix:
# Set N number of parallel jobs to run tests on. Here we use 10 jobs
# Remember to update ci_node_index below to 0..N-1
ci_node_total: [ 10 ]
ci_node_index: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
openfisca-dependencies: [minimal, maximal]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Cache build
id: restore-build
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-ubuntu-20.04-${{ matrix.openfisca-dependencies }}
- name: Split YAML tests
id: yaml-test
env:
CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
run: |
echo "TEST_FILES_SUBLIST=$(python "${GITHUB_WORKSPACE}/.github/split_tests.py" ${CI_NODE_TOTAL} ${CI_NODE_INDEX})" >> $GITHUB_ENV
- name: Run YAML test
run: |
openfisca test --country-package openfisca_france ${TEST_FILES_SUBLIST}
test-api:
runs-on: ubuntu-20.04
strategy:
matrix:
dependencies-version: [maximal]
needs: [ build ]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Cache build
id: restore-build
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-ubuntu-20.04-${{ matrix.dependencies-version }}
- name: Test the Web API
run: "${GITHUB_WORKSPACE}/.github/test-api.sh"
test-on-windows:
runs-on: windows-latest
if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch
needs: [ build-and-test-conda ]
steps:
# Checkout needed to get github.sha
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: openfisca
miniforge-version: latest
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
use-mamba: true
channels: conda-forge,defaults
- name: Restore build
uses: actions/cache@v4
with:
path: ./conda-bld
key: build-conda-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
fail-on-cache-miss: true
enableCrossOsArchive: true
- name: Test max path length
run: "python3 openfisca_france/scripts/check_path_length.py"
- name: Install package
shell: pwsh
run: mamba install --channel ./conda-bld --channel openfisca openfisca-france
- name: Test conda package
shell: pwsh
run: openfisca test tests/formulas/irpp.yaml
check-version-and-changelog:
runs-on: ubuntu-20.04
needs: [ lint-files, test-python, test-yaml, test-api ] # Last job to run
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all the tags
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Check version number has been properly updated
run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh"
# GitHub Actions does not have a halt job option, to stop from deploying if no functional changes were found.
# We build a separate job to substitute the halt option.
# The `deploy` job is dependent on the output of the `check-for-functional-changes` job.
check-for-functional-changes:
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch
needs: [ check-version-and-changelog ]
outputs:
status: ${{ steps.stop-early.outputs.status }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all the tags
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- id: stop-early
run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi
deploy:
runs-on: ubuntu-20.04
strategy:
matrix:
dependencies-version: [maximal]
needs: [ check-for-functional-changes ]
if: needs.check-for-functional-changes.outputs.status == 'success'
env:
PYPI_USERNAME: __token__
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all the tags
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Cache build
id: restore-build
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-ubuntu-20.04-${{ matrix.dependencies-version }}
- name: Cache release
id: restore-release
uses: actions/cache@v4
with:
path: dist
key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-ubuntu-20.04-${{ matrix.dependencies-version }}
- name: Upload a Python package to PyPi
run: twine upload dist/* --username $PYPI_USERNAME --password $PYPI_TOKEN
- name: Publish a git tag
run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh"
publish-to-conda:
runs-on: windows-latest
needs: [ deploy, test-on-windows ]
steps:
- uses: actions/checkout@v4
- name: Restore build
uses: actions/cache@v4
with:
path: ./conda-bld
key: build-conda-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}
fail-on-cache-miss: true
enableCrossOsArchive: true
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: openfisca
miniforge-version: latest
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
use-mamba: true
channels: conda-forge,defaults
- name: Install package
shell: pwsh
run: mamba install --channel ./conda-bld --channel openfisca openfisca-france
- name: Test conda package
shell: pwsh
run: openfisca test tests/formulas/irpp.yaml
- name: Conda upload already built package
shell: pwsh
run: |
conda install --yes anaconda-client
anaconda -t ${{ secrets.ANACONDA_TOKEN }} upload --user openfisca ./conda-bld\noarch\openfisca-france-*