-
Notifications
You must be signed in to change notification settings - Fork 9
461 lines (412 loc) · 15.9 KB
/
release.yaml
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
454
455
456
457
458
459
460
461
---
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2024 The Linux Foundation <https://linuxfoundation.org>
name: "🤖 DevOps Automation"
# yamllint disable-line rule:truthy
on:
workflow_dispatch:
push:
paths:
- "**"
- "!.github/**"
env:
DEFAULT_PYTHON: "3.10"
BUILD_ARTEFACTS: "dist"
# Configures publishing to PyPI
PYPI_PUBLISHING: "true"
# Create GitHub releases for all builds, not just production builds
GITHUB_PRERELEASE: "true"
# Create an initial tag, if missing
CREATE_MISSING_TAG: "true"
jobs:
one-password-verify:
name: "1Password"
uses: os-climate/osc-github-devops/.github/workflows/one-password-credentials.yaml@main
# Do NOT run until change is merged; secrets will NOT be available and workflow WILL fail
if: github.event_name != 'pull_request'
with:
VAULT_ITEM: "op://67hdehutbpddhfbgm6ffjvdsbu/Test Secure Note/notesPlain"
EXPORT: false
secrets:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.ONE_PASSWORD_DEVELOPMENT }}
classify-content:
name: "Inspect Repository"
runs-on: ubuntu-latest
outputs:
python: ${{ steps.classify.outputs.python }}
notebooks: ${{ steps.classify.outputs.notebooks }}
tox: ${{ steps.classify.outputs.tox }}
steps:
- uses: actions/checkout@v4
- name: "Classify content"
id: classify
# yamllint disable-line rule:line-length
uses: os-climate/osc-github-devops/.github/actions/repository-content-classify@main
github-workflow-metadata:
name: "Gather Workflow Metadata"
runs-on: ubuntu-latest
outputs:
owner: ${{ steps.set.outputs.owner }}
repository: ${{ steps.set.outputs.repository }}
tagged: ${{ steps.set.outputs.tagged }}
steps:
- name: "Capture workflow metadata"
id: set
# yamllint disable-line rule:line-length
uses: os-climate/osc-github-devops/.github/actions/github-workflow-metadata@main
tagging:
name: "Retrieve/Verify GIT Tags"
runs-on: ubuntu-latest
outputs:
current: ${{ steps.repository-tags.outputs.tag }}
invalid: ${{ steps.repository-tags.outputs.invalid }}
dev_tag: ${{ steps.get-development.outputs.tag }}
steps:
- name: "Retrieve/verify tags"
id: repository-tags
# yamllint disable-line rule:line-length
uses: os-climate/osc-github-devops/.github/actions/repository-tags-fetch@main
- name: "Create initial v0.0.0 tag"
id: set-initial-tag
# Only runs if no tags are found, pushes an initial v0.0.0
if: steps.repository-tags.outputs.invalid == 'true' && env.CREATE_MISSING_TAG
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
tag_name: v0.0.0
- name: "Generate a DEVELOPMENT tag"
id: get-development
uses: os-climate/osc-github-devops/.github/actions/semantic-tag-development@main
with:
tag: ${{ steps.repository-tags.outputs.tag }}
verify-github-environment:
name: "Verify GitHub Environment"
runs-on: ubuntu-latest
outputs:
present: ${{ steps.labelling.outputs.present }}
created: ${{ steps.labelling.outputs.created }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
# Required for action to create labels: github-mandatory-labels
contents: write
steps:
- uses: actions/checkout@v4
- name: "Verify/create release labels"
id: labelling
# yamllint disable-line rule:line-length
uses: os-climate/osc-github-devops/.github/actions/github-mandatory-labels@main
- name: "Check for required secrets/API keys/tokens"
uses: os-climate/osc-github-devops/.github/actions/github-mandatory-secrets@main
with:
# Mandatory secrets/variables to check
pypi_development: ${{ secrets.PYPI_DEVELOPMENT }}
pypi_production: ${{ secrets.PYPI_PRODUCTION }}
one_password_development: ${{ secrets.ONE_PASSWORD_DEVELOPMENT }}
parse-tox-configuration:
name: "TOX Environment"
needs:
- classify-content
if: needs.classify-content.outputs.tox == 'true'
uses: os-climate/osc-github-devops/.github/workflows/tox.yaml@main
python-project:
name: "Python Content"
needs:
- classify-content
if: needs.classify-content.outputs.python == 'true'
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.python.outputs.matrixjson }}
steps:
- uses: actions/checkout@v4
- name: "Extract Python versioning"
id: python
# yamllint disable-line rule:line-length
uses: os-climate/osc-github-devops/.github/actions/python-versions-matrix@main
python-build:
name: "Build"
uses: os-climate/osc-github-devops/.github/workflows/python-build-matrix.yaml@main
needs:
- github-workflow-metadata
- python-project
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.python-project.outputs.matrix) }}
permissions:
contents: write
# Required by SigStore signing action
id-token: write
with:
python_version: ${{ matrix.python-version }}
python-test:
name: "Test"
uses: os-climate/osc-github-devops/.github/workflows/python-test-matrix.yaml@main
needs:
- github-workflow-metadata
- python-project
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.python-project.outputs.matrix) }}
with:
python_version: ${{ matrix.python-version }}
github-release:
name: "Publish GitHub Release"
uses: os-climate/osc-github-devops/.github/workflows/github-release.yaml@main
needs:
- python-build
- tagging
# ToDo: Implement explicit development release and build naming
# with:
# prerelease: true
# devtag: ${{ needs.tagging.outputs.dev_tag }}
permissions:
# Needed both here and in the called workflow
contents: write
testpypi:
name: "Test Package Publishing"
needs:
- tagging
- github-workflow-metadata
- python-build
# Only test publishing on merge of pull requests or tag pushes
if: github.event.pull_request.merged == true || startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
environment:
name: development
permissions:
# IMPORTANT: mandatory for trusted publishing
id-token: write
steps:
- name: "Download build artefacts"
uses: actions/download-artifact@v4
if: env.PYPI_PUBLISHING == 'true'
with:
name: ${{ github.ref_name }}
path: ${{ env.BUILD_ARTEFACTS }}
- name: "Manicure artefacts directory"
id: files
run: |
# Remove file types unsupported by the Python Package Index
if [ ! -d ${{ env.BUILD_ARTEFACTS }} ]; then
echo "Early exit; build artefacts path NOT found: ${{ env.BUILD_ARTEFACTS }}"
exit 0
fi
if [ -f ${{ env.BUILD_ARTEFACTS }}/buildvars.txt ]; then
rm ${{ env.BUILD_ARTEFACTS }}/buildvars.txt
else
echo "No buildvars.txt file to purge"
fi
# Remove outputs related to SigStore signing
if test -n "$(find ${{ env.BUILD_ARTEFACTS }} -maxdepth 1 -name '**.sigstore*' -print -quit)"
then
echo "Found SigStore signing artefacts to purge"
rm ${{ env.BUILD_ARTEFACTS }}/*.sigstore*
else
echo "No SigStore signing artefacts to purge"
fi
- name: "Check PROJECT in Test PyPI"
id: testpypi-project-url-check
# yamllint disable-line rule:line-length
uses: os-climate/osc-github-devops/.github/actions/url-validity-check@main
with:
prefix: "https://test.pypi.org/project"
# Use project name, e.g. "/ITR"
string: "/${{ needs.github-workflow-metadata.outputs.repository }}"
suffix: "/"
- name: "Check RELEASE in Test PyPI"
id: testpypi-release-url-check
# yamllint disable-line rule:line-length
uses: os-climate/osc-github-devops/.github/actions/url-validity-check@main
with:
prefix: "https://test.pypi.org/project"
# Use project name, e.g. "/ITR"
string: "/${{ needs.github-workflow-metadata.outputs.repository }}"
suffix: "/${{ needs.tagging.outputs.current }}/"
- name: "Publish to Test PyPI [Trusted Publishing]"
uses: pypa/gh-action-pypi-publish@release/v1
# Primary/default method uses trusted publishing
# yamllint disable-line rule:line-length
if: steps.testpypi-project-url-check.outputs.valid == 'true' && steps.testpypi-release-url-check.outputs.valid == 'false'
with:
repository-url: https://test.pypi.org/legacy/
# Show checksum values
print-hash: true
packages-dir: ${{ env.BUILD_ARTEFACTS }}
# We already validate earlier in the pipeline
verify-metadata: false
# Test releases are always debugged
verbose: true
- name: "Publish to Test PyPI [Fallback: API Key]"
uses: pypa/gh-action-pypi-publish@release/v1
# Fallback method uses static organisation credentials
# Used initially when trusted publishing is unavailable
if: steps.testpypi-project-url-check.outputs.valid == 'false'
with:
repository-url: https://test.pypi.org/legacy/
# Show checksum values
print-hash: true
packages-dir: ${{ env.BUILD_ARTEFACTS }}
# We already validate earlier in the pipeline
verify-metadata: false
# Test releases are always debugged
verbose: true
# Organisation secret/variable
# Defined/stored in 1Password
password: ${{ secrets.PYPI_DEVELOPMENT }}
pypi:
name: "Publish Package"
if:
# Only publish on tag pushes or when a release is explicitly requested
startsWith(github.ref, 'refs/tags/') || contains(github.event.head_commit.message, '[release]')
# github.ref_name != 'main' &&
# github.ref_name != 'master'
needs: [tagging, python-build, github-workflow-metadata, testpypi]
runs-on: ubuntu-latest
environment:
name: production
permissions:
# IMPORTANT: mandatory for trusted publishing
id-token: write
steps:
- name: "Download build artefacts"
uses: actions/download-artifact@v4
with:
name: ${{ github.ref_name }}
path: ${{ env.BUILD_ARTEFACTS }}
- name: "Remove unsupported artefacts/files"
run: |
# Remove unsupported artefacts/files
if (ls ${{ env.BUILD_ARTEFACTS }}/*.sigstore*); then
rm ${{ env.BUILD_ARTEFACTS }}/*.sigstore*
fi
- name: "Check if PROJECT in PyPI"
id: pypi-project-url-check
# yamllint disable-line rule:line-length
uses: os-climate/osc-github-devops/.github/actions/url-validity-check@main
with:
prefix: "https://pypi.org/project"
# Use project name, e.g. "/ITR"
string: "/${{ needs.github-workflow-metadata.outputs.repository }}"
suffix: "/"
- name: "Check for RELEASE in PyPI"
id: pypi-release-url-check
# yamllint disable-line rule:line-length
uses: os-climate/osc-github-devops/.github/actions/url-validity-check@main
with:
prefix: "https://pypi.org/project"
# Use project name, e.g. "/ITR"
string: "/${{ needs.github-workflow-metadata.outputs.repository }}"
suffix: "/${{ needs.tagging.outputs.current }}/"
- name: "Publish to PyPI [Trusted Publishing]"
uses: pypa/gh-action-pypi-publish@release/v1
# Primary/default method uses trusted publishing
# yamllint disable-line rule:line-length
if: steps.pypi-project-url-check.outputs.valid == 'true' && steps.pypi-release-url-check.outputs.valid == 'false'
with:
# Show checksum values
print-hash: true
packages-dir: ${{ env.BUILD_ARTEFACTS }}
# We already validate earlier in the pipeline
verify-metadata: false
- name: "Publish to PyPI [Fallback: API Key]"
uses: pypa/gh-action-pypi-publish@release/v1
# Fallback method uses static organisation credentials
# Used initially when trusted publishing is unavailable
if: steps.pypi-project-url-check.outputs.valid == 'false'
with:
# Show checksum values
print-hash: true
packages-dir: ${{ env.BUILD_ARTEFACTS }}
# We already validate earlier in the pipeline
verify-metadata: false
# Organisation secret/variable
# Defined/stored in 1Password
password: ${{ secrets.PYPI_PRODUCTION }}
notebooks:
name: "Jupyter/Notebooks"
needs:
- classify-content
- python-project
runs-on: "ubuntu-latest"
continue-on-error: false
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.python-project.outputs.matrix) }}
# Don't run when pull request is merged, only if Jupyter Notebooks are present
if: needs.classify-content.outputs.notebooks == 'true'
steps:
- uses: actions/checkout@v4
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: "Set up Python ${{ matrix.python-version }}"
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: "Install PDM tooling"
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.python-version }}
- name: "Install notebook/test dependencies"
run: |
# Install notebook/test dependencies
python -m pip install -q --upgrade pip
pdm export -o requirements.txt
if [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
pip install -q .
pip install -q pytest nbmake
- name: "Testing Jupyter notebooks"
run: |
# Testing Jupyter notebooks
# Consider enabling the line below when debugging/testing
# find . -name '*.ipynb'
echo "Running command: pytest --nbmake -- **/*.ipynb"
pytest --nbmake src/*/*.ipynb --cov=src/devops_reusable_workflows
# Might need an __init__.py file in tests folder for notebooks there to be tested?
# https://stackoverflow.com/questions/47287721/coverage-py-warning-no-data-was-collected-no-data-collected
# pytest --nbmake tests/test_*.ipynb --cov=tests
# TEMP DISABLED - NEED TO CHECK - WHERE ARE THESE LOGS GENERATED???
# - name: "Upload Logs"
# if: always()
# uses: actions/upload-artifact@v4
# with:
# name: debug-logs
# path: /tmp/*.log
# retention-days: 14
security:
name: "Security/Audit"
needs:
- classify-content
- python-project
if: needs.classify-content.outputs.python == 'true'
runs-on: "ubuntu-latest"
continue-on-error: true
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.python-project.outputs.matrix) }}
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
- name: "Set up Python ${{ matrix.python-version }}"
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: "Install PDM tooling"
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.python-version }}
- name: "Install dependencies"
run: |
pip install -q --upgrade pip
pdm lock
pdm export -o requirements.txt
python -m pip install -q -r requirements.txt
python -m pip install -q .
pip install --upgrade -q setuptools
pdm list --graph
- name: "Perform package auditing"
uses: pypa/gh-action-pip-audit@v1.1.0