Skip to content

Commit 64801b0

Browse files
add build workflow as a Trusted Publisher so we don't have to use a token anymore
1 parent 7c93c72 commit 64801b0

1 file changed

Lines changed: 41 additions & 14 deletions

File tree

.github/workflows/build.yml

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,52 @@
11
name: build
22

33
on:
4+
pull_request:
45
release:
5-
types:
6-
- published
6+
types: [released]
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
11+
cancel-in-progress: true
712

813
jobs:
9-
build_and_publish:
10-
name: build and publish package
14+
build:
1115
runs-on: ubuntu-latest
1216
steps:
13-
- uses: actions/checkout@main
14-
- uses: actions/setup-python@main
17+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
18+
with:
19+
fetch-tags: true
20+
persist-credentials: false
21+
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
22+
with:
23+
python-version: "3"
24+
- run: pip install build
25+
- run: python -m build --sdist --wheel
26+
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
1527
with:
16-
python-version: "3.x"
17-
- uses: actions/cache@main
28+
name: dist
29+
path: ./dist/
30+
publish:
31+
if: (github.event_name == 'release') && (github.event.action == 'released')
32+
needs: [build]
33+
runs-on: ubuntu-latest
34+
permissions:
35+
id-token: write
36+
attestations: write
37+
# Requires environment protection rules in GitHub Settings:
38+
# Settings > Environments > release > Add required reviewers
39+
environment:
40+
name: release
41+
url: https://pypi.org/p/searvey
42+
steps:
43+
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
1844
with:
19-
path: ${{ env.pythonLocation }}
20-
key: build-${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'setup.*') }}
21-
- run: pip wheel . --no-deps -w dist
22-
- uses: pypa/gh-action-pypi-publish@release/v1
45+
pattern: dist*
46+
path: dist/
47+
merge-multiple: true
48+
- uses: actions/attest-build-provenance@96278af6caaf10aea03fd8d33a09a777ca52d62f # v3.2.0
2349
with:
24-
user: __token__
25-
password: ${{ secrets.PYPI_TOKEN }}
50+
subject-path: "dist/*"
51+
# To upload to PyPI without a token, add this workflow file as a Trusted Publisher in the project settings on the PyPI website
52+
- uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0

0 commit comments

Comments
 (0)