-
Notifications
You must be signed in to change notification settings - Fork 11
275 lines (244 loc) · 10.4 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
# We run checks on pushing to the specified branches.
# Pushing to main also triggers a release.
name: Check and Release
on:
push:
branches:
- main
- staging
permissions:
contents: read
jobs:
check:
if: ${{ !startsWith(github.event.commits[0].message, 'bump:') }}
uses: ./.github/workflows/_build.yaml
permissions:
contents: read
with:
disable-pip-audit: ${{ vars.DISABLE_PIP_AUDIT == 'true' }}
# On pushes to the 'main' branch create a new release by bumping the version
# and generating a change log. That's the new bump commit and associated tag.
bump:
needs: check
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
disable-sudo: true
- name: Check out repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
token: ${{ secrets.REPO_ACCESS_TOKEN }}
- name: Set up Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: '3.13'
- name: Set up Commitizen
run: |
pip install --upgrade pip wheel
pip install 'commitizen ==3.31.0'
- name: Set up user
run: |
git config --global user.name "$USER_NAME"
git config --global user.email "$USER_EMAIL"
git config --list --global # For debug purposes.
env:
# This is the username and email for the user who commits and pushes the release
# commit. In an organisation that should be a dedicated devops account.
USER_NAME: jenstroeger
USER_EMAIL: [email protected]
# In some cases a user may merge commits that don't cause a version bump, which causes commitizen
# to fail with error code 21 (NoneIncrementExit). Thus we silence that particular error to avoid
# failing this job: https://commitizen-tools.github.io/commitizen/bump/#avoid-raising-errors
# Furthermore, if the version strings have inconsistent versions then `cz` and CI fail such that
# the issue can be inspected and fixed.
- name: Create changelog and bump
run: cz --no-raise 21 bump --changelog --check-consistency --yes
- name: Push the release
run: |
git push
git push --tags
# When triggered by the version bump commit, build the package and publish the release artifacts.
build:
if: github.ref == 'refs/heads/main' && startsWith(github.event.commits[0].message, 'bump:')
uses: ./.github/workflows/_build.yaml
permissions:
contents: read
with:
disable-pip-audit: ${{ vars.DISABLE_PIP_AUDIT == 'true' }}
# Create a new Release on Github from the verified build artifacts, and optionally
# publish the artifacts to a PyPI server.
release:
needs: [build]
name: Release
outputs:
release-tag: ${{ steps.upload-assets.outputs.release-tag }}
release-url: ${{ steps.upload-assets.outputs.release-url }}
runs-on: ubuntu-latest
permissions:
contents: write # To publish release notes.
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
disable-sudo: true
- name: Check out repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Download artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: artifact-ubuntu-latest-python-3.13
path: dist
# Verify hashes by first computing hashes for the artifacts and then comparing them
# against the hashes computed by the build job.
- name: Verify the artifact hash
env:
ARTIFACT_HASH: ${{ needs.build.outputs.artifacts-sha256 }}
run: |
set -euo pipefail
echo "Hash of package should be $ARTIFACT_HASH."
echo "$ARTIFACT_HASH" | base64 --decode | sha256sum --strict --check --status || exit 1
# Create the Release Notes using commitizen.
- name: Set up Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: '3.13'
- name: Set up Commitizen
run: |
pip install --upgrade pip wheel
pip install 'commitizen ==3.31.0'
- name: Create Release Notes
run: cz changelog --dry-run "$(cz version --project)" > RELEASE_NOTES.md
# Create the release including the artifacts and the SLSA L3 provenance.
- name: Upload assets
id: upload-assets
env:
GH_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
run: |
TAG=$(git describe --tags --abbrev=0)
gh release create "$TAG" dist/* --title "$TAG" --notes-file RELEASE_NOTES.md
echo "release-tag=$TAG" >> "$GITHUB_OUTPUT"
echo "release-url=$(gh release view """$TAG""" --json url --jq .url)" >> "$GITHUB_OUTPUT"
# Uncomment the following steps to publish to a PyPI server.
# At the moment PyPI does not provide a mechanism to publish
# the provenance. So, users have to download the provenance from
# the release page of the GitHub repository to verify the artifact.
# Install Twine without using the package's Makefile to avoid
# installing unnecessary dependencies, which is slow.
# - name: Set up Twine
# run: |
# pip install --upgrade pip wheel
# pip install 'twine ==4.0.2'
# Pass the username, password, and PYPI repository URL via env variables.
# Read the password from GitHub secrets or via other trusted mechanisms.
# Do not hardcode the password in the workflow.
# - name: Publish to PyPI server
# run: twine upload --verbose --skip-existing dist/*.tar.gz dist/*.whl
# env:
# TWINE_USERNAME=<USERNAME>
# TWINE_PASSWORD=<PASSWORD>
# TWINE_REPOSITORY_URL=<REPOSITORY_URL>
# Generate the build provenance. The generator should be referenced with a semantic version.
# The build will fail if we reference it using the commit SHA. To avoid using a pre-built
# provenance generator which depends on an external service Rekor (https://github.com/sigstore/rekor)
# we build this generator from source for now. For more information see this discussion:
# https://github.com/slsa-framework/slsa-github-generator/issues/942
provenance:
needs: [build, release]
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
base64-subjects: ${{ needs.build.outputs.artifacts-sha256 }}
compile-generator: false # Do not build the provenance generator from source anymore.
# Set private-repository to true for private repositories. Note that the repository name is
# uploaded as part of the transparency log entry on the public Rekor instance (rekor.sigstore.dev).
private-repository: false
permissions:
actions: read # To read the workflow path.
id-token: write # To sign the provenance.
contents: write # To add assets to a release.
# Publish the SLSA provenance as the GitHub release asset.
publish_provenance:
needs: [release, provenance]
name: Publish provenance
runs-on: ubuntu-latest
permissions:
contents: write # To publish release notes.
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
disable-sudo: true
- name: Check out repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Download provenance
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: ${{ needs.provenance.outputs.provenance-name }}
- name: Upload provenance
run: gh release upload ${{ needs.release.outputs.release-tag }} ${{ needs.provenance.outputs.provenance-name }}
env:
GH_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
# Send out release notifications after the Release was published on GitHub.
# Uncomment the `if` to disable sending release notifications.
notifications:
# if: ${{ false }}
needs: [release]
name: Send Release notifications
uses: ./.github/workflows/_release-notifications.yaml
permissions:
contents: read
with:
repo-name: ${{ github.event.repository.name }}
release-tag: ${{ needs.release.outputs.release-tag }}
release-url: ${{ needs.release.outputs.release-url }}
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# Publish the generated Markdown documentation to the repository's Wiki.
# Uncomment the `if` to disable generating Wiki documentation.
wiki:
# if: ${{ false }}
needs: [release]
name: Publish Github Wiki documentation
uses: ./.github/workflows/_wiki-documentation.yaml
permissions:
contents: read
with:
release-tag: ${{ needs.release.outputs.release-tag }}
release-url: ${{ needs.release.outputs.release-url }}
# Github disallows passing environment variables as arguments to a reusable
# workflow, so we have to duplicate these values here. Related discussion
# here: https://github.com/actions/toolkit/issues/931
artifact-name: artifact-ubuntu-latest-python-3.13
git-user-name: jenstroeger
git-user-email: [email protected]
secrets:
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
# After the bump commit was pushed to the main branch, rebase the staging branch
# (to_head argument) on top of the new main branch (from_base argument), to keep
# the histories of both branches in sync.
rebase_staging:
# if: ${{ false }}
needs: [release]
name: Rebase staging branch on main
uses: ./.github/workflows/_generate-rebase.yaml
permissions:
contents: read
with:
to-head: staging
from-base: origin/main
git-user-name: jenstroeger
git-user-email: [email protected]
secrets:
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}