Skip to content

Commit c81903c

Browse files
authored
use trusted publishers to upload releases (#146)
* add the `zizmor` hook * rewrite the publish workflow to use trusted publishers * fix the pypi project path * follow recommendations by `zizmor` * follow recommendations in the nightly tests
1 parent 7dc5b71 commit c81903c

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
pull_request:
77
branches: [main]
88

9+
permissions: {}
10+
911
jobs:
1012
linux:
1113
name: "sphinx v${{matrix.sphinx-version}} py${{matrix.python-version}}"
@@ -33,6 +35,7 @@ jobs:
3335
uses: actions/checkout@v4
3436
with:
3537
fetch-depth: 0
38+
persist-credentials: false
3639

3740
- name: setup python
3841
uses: actions/setup-python@v5

.github/workflows/nightly.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
schedule:
99
- cron: "0 0 * * *"
1010

11+
permissions: {}
12+
1113
jobs:
1214
detect-ci-trigger:
1315
name: detect upstream-dev ci trigger
@@ -21,6 +23,7 @@ jobs:
2123
- uses: actions/checkout@v4
2224
with:
2325
fetch-depth: 2
26+
persist-credentials: false
2427
- uses: xarray-contrib/[email protected]
2528
id: detect-trigger
2629
with:
@@ -52,6 +55,7 @@ jobs:
5255
with:
5356
# need to fetch all tags to get a correct version
5457
fetch-depth: 0 # fetch all branches and tags
58+
persist-credentials: false
5559

5660
- name: setup python
5761
uses: actions/setup-python@v5
@@ -96,9 +100,15 @@ jobs:
96100
&& github.event_name == 'schedule'
97101
&& github.repository == 'xarray-contrib/sphinx-autosummary-accessors'
98102
&& needs.upstream-dev.outputs.artifacts_availability == 'true'
103+
104+
permissions:
105+
issues: write
106+
99107
steps:
100108
- name: checkout the repository
101109
uses: actions/checkout@v4
110+
with:
111+
persist-credentials: false
102112
- name: setup python
103113
uses: actions/setup-python@v5
104114
with:

.github/workflows/publish.yaml

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
name: Upload package to PyPI
1+
name: Upload Python Package on PyPI
22

33
on:
44
release:
5-
types: [created]
5+
types: [published]
66

77
jobs:
8-
publish:
9-
name: Publish to PyPI
8+
deploy:
109
runs-on: ubuntu-latest
10+
environment:
11+
name: pypi
12+
url: https://pypi.org/p/sphinx-autosummary-accessors
13+
permissions:
14+
id-token: write
1115
steps:
12-
- uses: actions/checkout@v4
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
persist-credentials: false
1320
- name: Set up Python
1421
uses: actions/setup-python@v5
1522
with:
1623
python-version: "3.x"
17-
- name: Install dependencies
18-
run: |
19-
python -m pip install --upgrade pip build twine
20-
- name: Build
21-
run: |
22-
python -m build --sdist --wheel --outdir dist/ .
23-
- name: Check the built archives
24-
run: |
25-
twine check dist/*
26-
- name: Publish to PyPI
24+
- name: Install publish dependencies
25+
run: python -m pip install build
26+
- name: Build package
27+
run: python -m build . -o dist
28+
- name: Publish package to PyPI
2729
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc
2830
with:
29-
user: __token__
30-
password: ${{ secrets.pypi_token }}
31-
repository_url: https://upload.pypi.org/legacy/
32-
verify_metadata: true
31+
packages-dir: dist

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ repos:
3131
rev: 25.1.0
3232
hooks:
3333
- id: black
34+
- repo: https://github.com/woodruffw/zizmor-pre-commit
35+
rev: v1.4.1
36+
hooks:
37+
- id: zizmor

0 commit comments

Comments
 (0)