Skip to content

Commit 2cec24c

Browse files
committed
Update publish workflow to use Trusted Publishing
1 parent 3a54c75 commit 2cec24c

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

.github/workflows/publish.yml

+37-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,50 @@
1-
# This workflows will upload a Python Package using Twine when a release is created
2-
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3-
4-
name: Upload Python Package
5-
1+
name: Publish to PyPI
62
on:
73
release:
8-
types: [created]
4+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release
5+
types: [released]
6+
workflow_dispatch:
97

108
jobs:
11-
deploy:
9+
test:
10+
uses: ./.github/workflows/ci.yml
11+
12+
build:
13+
needs: ['test']
1214
runs-on: ubuntu-latest
1315

1416
steps:
15-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v4
1618
- name: Set up Python
17-
uses: actions/setup-python@v2
19+
uses: actions/setup-python@v4
1820
with:
1921
python-version: "3.x"
2022
- name: Install dependencies
2123
run: |
2224
python -m pip install --upgrade pip
23-
pip install setuptools wheel twine
24-
- name: Build and publish
25-
env:
26-
TWINE_USERNAME: __token__
27-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
28-
run: |
29-
python setup.py sdist bdist_wheel
30-
twine upload dist/*
25+
pip install build
26+
- name: Build package distributions
27+
run: python -m build
28+
29+
- uses: actions/upload-artifact@v3
30+
with:
31+
path: ./dist
32+
33+
# https://docs.pypi.org/trusted-publishers/using-a-publisher/
34+
pypi-publish:
35+
needs: ['build']
36+
environment: 'publish'
37+
38+
name: Upload release to PyPI
39+
runs-on: ubuntu-latest
40+
permissions:
41+
# Mandatory for trusted publishing
42+
id-token: write
43+
steps:
44+
- uses: actions/download-artifact@v3
45+
46+
- name: Publish package distributions to PyPI
47+
uses: pypa/gh-action-pypi-publish@release/v1
48+
with:
49+
packages-dir: artifact/
50+
print-hash: true

0 commit comments

Comments
 (0)