Skip to content

Commit 817d467

Browse files
pdepetrometa-codesync[bot]
authored andcommitted
Add GitHub workflow to publish to PyPI
Summary: Adds `.github/workflows/release.yml` so tintype can be published to PyPI from GitHub Actions. The workflow builds platform-specific wheels via cibuildwheel (needed because tintype has a pybind11 C++ extension), plus an sdist, and publishes via OIDC Trusted Publishing (no API tokens stored as secrets). - Triggers: - Push tag `v*` → publish to TestPyPI (validation channel) - GitHub Release published → publish to PyPI (production) - `workflow_dispatch` → manual TestPyPI publish - Matrix: `ubuntu-latest` + `macos-latest`. Windows is intentionally omitted because the C++ code in `snapshot_lib/` doesn't currently compile on MSVC. - `CIBW_BUILD`: cp312 + cp313. `CIBW_SKIP` drops manylinux_i686 and musllinux. - `CIBW_ARCHS_MACOS: "x86_64 arm64"` so Intel Mac users get a wheel too (macos-latest runners are now Apple Silicon). - Least-privilege `permissions: contents: read` at workflow level; `id-token: write` only on the publish jobs. - Concurrency cancels in-flight tag/manual runs on the same ref but NEVER cancels a `release: published` run mid-publish. - `skip-existing: true` on TestPyPI publish (manual re-runs are idempotent), not on PyPI publish (duplicates must fail loudly). Follow-ups for the maintainer (out of scope for this commit): - Configure Trusted Publisher on pypi.org + test.pypi.org (see comment in file). - Create GitHub `pypi` + `testpypi` environments in repo settings. - Bump hard-coded version in pyproject.toml (or migrate to setuptools-scm) before tagging. Reviewed By: youngd007 Differential Revision: D103339939 fbshipit-source-id: c3a39e343cb659f665a6b5fe1b55a07667dd6cf7
1 parent 7e0bb0d commit 817d467

1 file changed

Lines changed: 131 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Release
2+
3+
# Build platform-specific wheels + sdist and publish to (Test)PyPI.
4+
#
5+
# Publishing uses OIDC Trusted Publishing, so no API tokens are stored in
6+
# GitHub secrets. This requires one-time configuration on each index:
7+
#
8+
# 1. On https://pypi.org and https://test.pypi.org, go to the project's
9+
# "Publishing" settings (or create a pending publisher if the project
10+
# does not yet exist) and add a Trusted Publisher with:
11+
# - Owner: <github-org-or-user>
12+
# - Repository name: tintype
13+
# - Workflow name: release.yml
14+
# - Environment name: pypi (for PyPI)
15+
# testpypi (for TestPyPI)
16+
# See https://docs.pypi.org/trusted-publishers/ for details.
17+
#
18+
# 2. In this repo's GitHub settings, create two environments named
19+
# "pypi" and "testpypi" (Settings -> Environments -> New environment).
20+
# Optionally add required reviewers for the "pypi" environment so that
21+
# production releases require manual approval.
22+
23+
on:
24+
push:
25+
tags:
26+
- 'v*'
27+
release:
28+
types: [published]
29+
workflow_dispatch:
30+
31+
permissions:
32+
contents: read
33+
34+
# Cancel in-progress runs for the same ref on tag pushes and manual runs,
35+
# but NOT on release: published events — we don't want to cancel a real
36+
# PyPI publish mid-flight.
37+
concurrency:
38+
group: ${{ github.workflow }}-${{ github.ref }}
39+
cancel-in-progress: ${{ github.event_name != 'release' }}
40+
41+
jobs:
42+
build_wheels:
43+
name: build_wheels (${{ matrix.os }})
44+
runs-on: ${{ matrix.os }}
45+
timeout-minutes: 60
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
os: [ubuntu-latest, macos-latest]
50+
51+
steps:
52+
- uses: actions/checkout@v4
53+
with:
54+
submodules: recursive
55+
56+
- name: Build wheels
57+
uses: pypa/cibuildwheel@v2
58+
env:
59+
CIBW_BUILD: "cp312-* cp313-*"
60+
CIBW_SKIP: "*-manylinux_i686 *-musllinux*"
61+
CIBW_ARCHS_MACOS: "x86_64 arm64"
62+
63+
- name: Upload wheels artifact
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: cibw-wheels-${{ matrix.os }}
67+
path: ./wheelhouse/*.whl
68+
69+
build_sdist:
70+
name: build_sdist
71+
runs-on: ubuntu-latest
72+
timeout-minutes: 15
73+
74+
steps:
75+
- uses: actions/checkout@v4
76+
with:
77+
submodules: recursive
78+
79+
- name: Build sdist
80+
run: pipx run build --sdist
81+
82+
- name: Upload sdist artifact
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: cibw-sdist
86+
path: dist/*.tar.gz
87+
88+
publish_testpypi:
89+
name: publish_testpypi
90+
needs: [build_wheels, build_sdist]
91+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
92+
runs-on: ubuntu-latest
93+
timeout-minutes: 15
94+
environment: testpypi
95+
permissions:
96+
id-token: write
97+
98+
steps:
99+
- name: Download all artifacts
100+
uses: actions/download-artifact@v4
101+
with:
102+
pattern: cibw-*
103+
path: dist
104+
merge-multiple: true
105+
106+
- name: Publish to TestPyPI
107+
uses: pypa/gh-action-pypi-publish@release/v1
108+
with:
109+
repository-url: https://test.pypi.org/legacy/
110+
skip-existing: true
111+
112+
publish_pypi:
113+
name: publish_pypi
114+
needs: [build_wheels, build_sdist]
115+
if: github.event_name == 'release' && github.event.action == 'published'
116+
runs-on: ubuntu-latest
117+
timeout-minutes: 15
118+
environment: pypi
119+
permissions:
120+
id-token: write
121+
122+
steps:
123+
- name: Download all artifacts
124+
uses: actions/download-artifact@v4
125+
with:
126+
pattern: cibw-*
127+
path: dist
128+
merge-multiple: true
129+
130+
- name: Publish to PyPI
131+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)