Skip to content

Commit b7937a8

Browse files
shixishclaude
andcommitted
ci: merge PyPI publishing into release.yml (no environment)
One Release workflow on v* tags: verify, build sdist/wheel and db binaries, publish to PyPI via trusted publishing (after binaries build), then the GitHub Release. Concurrency never cancels an in-flight publish. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 9ad9f63 commit b7937a8

4 files changed

Lines changed: 131 additions & 161 deletions

File tree

‎.github/workflows/publish-pypi.yml‎

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

‎.github/workflows/release.yml‎

Lines changed: 121 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,110 @@
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).
614
on:
715
push:
816
tags: ["v*"]
917
workflow_dispatch:
1018

1119
permissions:
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.
1625
concurrency:
1726
group: release-${{ github.ref }}
18-
cancel-in-progress: true
27+
cancel-in-progress: false
1928

2029
jobs:
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

‎Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ _release-test:
6262
UV_PUBLISH_TOKEN="$$TOKEN" uv publish --publish-url https://test.pypi.org/legacy/
6363

6464
# MANUAL FALLBACK ONLY. The normal release path is CI: merge to main, then push
65-
# a tag vX.Y.Z matching pyproject.toml; .github/workflows/publish-pypi.yml
65+
# a tag vX.Y.Z matching pyproject.toml; .github/workflows/release.yml
6666
# publishes to PyPI via trusted publishing (no token). Use this target only if
6767
# that workflow is unavailable. It uploads with a token from macOS Keychain
6868
# (service: pypi-token-pypi) after a confirmation gate (PyPI does not allow
6969
# re-uploads).
7070
release: build _release
7171

7272
_release:
73-
@echo "NOTE: 'make release' is the manual fallback; normally push tag vX.Y.Z and let publish-pypi.yml publish."
73+
@echo "NOTE: 'make release' is the manual fallback; normally push tag vX.Y.Z and let release.yml publish."
7474
@VERSION=$$(grep '^version' $(PYPROJECT) | head -1 | cut -d'"' -f2) && \
7575
STATUS=$$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/$(PKG)/$$VERSION/json") && \
7676
if [ "$$STATUS" = "200" ]; then \

‎README.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,14 @@ Releases are published by CI; nothing is uploaded from a laptop.
535535
git tag vX.Y.Z && git push origin vX.Y.Z
536536
```
537537

538-
The tag must match the `pyproject.toml` version. Pushing it runs two workflows:
539-
[`publish-pypi.yml`](.github/workflows/publish-pypi.yml) checks the version, runs the
540-
unit tests and pyright, builds the sdist and wheel, and publishes them to PyPI via
541-
[trusted publishing](https://docs.pypi.org/trusted-publishers/) (no API token), and
542-
[`release.yml`](.github/workflows/release.yml) builds the standalone `db` binaries
543-
and attaches them to a GitHub Release. Running `publish-pypi.yml` manually
544-
(workflow_dispatch) is a dry run: it builds and checks but never uploads.
538+
The tag must match the `pyproject.toml` version. Pushing it runs one workflow,
539+
[`release.yml`](.github/workflows/release.yml), which checks the version, runs the
540+
unit tests and pyright, builds the sdist and wheel and the standalone `db`
541+
binaries, then publishes to PyPI via
542+
[trusted publishing](https://docs.pypi.org/trusted-publishers/) (no API token, no
543+
GitHub environment; only after the binaries build) and attaches the binaries to a
544+
GitHub Release. Running `release.yml` manually (workflow_dispatch) is a dry run: it
545+
builds and checks but never publishes.
545546

546547
`make release` (token from macOS Keychain) remains only as a manual fallback for
547548
when the workflow can't be used.

0 commit comments

Comments
 (0)