Skip to content

Commit 576e412

Browse files
committed
ci: publish on version bump
Tag pushes and workflow dispatch aren't available from every environment, so the publish workflow now also triggers on pushes to main that touch pyproject.toml (or itself): it publishes the declared version when PyPI doesn't already have it, then creates the matching tag and GitHub release. Release-event and manual-dispatch paths keep working, and the PyPI-existence guard makes every path idempotent. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V9yMCN3Y6hb1qcgGWEHN7p
1 parent b0a2fcb commit 576e412

1 file changed

Lines changed: 34 additions & 15 deletions

File tree

.github/workflows/publish.yml

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ name: Publish to PyPI
33
on:
44
release:
55
types: [published]
6-
# Manual fallback: dispatch on the release commit (usually main's head) to
7-
# publish it to PyPI and create the tag + GitHub release in one run.
6+
# Publish-on-version-bump: a push to main that changes pyproject.toml (or
7+
# this workflow) publishes the version it declares — if PyPI doesn't already
8+
# have it — and creates the matching tag + GitHub release.
9+
push:
10+
branches: [main]
11+
paths:
12+
- pyproject.toml
13+
- .github/workflows/publish.yml
14+
# Manual fallback: same behavior as the push trigger, run on demand.
815
workflow_dispatch:
9-
inputs:
10-
tag:
11-
description: "Release tag to create (e.g. v0.3.0)"
12-
required: true
13-
type: string
1416

1517
jobs:
1618
publish:
@@ -28,23 +30,40 @@ jobs:
2830
with:
2931
python-version: "3.12"
3032

33+
- name: Determine version and whether PyPI already has it
34+
id: meta
35+
run: |
36+
VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
37+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
38+
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
39+
if curl -fsS "https://pypi.org/pypi/arcade-agent/$VERSION/json" >/dev/null 2>&1; then
40+
echo "published=true" >> "$GITHUB_OUTPUT"
41+
echo "PyPI already has $VERSION - nothing to publish."
42+
else
43+
echo "published=false" >> "$GITHUB_OUTPUT"
44+
fi
45+
3146
- name: Install build tools
47+
if: steps.meta.outputs.published == 'false'
3248
run: pip install build
3349

3450
- name: Build package
51+
if: steps.meta.outputs.published == 'false'
3552
run: python -m build
3653

3754
- name: Publish to PyPI
55+
if: steps.meta.outputs.published == 'false'
3856
uses: pypa/gh-action-pypi-publish@v1.14.0
3957

40-
# Runs created via workflow_dispatch have no tag or release object yet;
41-
# create both at the built SHA after a successful publish.
42-
# (GITHUB_TOKEN-created releases do not re-trigger this workflow, so
43-
# this cannot double-publish.)
44-
- name: Create tag + GitHub release (dispatch runs only)
45-
if: github.event_name == 'workflow_dispatch'
58+
# Push/dispatch runs have no tag or release object yet; create both at
59+
# the built SHA after a successful publish. (GITHUB_TOKEN-created
60+
# releases do not re-trigger this workflow, so this cannot
61+
# double-publish.)
62+
- name: Create tag + GitHub release
63+
if: github.event_name != 'release' && steps.meta.outputs.published == 'false'
4664
env:
4765
GH_TOKEN: ${{ github.token }}
66+
TAG: ${{ steps.meta.outputs.tag }}
4867
run: |
49-
gh release create "${{ inputs.tag }}" --repo "$GITHUB_REPOSITORY" \
50-
--target "$GITHUB_SHA" --title "${{ inputs.tag }}" --generate-notes
68+
gh release create "$TAG" --repo "$GITHUB_REPOSITORY" \
69+
--target "$GITHUB_SHA" --title "$TAG" --generate-notes

0 commit comments

Comments
 (0)