-
Notifications
You must be signed in to change notification settings - Fork 18
453 lines (398 loc) · 16.4 KB
/
tests_and_publish.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
name: "Test and Publish"
on:
push:
branches:
- master
- develop
paths-ignore:
- "docs/**"
- CHANGELOG.md
- README.md
- CONTRIBUTING.md
pull_request:
branches:
- master
- develop
paths-ignore:
- "docs/**"
- CHANGELOG.md
- README.md
- CONTRIBUTING.md
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
repository_dispatch:
types: [ok-to-test-command]
jobs:
unit_tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v4
- name: Setup python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry
run: |
python -V
python -m pip install poetry
- name: Check pre-commit status
run: |
poetry install -v
poetry run pre-commit run --all-files
- name: Test with tox
run: |
pip install tox-pip-version tox-gh-actions "tox<4.0.0"
tox -v
- name: Store coverage reports
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.python-version }}
path: coverage.xml
if-no-files-found: error
sonarcloud_trusted_branch:
if: (github.event.pull_request.head.repo.full_name == github.repository || github.event.pull_request == null)
runs-on: ubuntu-latest
needs: unit_tests
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: coverage-3.9
path: .
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
with:
projectBaseDir: ${{ github.workspace }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
sonarcloud_forked_branch:
if: |
github.event_name == 'repository_dispatch' &&
github.event.client_payload.slash_command.args.named.sha != '' &&
contains(
github.event.client_payload.pull_request.head.sha,
github.event.client_payload.slash_command.args.named.sha
)
runs-on: ubuntu-latest
permissions:
pull-requests: write
checks: write
needs: unit_tests
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
- uses: actions/download-artifact@v4
with:
name: coverage-3.9
path: .
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
with:
projectBaseDir: ${{ github.workspace }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
- uses: actions/github-script@v6
id: update-check-run
if: ${{ always() }}
env:
number: ${{ github.event.client_payload.pull_request.number }}
job: ${{ github.job }}
# Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
conclusion: ${{ job.status }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: pull } = await github.rest.pulls.get({
...context.repo,
pull_number: process.env.number
});
const ref = pull.head.sha;
const { data: checks } = await github.rest.checks.listForRef({
...context.repo,
ref
});
const check = checks.check_runs.filter(c => c.name === process.env.job);
const { data: result } = await github.rest.checks.update({
...context.repo,
check_run_id: check[0].id,
status: 'completed',
conclusion: process.env.conclusion
});
return result;
codeql:
runs-on: ubuntu-latest
needs: unit_tests
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: python
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
### PROJECT SPECIFIC CONFIGURATION HERE
e2e_tests_trusted_branch:
if: (github.event.pull_request.head.repo.full_name == github.repository || github.event.pull_request == null)
needs: [unit_tests, sonarcloud_trusted_branch]
runs-on: ubuntu-latest
strategy:
matrix:
e2e_config: ["e2e", "e2e_pipeline_data_passing"]
steps:
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Setup poetry
run: |
python -V
python -m pip install poetry
- name: Build the package
run: |
poetry build -f sdist
- name: Initialize starter project
run: |
pip install $(find "./dist" -name "*.tar.gz")
kedro new --starter spaceflights --config tests/conf/${{ matrix.e2e_config }}/starter-config.yml --verbose
- name: Install starter requirements
working-directory: ./spaceflights
run: |
find "../dist" -name "*.tar.gz" | xargs -I@ cp @ kedro-azureml.tar.gz
echo -e "\n./kedro-azureml.tar.gz\n" >> src/requirements.txt
echo -e "kedro-docker<0.5.0\n" >> src/requirements.txt
echo -e "openpyxl\n" >> src/requirements.txt # temp fix for kedro-datasets issues with optional packages
sed -i '/kedro-telemetry/d' src/requirements.txt
sed -i '/kedro-viz/d' src/requirements.txt # starter version requirements make tests fail
echo $(cat src/requirements.txt)
pip install -r src/requirements.txt
- name: Update starter configs
working-directory: ./spaceflights
run: |
kedro docker init
sed -i 's/\(COPY src\/requirements.txt.*\)$/\1\nCOPY kedro-azureml.tar.gz ./g' Dockerfile
cat Dockerfile
echo "!data/01_raw" >> .dockerignore
rm conf/base/catalog.yml
cp ../tests/conf/${{ matrix.e2e_config }}/catalog.yml conf/base/catalog.yml
cp ../tests/conf/${{ matrix.e2e_config }}/azureml.yml conf/base/azureml.yml
sed -i 's/{container_registry}/${{ secrets.REGISTRY_LOGIN_SERVER }}/g' conf/base/azureml.yml
sed -i 's/{image_tag}/${{ matrix.e2e_config }}/g' conf/base/azureml.yml
cat conf/base/azureml.yml
- name: Login via Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Login to acr.io
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.AZURE_CLIENT_ID }}
password: ${{ secrets.AZURE_CLIENT_SECRET }}
- name: Build and push docker image
working-directory: ./spaceflights
run: |
docker pull ${{ secrets.REGISTRY_LOGIN_SERVER }}/kedro-azureml-e2e:${{ matrix.e2e_config }} || true
docker build --build-arg BASE_IMAGE=python:3.10-buster -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/kedro-azureml-e2e:${{ matrix.e2e_config }} --cache-from=${{ secrets.REGISTRY_LOGIN_SERVER }}/kedro-azureml-e2e:${{ matrix.e2e_config }} .
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/kedro-azureml-e2e:${{ matrix.e2e_config }}
- name: Run on Azure ML Pipelines
working-directory: ./spaceflights
env:
AZURE_STORAGE_ACCOUNT_KEY: ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
run: |
kedro azureml run --wait-for-completion --env-var 'GETINDATA=ROCKS!'
e2e_tests_forked_branch:
if: |
github.event_name == 'repository_dispatch' &&
github.event.client_payload.slash_command.args.named.sha != '' &&
contains(
github.event.client_payload.pull_request.head.sha,
github.event.client_payload.slash_command.args.named.sha
)
needs: [unit_tests, sonarcloud_forked_branch]
runs-on: ubuntu-latest
strategy:
matrix:
e2e_config: ["e2e", "e2e_pipeline_data_passing"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Setup poetry
run: |
python -V
python -m pip install poetry
- name: Build the package
run: |
poetry build -f sdist
- name: Initialize starter project
run: |
pip install $(find "./dist" -name "*.tar.gz")
kedro new --starter spaceflights --config tests/conf/${{ matrix.e2e_config }}/starter-config.yml --verbose
- name: Install starter requirements
working-directory: ./spaceflights
run: |
find "../dist" -name "*.tar.gz" | xargs -I@ cp @ kedro-azureml.tar.gz
echo -e "\n./kedro-azureml.tar.gz\n" >> src/requirements.txt
echo -e "kedro-docker<0.5.0\n" >> src/requirements.txt
echo -e "openpyxl\n" >> src/requirements.txt # temp fix for kedro-datasets issues with optional packages
sed -i '/kedro-telemetry/d' src/requirements.txt
sed -i '/kedro-viz/d' src/requirements.txt # starter version requirements make tests fail
echo $(cat src/requirements.txt)
pip install -r src/requirements.txt
- name: Update starter configs
working-directory: ./spaceflights
run: |
kedro docker init
sed -i 's/\(COPY src\/requirements.txt.*\)$/\1\nCOPY kedro-azureml.tar.gz ./g' Dockerfile
cat Dockerfile
echo "!data/01_raw" >> .dockerignore
rm conf/base/catalog.yml
cp ../tests/conf/${{ matrix.e2e_config }}/catalog.yml conf/base/catalog.yml
cp ../tests/conf/${{ matrix.e2e_config }}/azureml.yml conf/base/azureml.yml
sed -i 's/{container_registry}/${{ secrets.REGISTRY_LOGIN_SERVER }}/g' conf/base/azureml.yml
sed -i 's/{image_tag}/${{ matrix.e2e_config }}/g' conf/base/azureml.yml
cat conf/base/azureml.yml
- name: Login via Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Login to acr.io
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.AZURE_CLIENT_ID }}
password: ${{ secrets.AZURE_CLIENT_SECRET }}
- name: Build and push docker image
working-directory: ./spaceflights
run: |
docker pull ${{ secrets.REGISTRY_LOGIN_SERVER }}/kedro-azureml-e2e:${{ matrix.e2e_config }} || true
docker build --build-arg BASE_IMAGE=python:3.10-buster -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/kedro-azureml-e2e:${{ matrix.e2e_config }} --cache-from=${{ secrets.REGISTRY_LOGIN_SERVER }}/kedro-azureml-e2e:${{ matrix.e2e_config }} .
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/kedro-azureml-e2e:${{ matrix.e2e_config }}
- name: Run on Azure ML Pipelines
working-directory: ./spaceflights
env:
AZURE_STORAGE_ACCOUNT_KEY: ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
run: |
kedro azureml run --wait-for-completion --env-var 'GETINDATA=ROCKS!'
- uses: actions/github-script@v6
id: update-check-run
if: ${{ always() }}
env:
number: ${{ github.event.client_payload.pull_request.number }}
job: ${{ github.job }}
# Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
conclusion: ${{ job.status }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: pull } = await github.rest.pulls.get({
...context.repo,
pull_number: process.env.number
});
const ref = pull.head.sha;
const { data: checks } = await github.rest.checks.listForRef({
...context.repo,
ref
});
const check = checks.check_runs.filter(c => c.name === process.env.job);
const { data: result } = await github.rest.checks.update({
...context.repo,
check_run_id: check[0].id,
status: 'completed',
conclusion: process.env.conclusion
});
return result;
publish:
# only run on push to master
if: github.event.pull_request == null && github.ref == 'refs/heads/master'
needs: [e2e_tests_trusted_branch, codeql]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.8 ]
env:
PYTHON_PACKAGE: kedro_azureml
steps:
- name: Checkout the repo
uses: actions/checkout@v2
with:
fetch-depth: 0 # necessary to enable merging, all the history is needed
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Build package dist from source # A better way will be : https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ but pep 517 is still marked as experimental
run: |
pip install poetry
poetry build
- name: Merge back to develop # we have to set the config first on a fresh machine
run: |
git config user.name github-actions
git config user.email [email protected]
git checkout -B develop --track origin/develop
git merge master
git push
- name: Set dynamically package version as output variable # see https://github.com/actions/create-release/issues/39
# see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
id: set_package_version
run: |
echo "::set-output name=PACKAGE_VERSION::$(cat $PYTHON_PACKAGE/__init__.py | grep -Po '\d+\.\d+\.\d+')"
- name: Create temporary file with the body content for the release
run: |
grep -Poz "## \[${{steps.set_package_version.outputs.PACKAGE_VERSION}}] - \d{4}-\d{2}-\d{2}[\S\s]+?(?=## \[\d+\.\d+\.\d+\]|\[.+\]:)" CHANGELOG.md > release_body.md
- name: Create Release # https://github.com/actions/create-release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ steps.set_package_version.outputs.PACKAGE_VERSION }}
release_name: Release ${{ steps.set_package_version.outputs.PACKAGE_VERSION }}
body_path: ./release_body.md
draft: false
prerelease: false
- name: Rollback Release in case of run failure
if: failure() && steps.create_release.outputs.id != ''
uses: author/action-rollback@stable
with:
# Using a known release ID
release_id: ${{ steps.create_release.outputs.id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish distribution to PyPI # official action from python maintainers
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
verbose: true # trace if the upload fails