Skip to content

Commit 2417963

Browse files
committed
build: add workflow to publish to PyPI
1 parent 6bc644f commit 2417963

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

.github/workflows/publish.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Build and publish
2+
# Adapted from:
3+
# https://packaging.python.org/en/latest/guides/publishing-package-
4+
# distribution-releases-using-github-actions-ci-cd-workflows/
5+
6+
on: push # The actual PyPI release is triggered on tag pushes
7+
8+
jobs:
9+
build:
10+
name: Build 📦
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.9"
19+
- name: Install pypa/build
20+
run: >-
21+
python3 -m
22+
pip install
23+
build
24+
--user
25+
- name: Build a binary wheel and a source tarball
26+
run: python3 -m build
27+
- name: Store the distribution packages
28+
uses: actions/upload-artifact@v3
29+
with:
30+
name: python-package-distributions
31+
path: dist/
32+
33+
# Will be triggered on every tagged push to main
34+
publish-to-pypi:
35+
name: >-
36+
Publish to PyPI 🐍
37+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
38+
needs:
39+
- build
40+
runs-on: ubuntu-latest
41+
environment:
42+
name: pypi
43+
url: https://pypi.org/p/sbi
44+
permissions:
45+
id-token: write # IMPORTANT: mandatory for trusted publishing
46+
47+
steps:
48+
- name: Download all the dists
49+
uses: actions/download-artifact@v3
50+
with:
51+
name: python-package-distributions
52+
path: dist/
53+
- name: Publish distribution 📦 to PyPI
54+
uses: pypa/gh-action-pypi-publish@release/v1
55+
56+
github-release:
57+
name: >-
58+
Sign with Sigstore
59+
and upload them to GitHub Release
60+
needs:
61+
- publish-to-pypi
62+
runs-on: ubuntu-latest
63+
64+
permissions:
65+
contents: write # IMPORTANT: mandatory for making GitHub Releases
66+
id-token: write # IMPORTANT: mandatory for sigstore
67+
68+
steps:
69+
- name: Download all the dists
70+
uses: actions/download-artifact@v3
71+
with:
72+
name: python-package-distributions
73+
path: dist/
74+
- name: Sign the dists with Sigstore
75+
uses: sigstore/gh-action-sigstore-python@v2.1.1
76+
with:
77+
inputs: >-
78+
./dist/*.tar.gz
79+
./dist/*.whl
80+
- name: Create GitHub Release
81+
env:
82+
GITHUB_TOKEN: ${{ github.token }}
83+
run: >-
84+
gh release create
85+
'${{ github.ref_name }}'
86+
--repo '${{ github.repository }}'
87+
--notes ""
88+
- name: Upload artifact signatures to GitHub Release
89+
env:
90+
GITHUB_TOKEN: ${{ github.token }}
91+
# Upload to GitHub Release using the `gh` CLI.
92+
# `dist/` contains the built packages, and the
93+
# sigstore-produced signatures and certificates.
94+
run: >-
95+
gh release upload
96+
'${{ github.ref_name }}' dist/**
97+
--repo '${{ github.repository }}'
98+
99+
# Will be triggered on every push to main
100+
publish-to-testpypi:
101+
name: Test release with TestPyPI 🐍
102+
needs:
103+
- build
104+
runs-on: ubuntu-latest
105+
106+
environment:
107+
name: testpypi
108+
url: https://test.pypi.org/p/sbi
109+
110+
permissions:
111+
id-token: write # IMPORTANT: mandatory for trusted publishing
112+
113+
steps:
114+
- name: Download all the dists
115+
uses: actions/download-artifact@v3
116+
with:
117+
name: python-package-distributions
118+
path: dist/
119+
- name: Publish distribution 📦 to TestPyPI
120+
uses: pypa/gh-action-pypi-publish@release/v1
121+
with:
122+
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)