Repository navigation
231 lines (206 loc) · 7.83 KB
/
Copy pathrelease.yml
File metadata and controls
231 lines (206 loc) · 7.83 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
219
220
221
222
223
224
225
226
227
228
229
230
231
name: Release
# One workflow for a release. Triggered by pushing a version tag (e.g. v3.4.0);
# also runnable manually (workflow_dispatch) as a dry run that verifies and
# builds everything but never publishes.
#
# verify -> build-dist (sdist + wheel) --\
# verify -> build-binaries (db CLI) -----+-> publish-pypi -> github-release
#
# PyPI publishing uses trusted publishing (OIDC), so no API token is stored.
# One-time setup (maintainer): on pypi.org > diffbot > Manage > Publishing, add
# a GitHub publisher with owner `diffbot`, repository `diffbot-python`,
# workflow `release.yml`, and NO environment (leave it blank).
#
# Release candidates: set pyproject.toml to a PEP 440 prerelease (e.g. 3.4.0rc0)
# and push the matching tag (v3.4.0rc0). pip ignores prereleases unless asked
# (`pip install --pre` or `diffbot==3.4.0rc0`), and the GitHub Release is marked
# as a prerelease.
on:
push:
tags: ["v*"]
workflow_dispatch:
permissions:
contents: read
# Never cancel an in-flight run: a cancelled publish could leave PyPI with only
# some of the files for a version (PyPI doesn't allow re-uploading them) or
# leave PyPI and the GitHub Release out of sync. Runs for the same ref queue.
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
verify:
name: Verify version, tests, and types
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.12"
- name: Install dependencies (locked)
run: uv sync --frozen --extra dev
# __version__ is read from the installed distribution metadata, so this
# checks that pyproject.toml's version is what the package reports.
- name: Check tag matches package version
run: |
set -euo pipefail
pkg=$(grep -m1 '^version' pyproject.toml | cut -d'"' -f2)
runtime=$(uv run --frozen python -c 'import diffbot; print(diffbot.__version__)')
if [ "$pkg" != "$runtime" ]; then
echo "::error::pyproject.toml version ${pkg} does not match diffbot.__version__ ${runtime}."
exit 1
fi
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
tag=${GITHUB_REF_NAME#v}
if [ "$pkg" != "$tag" ]; then
echo "::error::Tag v${tag} does not match pyproject.toml version ${pkg}. Bump pyproject.toml (e.g. 'make bump-patch') and re-tag."
exit 1
fi
fi
echo "Package version: ${pkg}"
# Unit tests only: pyproject's addopts deselect `-m live` by default.
- name: Run tests
run: uv run --frozen pytest
- name: Run pyright
run: uv run --frozen pyright
build-dist:
name: Build sdist and wheel
needs: verify
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.12"
- name: Build
run: uv build --sdist --wheel --out-dir dist
- name: Check distributions
run: uvx twine check --strict dist/*
- name: Check built version matches pyproject.toml
run: |
set -euo pipefail
pkg=$(grep -m1 '^version' pyproject.toml | cut -d'"' -f2)
ls dist
test -f "dist/diffbot-${pkg}.tar.gz"
test -f "dist/diffbot-${pkg}-py3-none-any.whl"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: python-dist
path: dist/
if-no-files-found: error
build-binaries:
needs: verify
name: Build ${{ matrix.target_os }}-${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
# Cap the wait so a capacity-starved runner fails this leg in minutes
# instead of hanging the release for GitHub's 24h queue limit.
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
# Built on the oldest practical glibc for forward compatibility.
- runner: ubuntu-22.04
target_os: linux
arch: x86_64
# GitHub-hosted ARM Linux runner: free for public repos; requires a
# Team/Enterprise plan for private repos.
- runner: ubuntu-22.04-arm
target_os: linux
arch: aarch64
# macOS is Apple Silicon only: GitHub's Intel (macos-13) runners are
# being deprecated and their queue is unreliable. Intel-Mac users can
# still `pip install diffbot`.
- runner: macos-15 # Apple Silicon
target_os: darwin
arch: aarch64
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.12"
- name: Build binary
run: ./scripts/build_binary.sh --arch ${{ matrix.arch }}
- name: Verify checksum
working-directory: dist
run: |
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -c "db-${{ matrix.target_os }}-${{ matrix.arch }}.sha256"
else
shasum -a 256 -c "db-${{ matrix.target_os }}-${{ matrix.arch }}.sha256"
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: db-${{ matrix.target_os }}-${{ matrix.arch }}
path: |
dist/db-${{ matrix.target_os }}-${{ matrix.arch }}
dist/db-${{ matrix.target_os }}-${{ matrix.arch }}.sha256
if-no-files-found: error
publish-pypi:
name: Publish to PyPI
# Only after the sdist/wheel AND all db binaries built successfully.
needs: [build-dist, build-binaries]
# Tag pushes only; workflow_dispatch stops after the builds.
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
timeout-minutes: 15
# No GitHub environment: the PyPI trusted publisher has none configured.
permissions:
id-token: write
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: python-dist
path: dist/
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
github-release:
name: Publish GitHub Release
needs: [build-dist, build-binaries, publish-pypi]
runs-on: ubuntu-latest
# Only publish for real tag pushes; workflow_dispatch runs just build + verify.
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: List artifacts
run: ls -lR dist
- name: Publish release
env:
GH_TOKEN: ${{ github.token }}
# This job doesn't check out the repo, so gh can't infer it from a local
# git remote — pass --repo explicitly on every gh call.
run: |
set -euo pipefail
tag="${GITHUB_REF_NAME}"
repo="${GITHUB_REPOSITORY}"
if gh release view "$tag" --repo "$repo" >/dev/null 2>&1; then
echo "Release $tag exists; uploading assets (clobbering)."
gh release upload "$tag" dist/* --repo "$repo" --clobber
else
# PEP 440 pre/dev releases (v3.4.0rc0, v3.4.0a1, v3.4.0b2, v3.4.0.dev1)
# are marked as GitHub prereleases so they never become "Latest".
prerelease=()
if [[ "${tag#v}" =~ (a|b|rc|\.dev)[0-9]+$ ]]; then
prerelease=(--prerelease)
fi
echo "Creating release $tag ${prerelease[*]:-}."
gh release create "$tag" \
--repo "$repo" \
--title "$tag" \
--generate-notes \
"${prerelease[@]}" \
dist/*
fi