Skip to content

Commit 9604839

Browse files
committed
chore(ci): automate release process
This PR significant changes the release process, by mostly automating it all. The docs on creating releases has been updated and moved into the `docs/` folder (anticipating that we will use MkDocs eventually). The check step in the build pipeline has been removed, as it is redundant given that cibuildwheel already does checks. Signed-off-by: JP-Ellis <[email protected]>
1 parent e9898fa commit 9604839

File tree

6 files changed

+121
-128
lines changed

6 files changed

+121
-128
lines changed

.github/CHANGELOG.md.j2

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% for entry in tree %}
2+
3+
## {{ entry.version }}{% if entry.date %} ({{ entry.date }}){% endif %}
4+
5+
{% for change_key, changes in entry.changes.items() %}
6+
7+
{% if change_key %}
8+
### {{ change_key }}
9+
{% endif %}
10+
11+
{% for change in changes %}
12+
{% if change.scope %}
13+
- **{{ change.scope }}**: {{ change.message }}
14+
{% elif change.message %}
15+
- {{ change.message }}
16+
{% endif %}
17+
{% endfor %}
18+
{% endfor %}
19+
{% endfor %}

.github/workflows/build.yml

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ env:
2020
CIBW_BUILD_FRONTEND: build
2121

2222
jobs:
23-
build-sdit:
23+
build-sdist:
2424
name: Build source distribution
2525

2626
if: github.event_name == 'push' || ! github.event.pull_request.draft
@@ -114,7 +114,7 @@ jobs:
114114
build-arm64:
115115
name: Build wheels on ${{ matrix.os }} (arm64)
116116

117-
# As this requires emulation, it's not worth running on PRs
117+
# As this requires emulation, it's not worth running on PRs or master
118118
if: >-
119119
github.event_name == 'push' &&
120120
startsWith(github.event.ref, 'refs/tags')
@@ -189,26 +189,75 @@ jobs:
189189
pipx run twine check --strict wheelhouse/*
190190
191191
publish:
192-
name: Publish wheels
192+
name: Publish wheels and sdist
193193

194194
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
195195
runs-on: ubuntu-latest
196196
environment: pypi
197197

198-
needs: [check]
198+
needs:
199+
- build-sdist
200+
- build-x86_64
201+
- build-arm64
199202

200203
permissions:
201204
# Required for trusted publishing
202205
id-token: write
206+
# Required for release creation
207+
contents: write
203208

204209
steps:
205210
- uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4
206211
with:
207212
path: wheels
213+
merge-multiple: true
214+
215+
- name: Setup Python
216+
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5
217+
with:
218+
python-version: ${{ env.STABLE_PYTHON_VERSION }}
219+
220+
- name: Update changelog
221+
id: changelog
222+
run: |
223+
pip install --upgrade commitizen
224+
225+
cz changelog \
226+
--incremental \
227+
--template .github/CHANGELOG.md.j2 \
228+
--dry-run \
229+
| tail -n+2 \
230+
> ${{ runner.temp }}/changelog
231+
echo -e "\n\n## Pull Requests\n\n" >> ${{ runner.temp }}/changelog
232+
233+
cz changelog \
234+
--incremental \
235+
--template .github/CHANGELOG.md.j2
236+
237+
- name: Generate release
238+
id: release
239+
uses: softprops/action-gh-release@v1
240+
with:
241+
files: wheels/*
242+
body_path: ${{ runner.temp }}/changelog
243+
draft: false
244+
prerelease: false
245+
generate_release_notes: true
208246

209247
- name: Push build artifacts to PyPI
210248
uses: pypa/gh-action-pypi-publish@e53eb8b103ffcb59469888563dc324e3c8ba6f06 # v1.8.12
211249
with:
212250
skip-existing: true
213251
password: ${{ secrets.PYPI_TOKEN }}
214252
packages-dir: wheels
253+
254+
- name: Create PR for changelog update
255+
uses: peter-evans/create-pull-request@v6
256+
with:
257+
token: ${{ secrets.GH_TOKEN }}
258+
commit-message: "chore: update changelog ${{ github.ref_name }}"
259+
title: "chore: update changelog"
260+
body: |
261+
This PR updates the changelog for ${{ github.ref_name }}.
262+
branch: chore/update-changelog
263+
base: master

RELEASING.md

Lines changed: 0 additions & 54 deletions
This file was deleted.

docs/releases.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Releases
2+
3+
Pact Python is made available through both GitHub releases and PyPI. The GitHub releases also come with a summary of changes and contributions since the last release.
4+
5+
The entire process is automated through the [build](https://github.com/pact-foundation/pact-python/actions?query=workflow%3Abuild) GitHub Action. A description of the process is provided [below](#build-pipeline).
6+
7+
## Versioning
8+
9+
Pact Python follows [semantic versioning](https://semver.org/). Breaking changes are indicated by a major version bump, new features by a minor version bump, and bug fixes by a patch version bump.
10+
11+
There are a couple of exceptions to the [semantic versioning](https://semver.org/) rules:
12+
13+
- Dropping support for a Python version is not considered a breaking change and is not necessarily accompanied by a major version bump.
14+
- Private APIs are not considered part of the public API and are not subject to the same rules as the public API. They can be changed at any time without a major version bump. Private APIs are denoted by a leading underscore in the name. Please be aware that the distinction between public and private APIs will be made concrete from version 3 onwards, and best judgement is used in the meantime to determine what is public and what is private.
15+
- Deprecations are not considered breaking changes and are not necessarily accompanied by a major version bump. Their removal is considered a breaking change and is accompanied by a major version bump.
16+
17+
Any deviation from the the standard semantic versioning rules will be clearly documented in the release notes.
18+
19+
The version is stored in `pact/__version__.py`. This file is automatically generated by [`hatch-vcs`](https://pypi.org/project/hatch-vcs/) and generates a version based on the latest version tag and the number of commits since that tag. Specifically:
20+
21+
- If the latest tag is `v1.2.3` and there have been no commits since then and the repository is clean, the version will be `1.2.3`.
22+
- Otherwise, the version will take the form of `1.2.3.dev{N}+g{hash}` (or `1.2.3.dev{N}+g{hash}.d{date}` if there's a dirty repository) where `N` is the number of commits since the latest tag, `hash` is the short hash of the latest commit.
23+
24+
## Build Pipeline
25+
26+
The build pipeline is defined in `.github/workflows/build.yml`. It is triggered on PRs targeting `master`, pushes to the `master` branch, and on every new tag. The pipeline is responsible for building the package (both as source distribution, and compiled wheels), creating the GitHub release, and uploading artifacts to PyPI.
27+
28+
### Build Steps
29+
30+
The build steps generates the source distribution and wheels. This is done using [cibuildwheel](https://cibuildwheel.readthedocs.io/) to ensure that the wheels are compatible with a wide range of Python versions and platforms.
31+
32+
In order to reduce the build time, the pipeline builds different sets of wheels depending on the trigger:
33+
34+
| Trigger | Platforms | Wheels |
35+
| ------------ | ----------------- | --------- |
36+
| Tag | `x86_64`, `arm64` | all |
37+
| `master` | `x86_64` | all |
38+
| Pull Request | `x86_64` | `cp312-*` |
39+
40+
### Publish Step
41+
42+
The publish step uses the `pypi` GitHub environment, and is gated behind a manual approval. The publish step is responsible for the following:
43+
44+
- Generating a changelog based on the conventional commits since the latest release.
45+
- Generating a new GitHub release with the changelog.
46+
- Uploading the source distribution and wheels to PyPI.
47+
- Creating a PR to update the `CHANGELOD.md` file with the new release notes.
48+
49+
While the generated changelog should be accurate, it may require some manual adjustments on the release page and in the PR.

script/commit_message.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

script/release_prep.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)