Skip to content

Commit abd1dca

Browse files
authored
#123: Release to PyPI with digital attestations (#125)
* #123: Release to PyPI with digital attestations PEP 740 - Index support for digital attestations https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ * testing publish to testpypi * testing publish to testpypi * fix syntax error * fetch all commits and tags for setuptools_scm versioning. * setuptools_scm should omit local version that doesn't support PyPI * revert 7d45792, 63b5d1d * "github release" job uploads for existing tag. * update CHANGES * CI runs on master only * revert name to "Test". this name is used for badge on PyPI.
1 parent 052367f commit abd1dca

File tree

3 files changed

+59
-31
lines changed

3 files changed

+59
-31
lines changed

.github/workflows/ci.yml

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Test
22
on:
33
push:
4+
branches:
5+
- master
46
paths-ignore:
57
- 'doc/**'
68
pull_request:
@@ -31,7 +33,7 @@ jobs:
3133
- name: Checkout code
3234
uses: actions/checkout@v4
3335
with:
34-
fetch-depth: 1
36+
persist-credentials: false
3537

3638
- name: Set up Python ${{ matrix.python-version }}
3739
uses: astral-sh/setup-uv@v6
@@ -55,7 +57,7 @@ jobs:
5557

5658
build:
5759
name: build distribution
58-
if: github.repository_owner == 'sphinx-doc' && github.ref == 'refs/heads/master'
60+
if: ${{ github.repository_owner == 'sphinx-doc' && github.ref == 'refs/heads/master' }}
5961
needs:
6062
- tests
6163
runs-on: ubuntu-latest
@@ -64,7 +66,8 @@ jobs:
6466
- name: Checkout code
6567
uses: actions/checkout@v4
6668
with:
67-
fetch-depth: 1
69+
persist-credentials: false
70+
fetch-depth: 0
6871

6972
- name: Set up Python
7073
uses: astral-sh/setup-uv@v6
@@ -78,9 +81,32 @@ jobs:
7881
name: distributions
7982
path: dist/
8083

81-
pypi-publish:
84+
publish-to-testpypi:
85+
name: Upload release to TestPyPI
86+
if: ${{ github.repository_owner == 'sphinx-doc' && github.ref == 'refs/heads/master' }} # only publish to TestPyPI on push to master
87+
needs:
88+
- build
89+
runs-on: ubuntu-latest
90+
environment:
91+
name: testpypi
92+
url: https://test.pypi.org/p/sphinx-intl
93+
permissions:
94+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
95+
steps:
96+
- name: Download all the dists
97+
uses: actions/download-artifact@v4
98+
with:
99+
name: distributions
100+
path: dist/
101+
- name: Publish package distributions to TestPyPI
102+
uses: pypa/gh-action-pypi-publish@release/v1
103+
with:
104+
verbose: true
105+
repository-url: https://test.pypi.org/legacy/
106+
107+
publish-to-pypi:
82108
name: Upload release to PyPI
83-
if: github.repository_owner == 'sphinx-doc' && startsWith(github.ref, 'refs/tags/')
109+
if: ${{ github.repository_owner == 'sphinx-doc' && startsWith(github.ref, 'refs/tags/') }}
84110
needs:
85111
- build
86112
runs-on: ubuntu-latest
@@ -102,36 +128,35 @@ jobs:
102128
with:
103129
verbose: true
104130

105-
# for test
106-
password: ${{ secrets.TESTPYPI_TOKEN }}
107-
repository_url: https://test.pypi.org/legacy/
108-
109-
# for production
110-
# password: ${{ secrets.PYPI_TOKEN }}
111-
112131
github-release:
113-
name: GitHub release
114-
if: github.repository_owner == 'sphinx-doc'
132+
name: Sign the Python 🐍 distribution 📦 with Sigstore and upload them to GitHub Release
133+
if: ${{ github.repository_owner == 'sphinx-doc' && startsWith(github.ref, 'refs/tags/') }}
115134
runs-on: ubuntu-latest
116135
needs:
117-
- pypi-publish
136+
- publish-to-pypi
118137
environment: release
119138
permissions:
120-
contents: write # for softprops/action-gh-release to create GitHub release
121-
139+
contents: write # IMPORTANT: mandatory for making GitHub Releases
140+
id-token: write # IMPORTANT: mandatory for sigstore
122141
steps:
123-
- uses: actions/checkout@v4
124-
with:
125-
persist-credentials: false
126-
- name: Get release version
127-
id: get_version
128-
uses: actions/github-script@v7
142+
- name: Download all the dists
143+
uses: actions/download-artifact@v4
129144
with:
130-
script: core.setOutput('version', context.ref.replace("refs/tags/", ""))
131-
132-
- name: Create GitHub release
133-
uses: softprops/action-gh-release@v2
134-
if: startsWith(github.ref, 'refs/tags/')
145+
name: distributions
146+
path: dist/
147+
- name: Sign the dists with Sigstore
148+
uses: sigstore/[email protected]
135149
with:
136-
name: "sphinx-intl ${{ steps.get_version.outputs.version }}"
137-
body: "Changelog: https://sphinx-intl.readthedocs.io/en/master/changes.html"
150+
inputs: >-
151+
./dist/*.tar.gz
152+
./dist/*.whl
153+
- name: Upload artifact signatures to GitHub Release
154+
env:
155+
GITHUB_TOKEN: ${{ github.token }}
156+
# Upload to GitHub Release using the `gh` CLI.
157+
# `dist/` contains the built packages, and the
158+
# sigstore-produced signatures and certificates.
159+
run: >-
160+
gh release upload
161+
"$GITHUB_REF_NAME" dist/**
162+
--repo "$GITHUB_REPOSITORY"

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Environments
99
------------
1010

1111
* add python-3.14 support by @rffontenelle in https://github.com/sphinx-doc/sphinx-intl/pull/115
12+
* Release to PyPI with digital attestations (PEP-740) by @shimizukawa in https://github.com/sphinx-doc/sphinx-intl/pull/125
1213

1314
Incompatibility
1415
---------------

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ build-backend = "setuptools.build_meta"
6262
include-package-data = true
6363

6464
[tool.setuptools_scm]
65-
# this empty section means: use_scm_version=True
65+
# https://setuptools-scm.readthedocs.io/en/latest/extending/#available-implementations_1
66+
# because pypi does not support local version like .devN+<local_version>
67+
local_scheme = "no-local-version"
6668

6769
[tool.mypy]
6870
ignore_missing_imports = true

0 commit comments

Comments
 (0)