Skip to content

Commit 25650cd

Browse files
authored
Use release-environment-based PyPI Publishing (#41)
1 parent 1f105db commit 25650cd

File tree

1 file changed

+53
-46
lines changed

1 file changed

+53
-46
lines changed
Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,62 @@
11
# This GitHub workflow is only needed for python package releases which are supposed to be published on pypi.
2-
# This workflow will upload a Python Package using Twine when a release is created
2+
# It requires the Github "environments" feature (see instructions below) it might not be available for private free accounts (but works for public or organization repos).
3+
# After creating the "release" environment in the Github repo settings, you need to enter your Github organization/user name + repo name + "python-publish.yml" workflow file name in the PyPI UI to make this work.
4+
5+
# This workflow uploads a Python Package using Twine when a release is created.
36
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
47

58
name: Upload Python Package
69

710
on:
8-
release:
9-
types: [ created, edited ]
11+
release:
12+
types: [created, edited]
1013

1114
jobs:
12-
tests:
13-
if: startsWith(github.ref, 'refs/tags/v')
14-
runs-on: ${{ matrix.os }}
15-
strategy:
16-
matrix:
17-
python-version: [ "3.12" ]
18-
os: [ ubuntu-latest ]
19-
steps:
20-
- uses: actions/checkout@v4
21-
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v5
23-
with:
24-
python-version: ${{ matrix.python-version }}
25-
- name: Install tox
26-
run: |
27-
python -m pip install --upgrade pip
28-
pip install tox
29-
- name: Run tox
30-
run: |
31-
tox
15+
tests:
16+
if: startsWith(github.ref, 'refs/tags/v')
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
python-version: ["3.12"]
21+
os: [ubuntu-latest]
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
- name: Install tox
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install tox
32+
- name: Run tests
33+
run: |
34+
tox -e tests
3235
33-
build-n-publish:
34-
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
35-
runs-on: ubuntu-latest
36-
needs: tests
37-
steps:
38-
- uses: actions/checkout@v4
39-
- name: Set up Python
40-
uses: actions/setup-python@v5
41-
with:
42-
python-version: ${{ matrix.python-version }}
43-
- name: Install dependencies
44-
run: |
45-
python -m pip install --upgrade pip
46-
pip install -r dev_requirements/requirements-packaging.txt
47-
- name: Build a binary wheel and a source tarball
48-
run: |
49-
python -m build
50-
- name: Publish distribution 📦 to PyPI
51-
if: startsWith(github.ref, 'refs/tags/v')
52-
uses: pypa/gh-action-pypi-publish@release/v1
53-
with:
54-
user: __token__
55-
password: ${{ secrets.PYPI_API_TOKEN }}
36+
build-n-publish:
37+
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
38+
runs-on: ubuntu-latest
39+
# Specifying a GitHub environment, # Specifying a GitHub environment, which is strongly recommended by PyPI: https://docs.pypi.org/trusted-publishers/adding-a-publisher/
40+
# you have to create an environment in your repository settings and add the environment name here
41+
environment: release
42+
permissions:
43+
# IMPORTANT: this permission is mandatory for trusted publishing
44+
id-token: write
45+
needs: tests
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: Set up Python
49+
uses: actions/setup-python@v5
50+
with:
51+
python-version: ${{ matrix.python-version }}
52+
- name: Install dependencies
53+
run: |
54+
python -m pip install --upgrade pip
55+
pip install -r dev_requirements/requirements-packaging.txt
56+
- name: Build wheel and source distributions
57+
run: |
58+
python -m build
59+
- name: Publish distribution 📦 to PyPI
60+
if: startsWith(github.ref, 'refs/tags/v')
61+
uses: pypa/gh-action-pypi-publish@release/v1
62+

0 commit comments

Comments
 (0)