-
Notifications
You must be signed in to change notification settings - Fork 4
288 lines (252 loc) · 9 KB
/
test-gha-workflows.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
---
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2024 The Linux Foundation <https://linuxfoundation.org>
name: "🧪 Test GitHub Actions/Workflows"
# yamllint disable-line rule:truthy
on:
workflow_dispatch:
push:
branches: [main, master]
# paths: [".github/actions/**", ".github/workflows/**"]
env:
default-python: "3.10"
artefacts: "dist"
jobs:
### Test Individual Composite Actions ###
test:
name: "Validate Actions/Workflows"
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
# Does not currently work: https://github.com/actions/checkout/issues/1471
fetch-tags: true
# latest-semantic-tag currently contains a workaround for this behaviour
- name: "Action: semantic-tag-latest"
id: semantic-tag-latest
# yamllint disable-line rule:line-length
uses: os-climate/devops-reusable-workflows/.github/actions/semantic-tag-latest@main
- name: "Action: semantic-tag-increment"
id: semantic-tag-increment
# yamllint disable-line rule:line-length
uses: os-climate/devops-reusable-workflows/.github/actions/semantic-tag-increment@main
with:
tag: "${{ steps.semantic-tag-latest.outputs.TAG }}"
type: "minor"
### Primary Python Workflow Testing ###
identify-content:
name: "Identify Content"
runs-on: ubuntu-latest
outputs:
python: ${{ steps.identify-content.outputs.python }}
notebooks: ${{ steps.identify-content.outputs.notebooks }}
steps:
- uses: actions/checkout@v4
- name: "Identify Content"
id: identify-content
run: |
# Inspect files in repository
# Check if repository contains a Python project
if [ -f pyproject.toml ]; then
echo "Python project metadata found"
echo "python=true" >> "$GITHUB_OUTPUT"
else
echo "python=false" >> "$GITHUB_OUTPUT"
fi
# Check if repository contains Jupyter Notebooks
NOTEBOOKS=$(find . -name '*.ipynb' | wc -l )
if [ "$NOTEBOOKS" -ne 0 ]; then
echo "Jupyter notebooks found"
echo "notebooks=true" >> "$GITHUB_OUTPUT"
else
echo "notebooks=false" >> "$GITHUB_OUTPUT"
fi
python-project:
name: "Python Project"
needs:
- identify-content
if: needs.identify-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/devops-reusable-workflows/.github/actions/python-versions-matrix@main
python-build:
name: "Python Build"
needs:
- python-project
runs-on: "ubuntu-latest"
continue-on-error: true
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.python-project.outputs.matrix) }}
permissions:
contents: write
# Required by SigStore signing action
id-token: write
outputs:
publish: ${{ steps.python-project-build.outputs.publish }}
steps:
- uses: actions/checkout@v4
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: "Setup PDM Build Tool"
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.python-version }}
- name: "Action: semantic-tag-latest"
id: semantic-tag-latest
# yamllint disable-line rule:line-length
uses: os-climate/devops-reusable-workflows/.github/actions/semantic-tag-latest@main
- name: "🏷️ Create initial tag"
id: set-initial-tag
if: steps.semantic-tag-latest.outputs.tag-missing == 'true'
# https://github.com/softprops/action-gh-release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
tag_name: v0.0.1
- name: "Build: Python Project"
id: python-project-build
if: steps.semantic-tag-latest.outputs.missing == 'false'
# yamllint disable-line rule:line-length
uses: os-climate/devops-reusable-workflows/.github/actions/python-project-build@main
with:
artefacts: ${{ env.artefacts}}
- name: "Validate Artefacts with Twine"
id: python-twine-check
with:
artefacts: ${{ env.artefacts}}
uses: os-climate/devops-reusable-workflows/.github/actions/python-twine-check@main
- name: "Sign packages with Sigstore"
uses: sigstore/[email protected]
env:
package-path: ${{ env.artefacts }}
with:
inputs: >-
./${{ env.artefacts }}/*.tar.gz
./${{ env.artefacts }}/*.whl
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: ${{ github.ref_name }}
path: ${{ env.artefacts }}
github:
name: "📦 Publish to GitHub"
# Only publish on tag pushes
needs: python-build
runs-on: ubuntu-latest
permissions:
# IMPORTANT: mandatory to publish artefacts
contents: write
steps:
- name: "⬇ Download build artefacts"
uses: actions/download-artifact@v4
with:
name: ${{ github.ref_name }}
path: ${{ env.artefacts }}
- name: "🌥️ Set environment variables"
id: setenv
run: |
# vernum="${{ env.default-python }}.$(date +'%Y%m%d%H%M')"
datetime="$(date +'%Y%m%d%H%M')"
echo "datetime=${datetime}" >> "$GITHUB_OUTPUT"
- name: "📦 Publish DEVELOPMENT artefacts to GitHub"
if: startsWith(github.ref, 'refs/tags/') != true
# https://github.com/softprops/action-gh-release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
tag_name: ${{ github.ref_name }}-dev
name: "Test/Development Build: ${{ github.ref_name }}"
# body_path: ${{ github.workspace }}/CHANGELOG.rst
files: |
${{ env.artefacts }}/*.tar.gz
${{ env.artefacts }}/*.whl
${{ env.artefacts }}/*.sigstore*
- name: "📦 Publish PRODUCTION artefacts to GitHub"
if: startsWith(github.ref, 'refs/tags/')
# https://github.com/softprops/action-gh-release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: false
tag_name: ${{ github.ref_name }}
name: "Test/Development Build: ${{ github.ref_name }}"
# body_path: ${{ github.workspace }}/CHANGELOG.rst
files: |
${{ env.artefacts }}/*.tar.gz
${{ env.artefacts }}/*.whl
${{ env.artefacts }}/*.sigstore*
testpypi:
name: "📦 Test PyPI publishing"
# Only publish on tag pushes
# if: startsWith(github.ref, 'refs/tags/')
needs: python-build
runs-on: ubuntu-latest
environment:
name: testpypi
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.artefacts }}
- name: "Validate build artefacts"
id: files
run: |
if [ -f ${{ env.artefacts }}/buildvars.txt ]; then
rm ${{ env.artefacts }}/buildvars.txt
fi
if (ls ${{ env.artefacts }}/*.sigstore*); then
rm ${{ env.artefacts }}/*.sigstore*
fi
- name: "Publish to test PyPI"
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
verbose: true
packages-dir: ${{ env.artefacts }}
pypi:
name: "📦 Publish to PyPI"
# Only publish on tag pushes
if:
startsWith(github.ref, 'refs/tags/') &&
needs.python-build.outputs.publish == 'true'
# contains(github.event.head_commit.message, '[release]')
needs: [python-build, testpypi]
runs-on: ubuntu-latest
environment:
name: pypi
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.artefacts }}
- name: "Remove files unsupported by PyPi"
run: |
if (ls ${{ env.artefacts }}/*.sigstore*); then
rm ${{ env.artefacts }}/*.sigstore*
fi
# - name: "📦 Publish to PyPI"
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# verbose: true
# packages-dir: ${{ env.artefacts }}