Repository navigation
81 lines (73 loc) · 3.54 KB
/
Copy pathrc.yml
File metadata and controls
81 lines (73 loc) · 3.54 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
name: rc
# A pre-release tag (`v1.9.0-rc.1`) builds and tests exactly as `release.yml` does, then goes
# to TestPyPI -- a separate index whose database "may be periodically pruned" -- and never to
# PyPI, where a version is permanent. There is no GitHub Release: an RC is not a release.
#
# Before the first RC, once (the owner):
# 1. Create an account on https://test.pypi.org (separate from the PyPI one) and enable 2FA.
# 2. Add a pending Trusted Publisher for project `packvium`: owner `packvium`, repository
# `packvium-python`, workflow `rc.yml`, environment `testpypi`.
# 3. In this repository, create a GitHub environment named `testpypi` with the same
# reviewers as `pypi`.
# 4. Set the repository variable RC_PUBLISHING to `enabled`.
# A consumer then installs it with
# pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ packvium==<version>
on:
push:
tags: ["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/
# Inert until the owner sets the repository variable RC_PUBLISHING to `enabled` (Settings ->
# Secrets and variables -> Actions -> Variables). Without it the job is skipped and the run
# stays green, so an RC tag pushed before the accounts exist publishes nothing.
publish-testpypi:
needs: build
if: vars.RC_PUBLISHING == 'enabled'
runs-on: ubuntu-latest
environment: testpypi
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
with:
repository-url: https://test.pypi.org/legacy/