Skip to content

Commit c17bf1c

Browse files
committed
Add optional pypi release job inside the reusable tox workflow
1 parent 24da778 commit c17bf1c

File tree

2 files changed

+47
-41
lines changed

2 files changed

+47
-41
lines changed

.github/workflows/release.yml

-40
This file was deleted.

.github/workflows/tox.yml

+47-1
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,16 @@ on:
5454
description: Command to run after test commands.
5555
required: false
5656
type: string
57+
publish_pypi:
58+
default: false
59+
description: Whether to publish to PyPI
60+
required: false
61+
type: boolean
5762
# keep permissions at top level because this is a composite workflow
5863
permissions:
5964
checks: read
6065
contents: read
61-
id-token: write
66+
id-token: write # release
6267
packages: write # some tox environments might produce containers
6368
pull-requests: write # allow codenotify to comment on pull-request
6469
env:
@@ -247,3 +252,44 @@ jobs:
247252
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
248253
# https://github.com/sourcegraph/codenotify/issues/19
249254
continue-on-error: true
255+
256+
pypi:
257+
name: release ${{ github.event.ref }}
258+
# if: github.ref_type == 'tag' || inputs.publish_pypi == 'true'
259+
needs: check
260+
environment: release # keep it here to allow users to prompt for release
261+
runs-on: ubuntu-24.04
262+
steps:
263+
- name: Switch to using Python 3.12 by default
264+
uses: actions/setup-python@v5
265+
with:
266+
python-version: "3.12"
267+
268+
- name: Install tox
269+
run: python3 -m pip install --user "tox>=4.0.0"
270+
271+
- name: Check out src from Git
272+
uses: actions/checkout@v4
273+
with:
274+
fetch-depth: 0 # needed by setuptools-scm
275+
276+
- name: Build dists
277+
run: python3 -m tox -e pkg
278+
279+
- name: Fail if secrets are not available
280+
env:
281+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
282+
run: |
283+
if [ -z "${PYPI_API_TOKEN}" ]; then
284+
echo "PYPI_API_TOKEN is not set, please add it to your repository environment named 'release'."
285+
exit 1
286+
fi
287+
288+
- name: Publish to pypi.org
289+
uses: pypa/gh-action-pypi-publish@release/v1
290+
if: inputs.publish_pypi
291+
with:
292+
# trusted publishing is not possible with shared workflows due to
293+
# https://github.com/pypi/warehouse/issues/11096 so we need to use
294+
# secrets instead.
295+
password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)