Skip to content

Commit ec57ef7

Browse files
Switch to django commons release action (#25)
This will support releasing to PyPI when a tag is pushed and approved by the admins team of the project.
1 parent 00071c3 commit ec57ef7

File tree

1 file changed

+113
-31
lines changed

1 file changed

+113
-31
lines changed

.github/workflows/release.yml

Lines changed: 113 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,119 @@ on:
55
tags:
66
- '*.*.*'
77

8+
env:
9+
# Change these for your project's URLs
10+
PYPI_URL: https://pypi.org/p/django-fsm-2
11+
PYPI_TEST_URL: https://test.pypi.org/p/django-fsm-2
12+
813
jobs:
9-
release:
10-
name: Release
14+
15+
build:
16+
name: Build distribution 📦
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: "3.x"
25+
- name: Install pypa/build
26+
run:
27+
python3 -m pip install build --user
28+
- name: Build a binary wheel and a source tarball
29+
run: python3 -m build
30+
- name: Store the distribution packages
31+
uses: actions/upload-artifact@v3
32+
with:
33+
name: python-package-distributions
34+
path: dist/
35+
36+
publish-to-pypi:
37+
name: >-
38+
Publish Python 🐍 distribution 📦 to PyPI
39+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
40+
needs:
41+
- build
42+
runs-on: ubuntu-latest
43+
environment:
44+
name: pypi
45+
url: ${{ env.PYPI_URL }}
46+
permissions:
47+
id-token: write # IMPORTANT: mandatory for trusted publishing
48+
steps:
49+
- name: Download all the dists
50+
uses: actions/download-artifact@v3
51+
with:
52+
name: python-package-distributions
53+
path: dist/
54+
- name: Publish distribution 📦 to PyPI
55+
uses: pypa/gh-action-pypi-publish@release/v1
56+
57+
github-release:
58+
name: >-
59+
Sign the Python 🐍 distribution 📦 with Sigstore
60+
and upload them to GitHub Release
61+
needs:
62+
- publish-to-pypi
1163
runs-on: ubuntu-latest
64+
65+
permissions:
66+
contents: write # IMPORTANT: mandatory for making GitHub Releases
67+
id-token: write # IMPORTANT: mandatory for sigstore
68+
69+
steps:
70+
- name: Download all the dists
71+
uses: actions/download-artifact@v3
72+
with:
73+
name: python-package-distributions
74+
path: dist/
75+
- name: Sign the dists with Sigstore
76+
uses: sigstore/[email protected]
77+
with:
78+
inputs: >-
79+
./dist/*.tar.gz
80+
./dist/*.whl
81+
- name: Create GitHub Release
82+
env:
83+
GITHUB_TOKEN: ${{ github.token }}
84+
run: >-
85+
gh release create
86+
'${{ github.ref_name }}'
87+
--repo '${{ github.repository }}'
88+
--notes ""
89+
- name: Upload artifact signatures to GitHub Release
90+
env:
91+
GITHUB_TOKEN: ${{ github.token }}
92+
# Upload to GitHub Release using the `gh` CLI.
93+
# `dist/` contains the built packages, and the
94+
# sigstore-produced signatures and certificates.
95+
run: >-
96+
gh release upload
97+
'${{ github.ref_name }}' dist/**
98+
--repo '${{ github.repository }}'
99+
100+
publish-to-testpypi:
101+
name: Publish Python 🐍 distribution 📦 to TestPyPI
102+
needs:
103+
- build
104+
runs-on: ubuntu-latest
105+
106+
environment:
107+
name: testpypi
108+
url: ${{ env.PYPI_TEST_URL }}
109+
110+
permissions:
111+
id-token: write # IMPORTANT: mandatory for trusted publishing
112+
12113
steps:
13-
- name: Checkout code
14-
uses: actions/checkout@v4
15-
16-
- uses: snok/install-poetry@v1
17-
with:
18-
version: 1.3.2
19-
virtualenvs-create: true
20-
virtualenvs-in-project: true
21-
22-
- name: Set up Python 3.11
23-
uses: actions/setup-python@v5
24-
with:
25-
python-version: "3.11"
26-
cache: poetry
27-
28-
- name: Build project
29-
run: poetry build
30-
31-
- name: Create Release
32-
uses: ncipollo/release-action@v1
33-
with:
34-
artifacts: "dist/*"
35-
token: ${{ secrets.GITHUB_TOKEN }}
36-
draft: false
37-
38-
- name: Publish to PyPI
39-
env:
40-
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
41-
run: poetry publish
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/
123+
skip-existing: true

0 commit comments

Comments
 (0)