Repository navigation
284 lines (253 loc) · 9.79 KB
/
Copy pathrelease-core.yml
File metadata and controls
284 lines (253 loc) · 9.79 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
---
# Release workflow for pact-python (core package).
#
# This workflow handles the full release lifecycle in three stages:
#
# Stage 1: Prepare (trigger: push to main)
# The `prepare` job runs `scripts/release.py prepare core`, which uses
# git-cliff to compute the next semver from conventional commits, updates
# pyproject.toml and CHANGELOG.md, and force-pushes those changes to the
# fixed branch `release/pact-python`. It then creates (or updates the title
# and body of) the release PR targeting main.
#
# Stage 2: Tag (trigger: release PR merged → `closed` event, merged == true)
# When the release PR on `release/pact-python` is merged, the `tag` job runs
# `scripts/release.py tag core`, which reads the version from pyproject.toml
# and pushes a git tag of the form `pact-python/X.Y.Z`.
#
# Stage 3: Publish (trigger: tag push matching `pact-python/*`)
# The `build` and `publish` jobs build the sdist and wheel, create a GitHub
# release with the changelog, and publish the artifacts to PyPI.
#
# Additional: the `build` job also runs on open/updated PRs (not closed) so
# that release PRs can be verified to build correctly before merging.
#
# The `closed` PR type is listed in the trigger so that Stage 2 fires on merge.
# All jobs except `tag` guard against closed-but-not-merged events with
# explicit `if` conditions.
name: release
on:
push:
branches:
- main
tags:
- pact-python/*
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
- closed
permissions:
contents: read
# Only runs that a newer run fully supersedes share a group, and the newer run
# cancels the older one:
#
# - Push to main: only `prepare` runs, and it rebuilds the release branch from
# scratch.
# - Open or updated PR: only the verification build runs.
#
# Tag pushes and PR merges get a group of their own (the run ID), so nothing can
# cancel them or hold them in the pending queue. The `push` check matters: a
# `closed` PR event sets `github.ref` to the base branch, `refs/heads/main`.
concurrency:
group: >-
${{ github.workflow }}-${{
(
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'pull_request' && github.event.action != 'closed')
) && github.ref || github.run_id
}}
cancel-in-progress: true
env:
# Bump to 3.11 to access tomllib, otherwise, we would use the oldest supported Python version
STABLE_PYTHON_VERSION: '311'
HATCH_VERBOSE: '1'
FORCE_COLOR: '1'
jobs:
complete:
name: Release completion check
if: always()
runs-on: ubuntu-latest
needs:
- prepare
- tag
- build
- publish
steps:
- name: Failed
run: exit 1
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
prepare:
name: Update release PR
if: >-
github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment:
name: release-pr
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ vars.PACT_FOUNDATION_BOT_APP_ID }}
private-key: ${{ secrets.PACT_FOUNDATION_BOT_PRIVATE_KEY }}
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Need full history for git-cliff to determine the next version and
# generate the changelog
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Configure git identity
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
git config user.name "${{ steps.app-token.outputs.app-slug }}[bot]"
git config user.email "$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq '.id')+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com"
- name: Install git-cliff and typos
uses: taiki-e/install-action@682ce6c3c696a4cd5168a05f98e51aa02b877941 # v2.89.1
with:
tool: git-cliff,typos
- name: Set up uv
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
- name: Install Python
run: uv python install ${{ env.STABLE_PYTHON_VERSION }}
- name: Update release PR
run: uv run python scripts/release.py prepare core
env:
# Use the GitHub App token instead of GITHUB_TOKEN so that the PR can
# itself trigger workflows
GH_TOKEN: ${{ steps.app-token.outputs.token }}
tag:
name: Create release tag
if: >-
github.event_name == 'pull_request' && github.event.pull_request.merged == true && github.event.pull_request.head.ref
== 'release/pact-python'
runs-on: ubuntu-latest
environment:
name: release-pr
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ vars.PACT_FOUNDATION_BOT_APP_ID }}
private-key: ${{ secrets.PACT_FOUNDATION_BOT_PRIVATE_KEY }}
- name: Checkout merged release commit
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Tag the release PR's own commit. The tip of main may already hold
# later, unreleased changes.
ref: ${{ github.event.pull_request.merge_commit_sha }}
token: ${{ steps.app-token.outputs.token }}
- name: Configure git identity
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
git config user.name "${{ steps.app-token.outputs.app-slug }}[bot]"
git config user.email "$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq '.id')+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com"
- name: Set up uv
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
- name: Install Python
run: uv python install ${{ env.STABLE_PYTHON_VERSION }}
- name: Create and push release tag
run: uv run python scripts/release.py tag core
env:
# Use the GitHub App token instead of GITHUB_TOKEN so that the tag can
# itself trigger workflows
GH_TOKEN: ${{ steps.app-token.outputs.token }}
build:
name: Build source distribution
# Prepare the wheels for upload, and also verify that the build works on
# release PRs before merging.
if: >-
(
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/pact-python/')
) || (
github.event_name == 'pull_request' &&
github.event.action != 'closed' &&
github.event.pull_request.head.ref == 'release/pact-python'
)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up uv
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
- name: Install Python
run: uv python install ${{ env.STABLE_PYTHON_VERSION }}
- name: Install hatch
run: uv tool install hatch
- name: Build source distribution and wheel
run: hatch build
- name: Upload sdist
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wheels-sdist
path: ./dist/*.tar*
if-no-files-found: error
compression-level: 0
- name: Upload wheel
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: wheels-whl
path: ./dist/*.whl
if-no-files-found: error
compression-level: 0
publish:
name: Publish wheel and sdist
if: >-
github.event_name == 'push' && startsWith(github.ref, 'refs/tags/pact-python/')
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/pact-python
needs:
- build
permissions:
contents: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Extract release changelog
run: |
version="${{ github.ref_name }}"
version="${version#*/}"
out="${{ runner.temp }}/release-changelog.md"
awk -v ver="$version" '
/^## / { if (found) exit; if (index($0, ver)) found=1; next }
found { print }
' CHANGELOG.md > "$out"
if [ ! -s "$out" ]; then
printf '> [!WARNING]\n>\n> No changelog entry found for %s.\n' "$version" > "$out"
fi
- name: Find previous release tag
id: previous-tag
run: |
git fetch --tags --quiet
previous=$(git tag --list 'pact-python/*' --sort=-version:refname \
| grep -v "^${{ github.ref_name }}$" | head -1)
echo "tag=${previous}" >> "$GITHUB_OUTPUT"
- name: Download wheels and sdist
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: wheelhouse
merge-multiple: true
- name: Create GitHub release
uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3
with:
files: wheelhouse/*
body_path: ${{ runner.temp }}/release-changelog.md
previous_tag: ${{ steps.previous-tag.outputs.tag }}
draft: false
prerelease: false
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
skip-existing: true
packages-dir: wheelhouse