Skip to content

Commit d89c6fd

Browse files
author
Simon Morley
committed
ci: publish to PyPI via PYPI_API_TOKEN secret
Switches the publish-pypi job from OIDC/Trusted Publishing to the PYPI_API_TOKEN repository secret. The job runs only on this repository (never forks); the GitHub Release job runs only on a tag push, so manually re-publishing an existing tag does not recreate the release.
1 parent 16b8968 commit d89c6fd

1 file changed

Lines changed: 16 additions & 23 deletions

File tree

.github/workflows/release.yml

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
name: Release
22

3-
# Triggered by a version tag (vX.Y.Z). It always builds the distributions and cuts
4-
# a GitHub Release with the wheel + sdist attached. It also publishes to PyPI via
5-
# Trusted Publishing (no API tokens) once that is enabled - see below.
3+
# Triggered by a version tag (vX.Y.Z). It always builds the distributions, cuts a
4+
# GitHub Release with the wheel + sdist attached, and publishes to PyPI using the
5+
# PYPI_API_TOKEN repository secret.
66
#
7-
# Enable PyPI publishing (one-time):
8-
# 1. Register a Trusted Publisher for project `nrdax` at
9-
# https://pypi.org/manage/project/nrdax/settings/publishing/
10-
# (owner: NullRabbitLabs, repo: nrdax-python, workflow: release.yml,
11-
# environment: pypi).
12-
# 2. Turn it on for this repo: gh variable set PYPI_TRUSTED_PUBLISHING --body true
13-
# (or Settings > Secrets and variables > Actions > Variables).
14-
# Until it is enabled, tagging still produces a GitHub Release; the PyPI job is
15-
# skipped (not failed), so the release never blocks on PyPI setup.
7+
# PyPI auth: the `PYPI_API_TOKEN` secret (set with `gh secret set PYPI_API_TOKEN`,
8+
# value never in source). The publish job runs only on this repository, so forks
9+
# never attempt to publish. To publish an already-tagged version (e.g. after adding
10+
# the token later), use: Actions > Release > Run workflow > enter the tag.
1611

1712
on:
1813
push:
1914
tags: ["v*"]
2015
workflow_dispatch:
2116
inputs:
2217
tag:
23-
description: "Existing tag to build a release for (e.g. v0.1.0)"
18+
description: "Existing tag to build and publish (e.g. v0.1.0)"
2419
required: true
2520

2621
permissions:
@@ -50,6 +45,8 @@ jobs:
5045
github-release:
5146
name: github release
5247
needs: build
48+
# Only when an actual tag is pushed (not on manual re-publish of an existing tag).
49+
if: ${{ github.event_name == 'push' }}
5350
runs-on: ubuntu-latest
5451
permissions:
5552
contents: write
@@ -61,28 +58,24 @@ jobs:
6158
- name: Create GitHub Release
6259
uses: softprops/action-gh-release@v3
6360
with:
64-
tag_name: ${{ github.event.inputs.tag || github.ref_name }}
65-
name: ${{ github.event.inputs.tag || github.ref_name }}
61+
tag_name: ${{ github.ref_name }}
62+
name: ${{ github.ref_name }}
6663
generate_release_notes: true
6764
files: dist/*
6865
fail_on_unmatched_files: true
6966

7067
publish-pypi:
7168
name: publish to PyPI
7269
needs: build
73-
# Skipped until Trusted Publishing is configured and the variable is set to
74-
# "true" - so the GitHub Release never blocks on PyPI being ready.
75-
if: ${{ vars.PYPI_TRUSTED_PUBLISHING == 'true' }}
70+
# Never publish from forks.
71+
if: ${{ github.repository == 'NullRabbitLabs/nrdax-python' }}
7672
runs-on: ubuntu-latest
77-
environment:
78-
name: pypi
79-
url: https://pypi.org/project/nrdax/
80-
permissions:
81-
id-token: write # required for Trusted Publishing (OIDC)
8273
steps:
8374
- uses: actions/download-artifact@v8
8475
with:
8576
name: dist
8677
path: dist
8778
- name: Publish to PyPI
8879
uses: pypa/gh-action-pypi-publish@release/v1
80+
with:
81+
password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)