Skip to content

Commit faef040

Browse files
author
Lukas Puehringer
committed
build: add GH workflow to build + release on PyPI
Add workflow with two jobs to build and publish on PyPI. The release job waits for the build job and uses a custom release environment, which can be configured to require review. To share the build artifacts between the jobs and to make them available for intermediate review, they are stored using 'actions/upload-artifact' and 'actions/download-artifact'. https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts To upload the build artifacts to PyPI, the PyPA recommended 'pypa/gh-action-pypi-publish' is used. https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ **Caveat** The URL to grab the artifacts, e.g. for review, requires knowledge of action ID and artifact ID, and a login token (no special permissions). This makes it a bit cumbersome to fetch the artifacts with a script and compare them to a local build. https://docs.github.com/en/actions/managing-workflow-runs/downloading-workflow-artifacts Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
1 parent d36b701 commit faef040

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

.github/workflows/cd.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: CD
2+
concurrency: cd
3+
4+
# Trigger workflow on release tag push
5+
on:
6+
push:
7+
# TODO: Should we restrict to vX.Y.Z tags?
8+
tags: v*
9+
10+
jobs:
11+
build:
12+
name: Build
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout release tag
16+
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@0ebf233433c08fb9061af664d501c3f3ff0e9e20
20+
with:
21+
python-version: '3.x'
22+
23+
- name: Install build dependency
24+
run: python3 -m pip install --upgrade pip build
25+
26+
- name: Build binary wheel and source tarball
27+
run: python3 -m build --sdist --wheel --outdir dist/ .
28+
29+
- name: Store build artifacts for review and release
30+
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
31+
with:
32+
name: build-artifacts
33+
path: dist
34+
35+
release-on-pypi:
36+
name: Release on PyPI
37+
runs-on: ubuntu-latest
38+
needs: build
39+
environment: release
40+
steps:
41+
- name: Fetch build artifacts
42+
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741
43+
with:
44+
name: build-artifacts
45+
path: dist
46+
47+
- name: Publish binary wheel and source tarball on PyPI
48+
uses: pypa/gh-action-pypi-publish@717ba43cfbb0387f6ce311b169a825772f54d295
49+
with:
50+
user: __token__
51+
password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)