Skip to content

Commit f188bb6

Browse files
authored
Merge pull request #2149 from webknjaz/maintenance/trusted-publishing
📦 Migrate release workflow to Trusted Publishing
2 parents 4992fa2 + afd3b57 commit f188bb6

1 file changed

Lines changed: 115 additions & 11 deletions

File tree

.github/workflows/release.yml

Lines changed: 115 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: Release
1+
---
2+
name: 📦 Packaging
23

34
on:
45
push:
@@ -8,36 +9,139 @@ on:
89
types:
910
- published
1011

12+
env:
13+
FORCE_COLOR: 1 # Request colored output from CLI tools supporting it
14+
MYPY_FORCE_COLOR: 1 # MyPy's color enforcement
15+
PIP_DISABLE_PIP_VERSION_CHECK: 1 # Hide "there's a newer pip" message
16+
PIP_NO_PYTHON_VERSION_WARNING: 1 # Hide "this Python is deprecated" message
17+
PIP_NO_WARN_SCRIPT_LOCATION: 1 # Hide "script dir is not in $PATH" message
18+
PRE_COMMIT_COLOR: always
19+
PROJECT_NAME: pip-tools
20+
PY_COLORS: 1 # Recognized by the `py` package, dependency of `pytest`
21+
PYTHONIOENCODING: utf-8
22+
PYTHONUTF8: 1
23+
TOX_PARALLEL_NO_SPINNER: 1 # Disable tox's parallel run spinner animation
24+
TOX_TESTENV_PASSENV: >- # Make tox-wrapped tools see color requests
25+
FORCE_COLOR
26+
MYPY_FORCE_COLOR
27+
NO_COLOR
28+
PIP_DISABLE_PIP_VERSION_CHECK
29+
PIP_NO_PYTHON_VERSION_WARNING
30+
PIP_NO_WARN_SCRIPT_LOCATION
31+
PRE_COMMIT_COLOR
32+
PY_COLORS
33+
PYTEST_THEME
34+
PYTEST_THEME_MODE
35+
PYTHONIOENCODING
36+
PYTHONLEGACYWINDOWSSTDIO
37+
PYTHONUTF8
38+
UPSTREAM_REPOSITORY_ID: >-
39+
5746963
40+
41+
run-name: >-
42+
${{
43+
github.event.action == 'published'
44+
&& format('📦 Releasing v{0}...', github.ref_name)
45+
|| format('🌱 Smoke-testing packaging for commit {0}', github.sha)
46+
}}
47+
triggered by: ${{ github.event_name }} of ${{
48+
github.ref
49+
}} ${{
50+
github.ref_type
51+
}}
52+
(workflow run ID: ${{
53+
github.run_id
54+
}}; number: ${{
55+
github.run_number
56+
}}; attempt: ${{
57+
github.run_attempt
58+
}})
59+
1160
jobs:
1261
build:
13-
if: github.repository == 'jazzband/pip-tools'
62+
name: >-
63+
📦 v${{ github.ref_name }}
64+
[mode: ${{
65+
github.event.action == 'published'
66+
&& 'release' || 'nightly'
67+
}}]
68+
1469
runs-on: ubuntu-latest
1570

71+
timeout-minutes: 2
72+
1673
steps:
17-
- uses: actions/checkout@v3
74+
- uses: actions/checkout@v4
1875
with:
1976
fetch-depth: 0
2077

2178
- name: Set up Python
22-
uses: actions/setup-python@v4
79+
uses: actions/setup-python@v5
2380
with:
24-
python-version: 3.9
81+
python-version: 3.12
2582

2683
- name: Install dependencies
2784
run: |
28-
python -m pip install -U pip
29-
python -m pip install -U twine build setuptools-scm
85+
python -Im pip install -U twine build
3086
3187
- name: Build package
3288
run: |
33-
python -m setuptools_scm
34-
python -m build
89+
python -Im build
3590
twine check --strict dist/*
3691
92+
- name: Store the distribution packages
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: python-package-distributions
96+
# NOTE: Exact expected file names are specified here
97+
# NOTE: as a safety measure — if anything weird ends
98+
# NOTE: up being in this dir or not all dists will be
99+
# NOTE: produced, this will fail the workflow.
100+
path: |
101+
dist/*.tar.gz
102+
dist/*.whl
103+
retention-days: >-
104+
${{
105+
github.event.action == 'published'
106+
&& 90 || 30
107+
}}
108+
109+
publish-pypi:
110+
name: >-
111+
📦
112+
Publish v${{ github.ref_name }} to PyPI
113+
needs:
114+
- build
115+
if: >-
116+
github.event.action == 'published'
117+
&& env.UPSTREAM_REPOSITORY_ID == github.repository_id
118+
119+
runs-on: ubuntu-latest
120+
121+
timeout-minutes: 2 # docker+network are slow sometimes
122+
123+
environment:
124+
name: pypi
125+
url: >-
126+
https://pypi.org/project/${{ env.PROJECT_NAME }}/${{ github.ref_name }}
127+
128+
permissions:
129+
id-token: write # PyPI Trusted Publishing (OIDC)
130+
131+
steps:
132+
- name: Download all the dists
133+
uses: actions/download-artifact@v4
134+
with:
135+
name: python-package-distributions
136+
path: dist/
137+
- name: >-
138+
📦
139+
Publish v${{ github.ref_name }} to PyPI
140+
🔏
141+
uses: pypa/gh-action-pypi-publish@release/v1
37142
- name: Upload packages to Jazzband
38-
if: github.event.action == 'published'
39143
uses: pypa/gh-action-pypi-publish@release/v1
40144
with:
41145
user: jazzband
42146
password: ${{ secrets.JAZZBAND_RELEASE_KEY }}
43-
repository_url: https://jazzband.co/projects/pip-tools/upload
147+
repository_url: https://jazzband.co/projects/${{ env.PROJECT_NAME }}/upload

0 commit comments

Comments
 (0)