Repository navigation
114 lines (105 loc) · 4.91 KB
/
Copy pathrelease.yml
File metadata and controls
114 lines (105 loc) · 4.91 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
name: release
# Publishing is driven by a tag, and only by a tag. There is no manual upload step and
# no API token anywhere in this repository: PyPI Trusted Publishing exchanges this
# workflow's OIDC identity for a short-lived credential, so there is no long-lived
# secret to leak or rotate (the failure mode a leaked token creates simply cannot occur here).
#
# Before the first run, configure the publisher once on PyPI:
# Project -> Publishing -> Add a new GitHub publisher
# owner = <this repository's owner>, repository = <this repository>,
# workflow = release.yml, environment = pypi
# and create a GitHub environment named `pypi` with whatever reviewers the project
# wants. The environment is what turns "anyone who can push a tag" into "a release a
# named person approved".
# A pre-release tag (`v1.9.0-rc.1`) never reaches the production registries: the negated
# pattern must follow the positive one, and `rc.yml` takes those tags instead.
on:
push:
tags: ["v*", "!v*-*"]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: "3.12"
- run: python -m pip install --upgrade pip build twine
- run: python -m build
- run: python -m twine check --strict dist/*
# The tag and the packaged version must agree. Without this, `git tag v0.2.0` on a
# tree that still says 0.1.0 publishes 0.1.0 under a name that claims otherwise,
# and the mistake is only visible after it is public and immutable.
- name: The tag must match the version in the distribution
run: |
tagged="${GITHUB_REF_NAME#v}"
built=$(python -c "import tomllib,pathlib; print(tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']['version'])")
if [ "$tagged" != "$built" ]; then
echo "tag $GITHUB_REF_NAME does not match pyproject version $built" >&2
exit 1
fi
- name: Install the built wheel into a clean environment and re-run the tests
run: |
python -m venv /tmp/clean
/tmp/clean/bin/python -m pip install --quiet pytest
/tmp/clean/bin/python -m pip install --quiet --no-index --find-links dist packvium
/tmp/clean/bin/python -m pytest tests -q
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: distributions
path: dist/
publish:
needs: build
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write # OIDC, for Trusted Publishing and for the attestation
attestations: write # build provenance, so a consumer can verify where a file came from
steps:
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: distributions
path: dist/
- uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1
with:
subject-path: dist/*
- uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
# Rule 3: every tag gets a GitHub Release. A tag is a git object; a Release is what a
# human and a maintenance scorer can read, and cadence is a signal tags do not carry.
# Every mirror had every tag and zero Releases until 1.1.0, whose six were created by
# hand -- which is how the rule was being met, and therefore how it would stop being met.
github-release:
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write # the Release is the only thing this workflow writes to the repository
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- name: Create the GitHub Release from the tag
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
echo "Release $GITHUB_REF_NAME already exists; nothing to do."
exit 0
fi
# This version's entry, from its heading to the next one. A tag whose version has
# no entry would publish a Release nobody can read, so that fails the job rather
# than shipping an empty one.
awk -v want="## [$version]" '
index($0, want) == 1 { inside = 1; next }
inside && /^## \[/ { exit }
inside { print }
' CHANGELOG.md > release-notes.md
if [ ! -s release-notes.md ]; then
echo "CHANGELOG.md carries no entry for $version" >&2
exit 1
fi
gh release create "$GITHUB_REF_NAME" \
--title "Packvium $version" \
--notes-file release-notes.md \
--verify-tag