Skip to content

Commit c1af5b0

Browse files
authored
Update release.yml
1 parent 559beed commit c1af5b0

1 file changed

Lines changed: 82 additions & 58 deletions

File tree

.github/workflows/release.yml

Lines changed: 82 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,94 @@
1-
# This workflow will upload a Python Package to PyPI when a release is created
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
1+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
32

4-
# This workflow uses actions that are not certified by GitHub.
5-
# They are provided by a third-party and are governed by
6-
# separate terms of service, privacy policy, and support
7-
# documentation.
3+
on: push
84

9-
name: Upload Python Package
10-
11-
on:
12-
release:
13-
types: [published]
14-
15-
permissions:
16-
contents: read
175

186
jobs:
19-
release-build:
7+
build:
8+
name: Build distribution 📦
209
runs-on: ubuntu-latest
2110

2211
steps:
23-
- uses: actions/checkout@v4
24-
25-
- uses: actions/setup-python@v5
26-
with:
27-
python-version: "3.x"
28-
29-
- name: Build release distributions
30-
run: |
31-
# NOTE: put your own distribution build steps here.
32-
python -m pip install build
33-
python -m build
34-
35-
- name: Upload distributions
36-
uses: actions/upload-artifact@v4
37-
with:
38-
name: release-dists
39-
path: dist/
40-
41-
pypi-publish:
42-
runs-on: ubuntu-latest
12+
- uses: actions/checkout@v4
13+
with:
14+
persist-credentials: false
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.x"
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@v4
29+
with:
30+
name: python-package-distributions
31+
path: dist/
32+
publish-to-pypi:
33+
name: >-
34+
Publish Python 🐍 distribution 📦 to PyPI
35+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
4336
needs:
44-
- release-build
45-
permissions:
46-
# IMPORTANT: this permission is mandatory for trusted publishing
47-
id-token: write
48-
49-
# Dedicated environments with protections for publishing are strongly recommended.
50-
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
37+
- build
38+
runs-on: ubuntu-latest
5139
environment:
5240
name: pypi
53-
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
54-
url: https://pypi.org/p/ssri
55-
#
56-
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
57-
# ALTERNATIVE: exactly, uncomment the following line instead:
58-
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
59-
41+
url: https://pypi.org/p/ssri # Replace <package-name> with your PyPI project name
42+
permissions:
43+
id-token: write # IMPORTANT: mandatory for trusted publishing
6044
steps:
61-
- name: Retrieve release distributions
62-
uses: actions/download-artifact@v4
63-
with:
64-
name: release-dists
65-
path: dist/
45+
- name: Download all the dists
46+
uses: actions/download-artifact@v4
47+
with:
48+
name: python-package-distributions
49+
path: dist/
50+
- name: Publish distribution 📦 to PyPI
51+
uses: pypa/gh-action-pypi-publish@release/v1
52+
53+
github-release:
54+
name: >-
55+
Sign the Python 🐍 distribution 📦 with Sigstore
56+
and upload them to GitHub Release
57+
needs:
58+
- publish-to-pypi
59+
runs-on: ubuntu-latest
60+
61+
permissions:
62+
contents: write # IMPORTANT: mandatory for making GitHub Releases
63+
id-token: write # IMPORTANT: mandatory for sigstore
6664

67-
- name: Publish release distributions to PyPI
68-
uses: pypa/gh-action-pypi-publish@release/v1
69-
with:
70-
packages-dir: dist/
65+
steps:
66+
- name: Download all the dists
67+
uses: actions/download-artifact@v4
68+
with:
69+
name: python-package-distributions
70+
path: dist/
71+
- name: Sign the dists with Sigstore
72+
uses: sigstore/gh-action-sigstore-python@v3.0.0
73+
with:
74+
inputs: >-
75+
./dist/*.tar.gz
76+
./dist/*.whl
77+
- name: Create GitHub Release
78+
env:
79+
GITHUB_TOKEN: ${{ github.token }}
80+
run: >-
81+
gh release create
82+
"$GITHUB_REF_NAME"
83+
--repo "$GITHUB_REPOSITORY"
84+
--notes ""
85+
- name: Upload artifact signatures to GitHub Release
86+
env:
87+
GITHUB_TOKEN: ${{ github.token }}
88+
# Upload to GitHub Release using the `gh` CLI.
89+
# `dist/` contains the built packages, and the
90+
# sigstore-produced signatures and certificates.
91+
run: >-
92+
gh release upload
93+
"$GITHUB_REF_NAME" dist/**
94+
--repo "$GITHUB_REPOSITORY"

0 commit comments

Comments
 (0)