Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Publish

# Build the package from a published GitHub release and upload it to PyPI with
# Trusted Publishing, which also uploads provenance attestations for the
# files. On a pull request that changes this file, or when run by hand, only
# build the package, without uploading anything.
# files. On a pull request that changes this file, only build the package. A
# manual run can publish an existing release tag if the release event is missed.
#
# One-time setup:
# - On PyPI, in the wfdb project's settings, under Publishing, add a GitHub
Expand All @@ -19,6 +19,11 @@ on:
paths:
- .github/workflows/publish.yml
workflow_dispatch:
inputs:
release_tag:
description: Existing release tag to publish (for example, v5.15.0)
required: true
type: string

permissions:
contents: read
Expand All @@ -29,16 +34,36 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Check that the release is published
if: github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ inputs.release_tag }}
run: |
draft=$(gh release view "$RELEASE_TAG" --json isDraft --jq .isDraft)
if [ "$draft" != false ]; then
echo "::error::The release $RELEASE_TAG is still a draft"
exit 1
fi
- uses: actions/checkout@v7
if: github.event_name == 'workflow_dispatch'
with:
persist-credentials: false
ref: refs/tags/${{ inputs.release_tag }}
- uses: actions/checkout@v7
if: github.event_name != 'workflow_dispatch'
with:
persist-credentials: false
- uses: astral-sh/setup-uv@v10.4.0
- name: Check that the release tag matches the version
if: github.event_name == 'release'
if: github.event_name != 'pull_request'
env:
RELEASE_TAG: ${{ inputs.release_tag || github.ref_name }}
run: |
version=$(python3 -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')
if [ "$GITHUB_REF_NAME" != "v$version" ]; then
echo "::error::The release tag $GITHUB_REF_NAME does not match version $version in pyproject.toml"
if [ "$RELEASE_TAG" != "v$version" ]; then
echo "::error::The release tag $RELEASE_TAG does not match version $version in pyproject.toml"
exit 1
fi
- name: Build
Expand All @@ -51,7 +76,7 @@ jobs:

publish:
name: Upload to PyPI
if: github.event_name == 'release'
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
Loading