Files
remove-ai-watermarks/.github/workflows/publish.yml
T

70 lines
2.7 KiB
YAML

name: Publish to PyPI
on:
release:
types: [published]
permissions:
id-token: write
contents: read
jobs:
publish:
# Model-only prereleases are not Python package releases.
if: ${{ startsWith(github.event.release.tag_name, 'v') && !github.event.release.prerelease }}
runs-on: ubuntu-latest
environment: pypi
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
- name: Verify release tag matches package version
run: |
tag="${{ github.event.release.tag_name }}"
version="$(grep -m1 '^version = ' pyproject.toml | sed -E 's/^version = "([^"]+)"/\1/')"
if [ "${tag#v}" != "$version" ]; then
echo "Release tag '$tag' does not match pyproject.toml version '$version'" >&2
exit 1
fi
echo "Release tag '$tag' matches package version '$version'"
- name: Build package
run: uv build
# Publish with `uv publish` (its own uploader, not the twine bundled in the
# old pypa action). Trusted publishing is automatic in GitHub Actions: the
# `id-token: write` permission + the `pypi` environment supply the OIDC token,
# and PyPI's trusted-publisher entry matches on repo + workflow filename +
# environment name (all unchanged from the pypa-action setup), so no API token
# is needed. uv's uploader also accepts Metadata-Version 2.5 -- the permanent
# fix that lets the hatchling pin be relaxed (see pyproject [build-system]).
- name: Publish to PyPI
run: uv publish
- name: Record published release
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_NAME: ${{ github.event.release.name || github.event.release.tag_name }}
run: |
python3 - <<'PYTHON'
import json, os
from pathlib import Path
tag = os.environ["RELEASE_TAG"]
assert tag.startswith("v"), f"Unexpected release tag: {tag}"
Path("release-identity.json").write_text(json.dumps({
"version": tag[1:],
"tag": tag,
"release_name": os.environ["RELEASE_NAME"] or tag,
"run_id": os.environ["GITHUB_RUN_ID"],
"run_attempt": os.environ["GITHUB_RUN_ATTEMPT"],
}), encoding="utf-8")
PYTHON
- name: Upload published release identity
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: published-release-${{ github.run_attempt }}
path: release-identity.json
if-no-files-found: error