Skip to content

Commit dc8b09c

Browse files
committed
update release action
1 parent 143a4fb commit dc8b09c

File tree

1 file changed

+77
-15
lines changed

1 file changed

+77
-15
lines changed

.github/workflows/release.yml

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,100 @@
1-
name: Release
1+
name: Publish Python 🐍 distribution 📦 to PyPI
22

33
on:
4-
release:
5-
types: [created]
4+
push:
5+
# Only run this workflow when a tag with the pattern 'v*' is pushed
6+
tags:
7+
- 'v*'
68

79
jobs:
8-
release:
9-
runs-on: ubuntu-latest
10+
# Step 1: Build the Python package
11+
build:
12+
name: Build distribution 📦
13+
runs-on: ubuntu-20.04
1014
steps:
1115
- uses: actions/checkout@v4
16+
with:
17+
persist-credentials: false
1218

1319
- name: Set up Python
1420
uses: actions/setup-python@v4
1521
with:
1622
python-version: '3.7'
1723

18-
- name: Install dependencies
24+
- name: Install build dependencies
1925
run: |
2026
python -m pip install --upgrade pip
21-
pip install build twine wheel
27+
pip install build pytest
2228
pip install -e .
2329
2430
- name: Run tests
25-
run: |
26-
pip install pytest
27-
pytest tests/
31+
run: pytest tests/
2832

2933
- name: Build package
30-
run: |
31-
python -m build
34+
run: python -m build
35+
36+
- name: Store the distribution packages
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: python-package-distributions
40+
path: dist/
41+
42+
# Step 2: Publish the distribution to PyPI
43+
publish-to-pypi:
44+
name: Publish to PyPI
45+
needs: build
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- name: Download distribution packages
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: python-package-distributions
53+
path: dist/
3254

3355
- name: Publish to PyPI
56+
uses: pypa/[email protected]
57+
with:
58+
# If using a secret-based token:
59+
username: '__token__'
60+
password: ${{ secrets.PYPI_API_TOKEN }}
61+
62+
# Step 3: Sign the distribution and create a GitHub release
63+
github-release:
64+
name: Sign the distribution 📦 with Sigstore and upload to GitHub Release
65+
needs: publish-to-pypi
66+
runs-on: ubuntu-latest
67+
permissions:
68+
contents: write # Required to create GitHub Releases
69+
id-token: write # Required for sigstore
70+
71+
steps:
72+
- name: Download distribution packages
73+
uses: actions/download-artifact@v4
74+
with:
75+
name: python-package-distributions
76+
path: dist/
77+
78+
- name: Sign the dists with Sigstore
79+
uses: sigstore/[email protected]
80+
with:
81+
inputs: >-
82+
./dist/*.tar.gz
83+
./dist/*.whl
84+
85+
- name: Create GitHub Release
86+
env:
87+
GITHUB_TOKEN: ${{ github.token }}
88+
run: |
89+
# $GITHUB_REF_NAME is the tag name, e.g. 'v1.0.0'
90+
gh release create "$GITHUB_REF_NAME" \
91+
--repo "$GITHUB_REPOSITORY" \
92+
--title "Release $GITHUB_REF_NAME" \
93+
--notes "See CHANGELOG for details."
94+
95+
- name: Upload artifact signatures to GitHub Release
3496
env:
35-
TWINE_USERNAME: __token__
36-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
97+
GITHUB_TOKEN: ${{ github.token }}
3798
run: |
38-
twine upload dist/*
99+
gh release upload "$GITHUB_REF_NAME" dist/** \
100+
--repo "$GITHUB_REPOSITORY"

0 commit comments

Comments
 (0)