-
Notifications
You must be signed in to change notification settings - Fork 1
355 lines (314 loc) · 12.7 KB
/
ci.yml
File metadata and controls
355 lines (314 loc) · 12.7 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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
name: Dev build CI
on:
push:
paths-ignore:
- "README**"
tags:
- "v*"
branches:
- "main"
- "rel/*"
pull_request:
branches:
- "*"
paths-ignore:
- "README**"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# write to checks/pull-request extra permission needed by 5monkeys/cobertura-action to post coverage stats
# write packages needed by docker image step
permissions:
id-token: write
contents: write
checks: write
packages: write
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
env:
PREFERED_PYTHON_VERSION: "3.14"
CALIBRATION_TAG: "v0.2.0"
MLM_LICENSE_TOKEN: ${{secrets.MLM_LICENSE_TOKEN }}
CALIBRATION_CODE_LOCATION: "src/matlab/calibration"
PYTEST_XDIST_AUTO_NUM_WORKERS : "2"
jobs:
qa:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: pre-commit/action@v3.0.1
build:
strategy:
matrix:
python-versions: ["3.11", "3.12", "3.13", "3.14"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
# map step outputs to job outputs so they can be share among jobs
outputs:
package_version: ${{ env.PACKAGE_VERSION }}
package_name: ${{ env.PACKAGE_NAME }}
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-versions }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Declare version variables for dev builds
id: variables_step_dev
run: |
# Override the version with a dev suffix because we are not on a tag. Tag builds pull version directly from pyproject.toml
poetry version $(poetry version --short)-dev.$GITHUB_RUN_NUMBER
echo "Using version from pyproject.toml file with dev suffix (because not on a tag): $(poetry version --short)"
echo "PACKAGE_NAME=$(poetry version | awk '{print $1}')" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$(poetry version --short)" >> $GITHUB_ENV
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
shell: bash
- name: Declare variables PACKAGE_NAME and PACKAGE_VERSION
id: variables_step
run: |
echo "Version used by poetry: $(poetry version --short)"
echo "PACKAGE_NAME=$(poetry version | awk '{print $1}')" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$(poetry version --short)" >> $GITHUB_ENV
shell: bash
- name: Ensure tag and version match (tag builds only)
run: |
if [[ "${{ github.ref_name }}" != "v${{ env.PACKAGE_VERSION }}" ]]; then
echo "Tag and version do not match. Tag: ${{ github.ref_name }}, Version: ${{ env.PACKAGE_VERSION }}"
exit 1
fi
if: ${{ startsWith(github.ref, 'refs/tags/') }}
shell: bash
- name: build --skip-tests
run: ./build.sh --skip-tests
- name: Build wheels and source tarball
run: ./pack.sh
- name: Create Version file
run: echo "Version ${{ env.PACKAGE_VERSION }}, SHA ${{ github.sha }}, Ref ${{ github.ref_name }}" > dist/python${{matrix.python-versions}}/version.txt
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
if: matrix.python-versions == env.PREFERED_PYTHON_VERSION
- name: Login to GitHub Container registry ghcr.io
uses: docker/login-action@v3
if: matrix.python-versions == env.PREFERED_PYTHON_VERSION
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get image metadata
id: meta
uses: docker/metadata-action@v6
if: matrix.python-versions == env.PREFERED_PYTHON_VERSION
with:
images: ghcr.io/${{ github.repository }}
tags: |
# minimal
type=semver,pattern={{version}}
# use custom value instead of git tag
type=semver,pattern={{version}},value=${{ env.PACKAGE_VERSION }}
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
# branch event
type=ref,event=branch
# pull request event
type=ref,event=pr
- name: Build and push Docker image
uses: docker/build-push-action@v7
if: matrix.python-versions == env.PREFERED_PYTHON_VERSION
with:
context: .
file: deploy/Dockerfile
build-args: PYTHON_VERSION=${{ matrix.python-versions }}
push: true
tags: |
${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Zip up the folder
run: zip -r ${{ env.PACKAGE_NAME }}_python${{matrix.python-versions}}_${{ env.PACKAGE_VERSION }}.zip python${{matrix.python-versions}}
working-directory: dist
- name: Upload python wheel/tarball
uses: actions/upload-artifact@v7
with:
name: ${{ env.PACKAGE_NAME }}_python${{matrix.python-versions}}_${{ env.PACKAGE_VERSION }}.zip
path: dist/${{ env.PACKAGE_NAME }}_python${{matrix.python-versions}}_${{ env.PACKAGE_VERSION }}.zip
if-no-files-found: error
- name: Create Release ${{github.ref_name}} & upload artifacts
uses: softprops/action-gh-release@v2
if: ${{ startsWith(github.ref, 'refs/tags/') }}
with:
draft: false
prerelease: false
fail_on_unmatched_files: true
files: |
dist/${{ env.PACKAGE_NAME }}_python${{matrix.python-versions}}_${{ env.PACKAGE_VERSION }}.zip
tests:
strategy:
matrix:
python-versions: ["3.11", "3.12", "3.13", "3.14"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-versions }}
- name: Check out calibration code into ${{ env.CALIBRATION_CODE_LOCATION }} in repository
uses: actions/checkout@v6
if: github.event.pull_request.user.login != 'dependabot[bot]'
with:
path: ${{ env.CALIBRATION_CODE_LOCATION}}
sparse-checkout: |
+calibration
+general
external-packages
repository: ${{ vars.CALIBRATION_REPO }}
ssh-key: ${{ secrets.IMAP_MAG_CALIBRATION_DEPLOY_KEY }}
ref: ${{ env.CALIBRATION_TAG }}
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v3
- name: Run Tests
run: |
python -m pip install poetry
./build.sh
- name: Upload Coverage report
uses: actions/upload-artifact@v7
if: matrix.python-versions == env.PREFERED_PYTHON_VERSION
with:
name: CoverageReport_python${{matrix.python-versions}}
path: htmlcov
if-no-files-found: error
- name: Test Report
uses: dorny/test-reporter@v3
if: ${{ !cancelled() && hashFiles('test-results.xml') != '' }}
with:
name: Test Results (${{ matrix.python-versions }})
path: "test-results.xml"
reporter: java-junit
use-actions-summary: 'true'
fail-on-error: 'false'
fail-on-empty: 'true'
- name: Coverage Report
uses: 5monkeys/cobertura-action@v14
if: matrix.python-versions == env.PREFERED_PYTHON_VERSION
with:
report_name: Coverage Report (${{ matrix.python-versions }})
path: "coverage.xml"
minimum_coverage: 80
matlab-build:
strategy:
matrix:
python-versions: ["3.11", "3.12", "3.13", "3.14"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
# map step outputs to job outputs so they can be share among jobs
outputs:
package_version: ${{ env.PACKAGE_VERSION }}
package_name: ${{ env.PACKAGE_NAME }}
steps:
# builds fail with not enough space - needs more than the default 16GB!! in GH Actions default runners
- name: Free Disk Space (Ubuntu)
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: true
# Each of these frees more space, takes more time
android: false
dotnet: true
haskell: false
large-packages: false
docker-images: false
swap-storage: false
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-versions }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Declare version variables for dev builds
id: variables_step_dev
run: |
# Override the version with a dev suffix because we are not on a tag. Tag builds pull version directly from pyproject.toml
poetry version $(poetry version --short)-dev.$GITHUB_RUN_NUMBER
echo "Using version from pyproject.toml file with dev suffix (because not on a tag): $(poetry version --short)"
echo "PACKAGE_NAME=$(poetry version | awk '{print $1}')" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$(poetry version --short)" >> $GITHUB_ENV
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
shell: bash
- name: Declare variables PACKAGE_NAME and PACKAGE_VERSION
id: variables_step
run: |
echo "Version used by poetry: $(poetry version --short)"
echo "PACKAGE_NAME=$(poetry version | awk '{print $1}')" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$(poetry version --short)" >> $GITHUB_ENV
shell: bash
- name: Ensure tag and version match (tag builds only)
run: |
if [[ "${{ github.ref_name }}" != "v${{ env.PACKAGE_VERSION }}" ]]; then
echo "Tag and version do not match. Tag: ${{ github.ref_name }}, Version: ${{ env.PACKAGE_VERSION }}"
exit 1
fi
if: ${{ startsWith(github.ref, 'refs/tags/') }}
shell: bash
- name: Check out calibration code into ${{ env.CALIBRATION_CODE_LOCATION }} in repository
uses: actions/checkout@v6
if: github.event.pull_request.user.login != 'dependabot[bot]'
with:
path: ${{ env.CALIBRATION_CODE_LOCATION}}
sparse-checkout: |
+calibration
+general
external-packages
repository: ${{ vars.CALIBRATION_REPO }}
ssh-key: ${{ secrets.IMAP_MAG_CALIBRATION_DEPLOY_KEY }}
ref: ${{ env.CALIBRATION_TAG }}
- name: build --skip-tests
run: ./build.sh --skip-tests
- name: Build wheels and source tarball
run: ./pack.sh
- name: Create Version file
run: echo "Version ${{ env.PACKAGE_VERSION }}, SHA ${{ github.sha }}, Ref ${{ github.ref_name }}" > dist/python${{matrix.python-versions}}/version.txt
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
if: matrix.python-versions == env.PREFERED_PYTHON_VERSION
- name: Login to GitHub Container registry ghcr.io
uses: docker/login-action@v3
if: matrix.python-versions == env.PREFERED_PYTHON_VERSION
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get image metadata
id: meta
uses: docker/metadata-action@v6
if: matrix.python-versions == env.PREFERED_PYTHON_VERSION
with:
images: ghcr.io/${{ github.repository }}/${{ vars.CALIBRATION_IMAGE_NAME }}
tags: |
# minimal
type=semver,pattern={{version}}
# use custom value instead of git tag,prefix=matlab-
type=semver,pattern={{version}},value=${{ env.PACKAGE_VERSION }},prefix=matlab-
# set latest tag for default branch
type=raw,value=latest,prefix=matlab-,enable={{is_default_branch}}
# branch event
type=ref,event=branch,prefix=matlab-
# pull request event
type=ref,event=pr,prefix=matlab-pr-
- name: Build and push Docker image
uses: docker/build-push-action@v7
if: matrix.python-versions == env.PREFERED_PYTHON_VERSION
with:
context: .
file: deploy/MATLAB-Dockerfile
push: true
tags: |
${{ steps.meta.outputs.tags }}
cache-from: type=gha,scope=matlab_imap_pipeline_core_embedded
cache-to: type=gha,mode=max,scope=matlab_imap_pipeline_core_embedded