-
Notifications
You must be signed in to change notification settings - Fork 3
218 lines (201 loc) · 8.56 KB
/
Copy pathrelease.yml
File metadata and controls
218 lines (201 loc) · 8.56 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
name: release
# Publish a release to PyPI and cut the GitHub Release to match.
#
# Push a tag and this does the rest:
#
# git tag -a v2.3.0 -m "jupyddl 2.3.0" && git push origin v2.3.0
#
# Authentication is PyPI **Trusted Publishing** (OIDC), so there is no API
# token in this repository's secrets to leak or rotate. That requires a
# one-time setup on PyPI — see `docs/RELEASING.md`. Until it is done the
# `pypi` job fails and everything before it still succeeds, so a tag never
# leaves you with half a release and no artifacts.
#
# A release can also be cut entirely from the Actions tab, without anyone
# pushing a tag from a laptop:
#
# Actions -> release -> Run workflow -> target: pypi
#
# That path creates the tag itself, at the commit it built and tested, so the
# tag can never point at something that was never verified. Choosing
# `testpypi` instead runs the identical pipeline against TestPyPI and creates
# no tag, which is how to validate a change to this file without spending a
# real version number. PyPI releases are effectively permanent: a version can
# be yanked but never replaced, so the dry run is worth the two minutes.
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
target:
description: "Where to publish (pypi also tags and cuts the release)"
required: true
default: testpypi
type: choice
options: [testpypi, pypi]
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
jobs:
build:
name: build and verify
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v7
with:
submodules: false
fetch-depth: 0
- uses: actions/setup-python@v7
with:
python-version: '3.12'
- name: Read the version the package declares
id: version
run: |
version=$(python -c "import re,pathlib; \
print(re.search(r'^version = \"([^\"]+)\"', \
pathlib.Path('pyproject.toml').read_text(), re.M).group(1))")
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "pyproject declares $version"
# A tag that disagrees with the package version publishes something
# nobody asked for under a name nobody expects, and PyPI will not let
# you take it back. Refuse before anything is built.
- name: Refuse a tag that disagrees with the package version
if: startsWith(github.ref, 'refs/tags/')
run: |
tag="${GITHUB_REF_NAME#v}"
declared="${{ steps.version.outputs.version }}"
if [ "$tag" != "$declared" ]; then
echo "::error::tag ${GITHUB_REF_NAME} does not match pyproject version ${declared}." \
"Retag, or fix the version, but do not publish a mismatch."
exit 1
fi
echo "tag ${GITHUB_REF_NAME} matches ${declared}"
# jupyddl exports __version__ as well, and a package whose metadata and
# runtime disagree is a support ticket waiting to happen.
- name: Refuse a package whose __version__ disagrees with its metadata
run: |
runtime=$(python -c "import re,pathlib; \
print(re.search(r'^__version__ = \"([^\"]+)\"', \
pathlib.Path('jupyddl/__init__.py').read_text(), re.M).group(1))")
declared="${{ steps.version.outputs.version }}"
if [ "$runtime" != "$declared" ]; then
echo "::error::jupyddl.__version__ is ${runtime} but pyproject says ${declared}"
exit 1
fi
echo "__version__ matches ${declared}"
- name: Build the sdist and the wheel
run: |
python -m pip install --upgrade pip build twine
python -m build
twine check --strict dist/*
# The same smoke test the `build` workflow runs on every push, repeated
# here because this is the artefact that actually goes out.
- name: Install the wheel clean and plan with it
working-directory: /tmp
run: |
python -m venv /tmp/fresh
/tmp/fresh/bin/pip install "$GITHUB_WORKSPACE"/dist/*.whl
installed=$(/tmp/fresh/bin/python -c "import jupyddl; print(jupyddl.__version__)")
if [ "$installed" != "${{ steps.version.outputs.version }}" ]; then
echo "::error::installed wheel reports $installed"
exit 1
fi
/tmp/fresh/bin/jupyddl generate gripper -n 3 --seed 1 -o /tmp/smoke
/tmp/fresh/bin/jupyddl solve \
/tmp/smoke/gripper-03-1/domain.pddl \
/tmp/smoke/gripper-03-1/problem.pddl \
-s astar -H lmcut | tee /tmp/plan.txt
grep -q "Valid: True" /tmp/plan.txt
- name: Extract this version's changelog section
run: |
python - <<'PY' > release-notes.md
import pathlib, re
version = "${{ steps.version.outputs.version }}"
text = pathlib.Path("CHANGELOG.md").read_text(encoding="utf-8")
# Everything between this version's heading and the next one.
match = re.search(
rf"^## \[{re.escape(version)}\][^\n]*\n(.*?)(?=^## \[|\Z)",
text, re.M | re.S,
)
print(match.group(1).strip() if match else
f"See CHANGELOG.md for what changed in {version}.")
PY
cat release-notes.md
- uses: actions/upload-artifact@v7
with:
name: distributions
path: |
dist/
release-notes.md
pypi:
name: publish to ${{ github.event.inputs.target || 'pypi' }}
needs: build
runs-on: ubuntu-latest
# The environment is what a PyPI trusted publisher is scoped to, and it is
# also where a required reviewer can be attached if you ever want a human
# to approve each publish.
environment:
name: ${{ github.event.inputs.target || 'pypi' }}
url: https://pypi.org/project/jupyddl/${{ needs.build.outputs.version }}
permissions:
id-token: write # mint the OIDC token PyPI verifies; no secrets involved
steps:
- uses: actions/download-artifact@v8
with:
name: distributions
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: >-
${{ github.event.inputs.target == 'testpypi'
&& 'https://test.pypi.org/legacy/' || '' }}
# A tag re-run after a partial failure should not fall over on the
# files that already made it.
skip-existing: true
github-release:
name: cut the GitHub release
needs: [build, pypi]
# Either a tag was pushed, or someone asked for a real release from the
# Actions tab. A TestPyPI dry run deliberately creates neither tag nor
# release -- it exists to rehearse, not to leave traces.
#
# Deliberately NOT gated on the publish succeeding. A GitHub Release
# records that a version was cut from a verified commit; PyPI is a
# downstream channel that can fail for reasons the code has nothing to do
# with -- auth not configured, an outage, a rate limit. Losing the tag and
# the release because of that would mean no record of the version and a
# full re-run to get one. `build` succeeding is the gate that matters:
# that is where every check lives. A failed publish stays red and visible,
# and re-running just that job finishes the job.
if: >-
always()
&& needs.build.result == 'success'
&& (startsWith(github.ref, 'refs/tags/')
|| github.event.inputs.target == 'pypi')
runs-on: ubuntu-latest
permissions:
contents: write # create the tag, the release, and attach the artifacts
steps:
- uses: actions/download-artifact@v8
with:
name: distributions
- name: Create the release
uses: softprops/action-gh-release@v3
with:
# Named rather than inherited from the ref, so the dispatch path
# creates `v<version>` at this commit. The release API creates the
# tag when it does not exist, and the build job has already refused
# to get here if the version were inconsistent anywhere.
tag_name: v${{ needs.build.outputs.version }}
target_commitish: ${{ github.sha }}
name: jupyddl ${{ needs.build.outputs.version }}
body_path: release-notes.md
files: dist/*
draft: false
prerelease: ${{ contains(needs.build.outputs.version, 'rc')
|| contains(needs.build.outputs.version, 'a')
|| contains(needs.build.outputs.version, 'b') }}