Skip to content

Commit f5581de

Browse files
authored
📦 Implement tokenless publishing to PyPI (ansible#598)
1 parent a1298c0 commit f5581de

File tree

1 file changed

+77
-9
lines changed

1 file changed

+77
-9
lines changed

.github/workflows/release.yml

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ env:
77
on:
88
workflow_dispatch:
99

10+
env:
11+
PROJECT_NAME: django-ansible-base
12+
1013
jobs:
11-
stage:
14+
build:
1215
runs-on: ubuntu-latest
13-
timeout-minutes: 90
14-
permissions:
15-
packages: write
16-
contents: write
16+
timeout-minutes: 2
1717
steps:
1818
- name: Checkout dab
1919
uses: actions/checkout@v4
@@ -24,12 +24,80 @@ jobs:
2424
run: echo py_version=`make PYTHON_VERSION` >> $GITHUB_ENV
2525

2626
- name: Install python ${{ env.py_version }}
27-
uses: actions/setup-python@v4
27+
uses: actions/setup-python@v5
2828
with:
2929
python-version: ${{ env.py_version }}
3030

31-
- name: Install python deeps
31+
- name: Install python deps
3232
run: pip install -r requirements/requirements_dev.txt
3333

34-
- name: Create release
35-
run: ansible-playbook tools/ansible/release.yml -i localhost -e github_token=${{ secrets.GITHUB_TOKEN }}
34+
- name: Build the dists
35+
run: >-
36+
ansible-playbook
37+
tools/ansible/release.yml
38+
-i localhost
39+
-e github_token=${{ secrets.GITHUB_TOKEN }}
40+
-t build
41+
42+
- name: Store the distribution packages
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: python-package-distributions
46+
path: |
47+
dist/*.tar.gz
48+
dist/*.whl
49+
retention-days: 90
50+
51+
publish-pypi:
52+
name: Publish to PyPI
53+
needs:
54+
- build
55+
56+
runs-on: ubuntu-latest
57+
58+
timeout-minutes: 1
59+
60+
environment:
61+
name: pypi
62+
url: https://pypi.org/project/${{ env.PROJECT_NAME }}
63+
64+
permissions:
65+
contents: read # This job doesn't need to `git push` anything
66+
id-token: write # PyPI Trusted Publishing (OIDC)
67+
68+
steps:
69+
- name: Download all the dists
70+
uses: actions/download-artifact@v4
71+
with:
72+
name: python-package-distributions
73+
path: dist/
74+
- name: Publish dists to PyPI
75+
uses: pypa/gh-action-pypi-publish@release/v1
76+
77+
post-release-repo-update:
78+
name: Make a GitHub Release
79+
needs:
80+
- publish-pypi
81+
82+
runs-on: ubuntu-latest
83+
84+
timeout-minutes: 2
85+
86+
permissions:
87+
packages: write
88+
contents: write
89+
90+
steps:
91+
- name: Download all the dists
92+
uses: actions/download-artifact@v4
93+
with:
94+
name: python-package-distributions
95+
path: dist/
96+
97+
- name: Create a GitHub Release uploading the dists
98+
run: >-
99+
ansible-playbook
100+
tools/ansible/release.yml
101+
-i localhost
102+
-e github_token=${{ secrets.GITHUB_TOKEN }}
103+
-t github

0 commit comments

Comments
 (0)