Skip to content

Commit 917fba1

Browse files
committed
Migrate PyPI deployment to Trusted Publishing
1 parent cb64172 commit 917fba1

File tree

1 file changed

+54
-24
lines changed

1 file changed

+54
-24
lines changed

.github/workflows/deployment.yml

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,68 @@
11
name: Deployment
2+
23
on: [push, pull_request]
4+
35
jobs:
4-
has:
5-
name: Check Secrets
6-
runs-on: ubuntu-latest
7-
steps:
8-
- id: secrets
9-
env:
10-
test_pypi_token: ${{ secrets.TEST_PYPI_TOKEN }}
11-
pypi_token: ${{ secrets.PYPI_TOKEN }}
12-
if: ${{ env.test_pypi_token != '' && env.pypi_token != '' }}
13-
run:
14-
echo "::set-output name=secrets::1"
15-
outputs:
16-
secrets: ${{ steps.secrets.outputs.secrets }}
17-
build-and-publish:
18-
needs: has
6+
build:
7+
name: Build distribution
198
runs-on: ubuntu-latest
209
steps:
2110
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
2214
- uses: actions/setup-python@v5
15+
2316
- name: Install dependencies
24-
run: pip install build twine
17+
run: pip install build
18+
2519
- name: Build a binary wheel and a source tarball
2620
run: python3 -m build
27-
- name: Publish distribution 📦 to Test PyPI
28-
if: ${{ needs.has.outputs.secrets }}
21+
22+
- name: Store the distribution packages
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: python-package-distributions
26+
path: dist/
27+
28+
publish-to-testpypi:
29+
name: Publish to TestPyPI
30+
if: "!startsWith(github.ref, 'refs/tags')"
31+
needs: build
32+
runs-on: ubuntu-latest
33+
environment:
34+
name: testpypi
35+
url: https://test.pypi.org/p/sphinxcontrib-django
36+
permissions:
37+
id-token: write
38+
steps:
39+
- name: Download all the dists
40+
uses: actions/download-artifact@v4
41+
with:
42+
name: python-package-distributions
43+
path: dist/
44+
45+
- name: Publish distribution 📦 to TestPyPI
2946
uses: pypa/gh-action-pypi-publish@release/v1
3047
with:
31-
password: ${{ secrets.TEST_PYPI_TOKEN }}
32-
repository_url: https://test.pypi.org/legacy/
33-
skip_existing: true
48+
repository-url: https://test.pypi.org/legacy/
49+
50+
publish-to-pypi:
51+
name: Publish to PyPI
52+
if: startsWith(github.ref, 'refs/tags')
53+
needs: build
54+
runs-on: ubuntu-latest
55+
environment:
56+
name: pypi
57+
url: https://pypi.org/p/sphinxcontrib-django
58+
permissions:
59+
id-token: write
60+
steps:
61+
- name: Download all the dists
62+
uses: actions/download-artifact@v4
63+
with:
64+
name: python-package-distributions
65+
path: dist/
66+
3467
- name: Publish distribution 📦 to PyPI
35-
if: startsWith(github.ref, 'refs/tags')
3668
uses: pypa/gh-action-pypi-publish@release/v1
37-
with:
38-
password: ${{ secrets.PYPI_TOKEN }}

0 commit comments

Comments
 (0)