1- name : Release Binaries
1+ name : Release
22
3- # Builds the self-contained `db` CLI binary for each supported platform and
4- # publishes them (with SHA256 checksums) to a GitHub Release. Triggered by
5- # pushing a version tag (e.g. v0.2.1); also runnable manually for dry runs.
3+ # One workflow for a release. Triggered by pushing a version tag (e.g. v3.4.0);
4+ # also runnable manually (workflow_dispatch) as a dry run that verifies and
5+ # builds everything but never publishes.
6+ #
7+ # verify -> build-dist (sdist + wheel) --\
8+ # verify -> build-binaries (db CLI) -----+-> publish-pypi -> github-release
9+ #
10+ # PyPI publishing uses trusted publishing (OIDC), so no API token is stored.
11+ # One-time setup (maintainer): on pypi.org > diffbot > Manage > Publishing, add
12+ # a GitHub publisher with owner `diffbot`, repository `diffbot-python`,
13+ # workflow `release.yml`, and NO environment (leave it blank).
614on :
715 push :
816 tags : ["v*"]
917 workflow_dispatch :
1018
1119permissions :
12- contents : write
20+ contents : read
1321
14- # Re-pushing a tag (or re-dispatching) cancels an in-flight run for the same
15- # ref so a stuck build can't pile up behind a newer attempt.
22+ # Never cancel an in-flight run: a cancelled publish could leave PyPI with only
23+ # some of the files for a version (PyPI doesn't allow re-uploading them) or
24+ # leave PyPI and the GitHub Release out of sync. Runs for the same ref queue.
1625concurrency :
1726 group : release-${{ github.ref }}
18- cancel-in-progress : true
27+ cancel-in-progress : false
1928
2029jobs :
21- build :
30+ verify :
31+ name : Verify version, tests, and types
32+ runs-on : ubuntu-latest
33+ timeout-minutes : 20
34+ steps :
35+ - uses : actions/checkout@v4
36+
37+ - name : Install uv
38+ uses : astral-sh/setup-uv@v5
39+ with :
40+ python-version : " 3.12"
41+
42+ - name : Install dependencies (locked)
43+ run : uv sync --frozen --extra dev
44+
45+ # __version__ is read from the installed distribution metadata, so this
46+ # checks that pyproject.toml's version is what the package reports.
47+ - name : Check tag matches package version
48+ run : |
49+ set -euo pipefail
50+ pkg=$(grep -m1 '^version' pyproject.toml | cut -d'"' -f2)
51+ runtime=$(uv run --frozen python -c 'import diffbot; print(diffbot.__version__)')
52+ if [ "$pkg" != "$runtime" ]; then
53+ echo "::error::pyproject.toml version ${pkg} does not match diffbot.__version__ ${runtime}."
54+ exit 1
55+ fi
56+ if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
57+ tag=${GITHUB_REF_NAME#v}
58+ if [ "$pkg" != "$tag" ]; then
59+ echo "::error::Tag v${tag} does not match pyproject.toml version ${pkg}. Bump pyproject.toml (e.g. 'make bump-patch') and re-tag."
60+ exit 1
61+ fi
62+ fi
63+ echo "Package version: ${pkg}"
64+
65+ # Unit tests only: pyproject's addopts deselect `-m live` by default.
66+ - name : Run tests
67+ run : uv run --frozen pytest
68+
69+ - name : Run pyright
70+ run : uv run --frozen pyright
71+
72+ build-dist :
73+ name : Build sdist and wheel
74+ needs : verify
75+ runs-on : ubuntu-latest
76+ timeout-minutes : 15
77+ steps :
78+ - uses : actions/checkout@v4
79+
80+ - name : Install uv
81+ uses : astral-sh/setup-uv@v5
82+ with :
83+ python-version : " 3.12"
84+
85+ - name : Build
86+ run : uv build --sdist --wheel --out-dir dist
87+
88+ - name : Check distributions
89+ run : uvx twine check --strict dist/*
90+
91+ - name : Check built version matches pyproject.toml
92+ run : |
93+ set -euo pipefail
94+ pkg=$(grep -m1 '^version' pyproject.toml | cut -d'"' -f2)
95+ ls dist
96+ test -f "dist/diffbot-${pkg}.tar.gz"
97+ test -f "dist/diffbot-${pkg}-py3-none-any.whl"
98+
99+ - name : Upload artifact
100+ uses : actions/upload-artifact@v4
101+ with :
102+ name : python-dist
103+ path : dist/
104+ if-no-files-found : error
105+
106+ build-binaries :
107+ needs : verify
22108 name : Build ${{ matrix.target_os }}-${{ matrix.arch }}
23109 runs-on : ${{ matrix.runner }}
24110 # Cap the wait so a capacity-starved runner fails this leg in minutes
@@ -46,20 +132,6 @@ jobs:
46132 steps :
47133 - uses : actions/checkout@v4
48134
49- # Fail fast if the tag doesn't match pyproject.toml's version, so the
50- # GitHub Release name can never disagree with the version the binaries
51- # report (db --version) or the one published to PyPI.
52- - name : Check tag matches package version
53- if : startsWith(github.ref, 'refs/tags/')
54- run : |
55- pkg=$(grep -m1 '^version' pyproject.toml | cut -d'"' -f2)
56- tag=${GITHUB_REF_NAME#v}
57- if [ "$pkg" != "$tag" ]; then
58- echo "::error::Tag v${tag} does not match pyproject.toml version ${pkg}. Bump pyproject.toml (e.g. 'make bump-patch') and re-tag."
59- exit 1
60- fi
61- echo "Tag and package version agree: ${pkg}"
62-
63135 - name : Install uv
64136 uses : astral-sh/setup-uv@v5
65137 with :
@@ -86,12 +158,35 @@ jobs:
86158 dist/db-${{ matrix.target_os }}-${{ matrix.arch }}.sha256
87159 if-no-files-found : error
88160
89- release :
161+ publish-pypi :
162+ name : Publish to PyPI
163+ # Only after the sdist/wheel AND all db binaries built successfully.
164+ needs : [build-dist, build-binaries]
165+ # Tag pushes only; workflow_dispatch stops after the builds.
166+ if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
167+ runs-on : ubuntu-latest
168+ timeout-minutes : 15
169+ # No GitHub environment: the PyPI trusted publisher has none configured.
170+ permissions :
171+ id-token : write
172+ steps :
173+ - name : Download artifact
174+ uses : actions/download-artifact@v4
175+ with :
176+ name : python-dist
177+ path : dist/
178+
179+ - name : Publish
180+ uses : pypa/gh-action-pypi-publish@release/v1
181+
182+ github-release :
90183 name : Publish GitHub Release
91- needs : build
184+ needs : [ build-dist, build-binaries, publish-pypi]
92185 runs-on : ubuntu-latest
93186 # Only publish for real tag pushes; workflow_dispatch runs just build + verify.
94- if : startsWith(github.ref, 'refs/tags/')
187+ if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
188+ permissions :
189+ contents : write
95190 steps :
96191 - name : Download all artifacts
97192 uses : actions/download-artifact@v4
0 commit comments