From 15833ab01a24969cf1217e1a03abe977272d2ce8 Mon Sep 17 00:00:00 2001 From: Igor Lins e Silva <4753812+igorls@users.noreply.github.com> Date: Sat, 6 Jun 2026 04:43:35 -0300 Subject: [PATCH 1/2] ci(publish): add workflow_dispatch manual trigger GitHub doesn't reliably emit a release event when a draft tied to a pre-existing tag is published (e.g. publishing the long-standing v3.3.6 draft fired no run). Add a workflow_dispatch trigger with a 'tag' input so a maintainer can run the publish for any existing tag from the Actions tab or 'gh workflow run'. A resolve step picks the release tag or the input, format-validates it (^v[0-9][0-9A-Za-z.+-]*$) before any use as a git ref, and the existing on-main + version-match checks + the pypi approval gate apply unchanged to both paths. --- .github/workflows/publish.yml | 62 ++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ca1813c..e77b5ed 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,10 +2,16 @@ name: Publish to PyPI # Publishes mempalace to PyPI via Trusted Publishing (OIDC — no stored token). # -# Trigger: a GitHub Release is *published* (not merely drafted). The release may -# create the `v*` tag or be cut from an existing one — either way the checks -# below run here on purpose, so this pipeline is self-contained and never -# uploads a tag that isn't on main or doesn't match the version manifest. +# Triggers: +# * release: published — the normal path (drafting + publishing a GitHub +# Release fires this). +# * workflow_dispatch — a manual escape hatch. GitHub does not reliably emit +# a `release` event when a *draft* tied to a pre-existing tag is published, +# so this lets a maintainer run the publish for any existing tag from the +# Actions tab ("Run workflow" → enter the tag, e.g. v3.4.0). +# +# Either way the checks below run on purpose, so this pipeline is self-contained +# and never uploads a tag that isn't on main or doesn't match the version manifest. # # One-time setup required before the first run (see docs/RELEASING.md): # 1. PyPI → Manage project `mempalace` → Publishing → Add a trusted publisher: @@ -17,6 +23,12 @@ name: Publish to PyPI on: release: types: [published] + workflow_dispatch: + inputs: + tag: + description: "Existing tag to build and publish (e.g. v3.4.0). Used when the release event didn't fire." + required: true + type: string permissions: contents: read @@ -26,32 +38,52 @@ jobs: name: Build + pre-publish checks runs-on: ubuntu-latest steps: + - name: Resolve the release tag + id: tag + env: + RELEASE_TAG: ${{ github.event.release.tag_name }} + INPUT_TAG: ${{ github.event.inputs.tag }} + run: | + set -euo pipefail + tag="${RELEASE_TAG:-${INPUT_TAG:-}}" + if [[ -z "$tag" ]]; then + echo "::error::no tag to publish — neither a release tag nor a workflow_dispatch input was provided" + exit 1 + fi + # Validate the shape before it is ever used as a git ref (ref-injection + # guard): a leading 'v' plus alphanumerics, dot, plus, hyphen only. + if [[ ! "$tag" =~ ^v[0-9][0-9A-Za-z.+-]*$ ]]; then + echo "::error::tag '$tag' is not a valid release tag (expected vX.Y.Z[-suffix])" + exit 1 + fi + echo "tag=$tag" >> "$GITHUB_OUTPUT" + echo "Resolved tag: $tag" + - uses: actions/checkout@v6 with: - # No explicit ref: on a release event the default checkout is already - # the release tag's commit (github.ref = refs/tags/). This avoids - # interpolating the event-controlled tag_name into a checkout ref - # (ref-injection). fetch-depth: 0 gives the ancestry check full history. - fetch-depth: 0 + # Safe: steps.tag.outputs.tag is format-validated above. On a release + # event this equals the release tag; on workflow_dispatch it's the input. + ref: ${{ steps.tag.outputs.tag }} + fetch-depth: 0 # full history for the ancestry check - - name: Verify the release tag is on main + - name: Verify the tag is on main env: - TAG: ${{ github.event.release.tag_name }} + TAG: ${{ steps.tag.outputs.tag }} run: | set -euo pipefail git fetch --no-tags origin main - tag_sha=$(git rev-parse HEAD) # the checked-out release tag commit + tag_sha=$(git rev-parse HEAD) # the checked-out tag commit main_sha=$(git rev-parse FETCH_HEAD) if git merge-base --is-ancestor "$tag_sha" "$main_sha"; then echo "Tag $TAG ($tag_sha) is reachable from main — OK." else - echo "::error::Release tag $TAG is not an ancestor of main. Releases must be cut from main." + echo "::error::tag $TAG is not an ancestor of main. Releases must be cut from main." exit 1 fi - name: Verify the tag matches the version manifest env: - TAG: ${{ github.event.release.tag_name }} + TAG: ${{ steps.tag.outputs.tag }} run: | set -euo pipefail # version.py is the source of truth (per CLAUDE.md); version-guard.yml @@ -90,7 +122,7 @@ jobs: name: pypi url: https://pypi.org/p/mempalace permissions: - id-token: write # mint the short-lived OIDC token for Trusted Publishing + id-token: write # mint the short-lived OIDC token for Trusted Publishing steps: - name: Download dist artifacts uses: actions/download-artifact@v4 From d51e9434f9dfeab3377f6fe015826c2f3ee45010 Mon Sep 17 00:00:00 2001 From: Igor Lins e Silva <4753812+igorls@users.noreply.github.com> Date: Sat, 6 Jun 2026 04:50:02 -0300 Subject: [PATCH 2/2] ci(publish): qualify checkout ref to refs/tags + tighten tag regex Address Copilot review on #1708: - Check out refs/tags/ instead of the bare name, so a same-named branch can't be resolved instead of the tag object (checkout prefers branches on ambiguous refs). - Tighten the dispatch-input validation to require vMAJOR.MINOR.PATCH with an optional -/+ suffix, rejecting loose values like v3 / v3foo. --- .github/workflows/publish.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e77b5ed..d656615 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -51,9 +51,11 @@ jobs: exit 1 fi # Validate the shape before it is ever used as a git ref (ref-injection - # guard): a leading 'v' plus alphanumerics, dot, plus, hyphen only. - if [[ ! "$tag" =~ ^v[0-9][0-9A-Za-z.+-]*$ ]]; then - echo "::error::tag '$tag' is not a valid release tag (expected vX.Y.Z[-suffix])" + # guard): require vMAJOR.MINOR.PATCH with an optional -/+ suffix, so + # loose values like 'v3' or 'v3foo' are rejected. + re='^v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$' + if [[ ! "$tag" =~ $re ]]; then + echo "::error::tag '$tag' is not a valid release tag (expected vMAJOR.MINOR.PATCH[-suffix])" exit 1 fi echo "tag=$tag" >> "$GITHUB_OUTPUT" @@ -61,9 +63,10 @@ jobs: - uses: actions/checkout@v6 with: - # Safe: steps.tag.outputs.tag is format-validated above. On a release - # event this equals the release tag; on workflow_dispatch it's the input. - ref: ${{ steps.tag.outputs.tag }} + # Fully-qualified refs/tags/ so an unqualified name can't resolve to a + # same-named *branch* instead of the tag (checkout prefers branches). + # steps.tag.outputs.tag is format-validated above (ref-injection guard). + ref: refs/tags/${{ steps.tag.outputs.tag }} fetch-depth: 0 # full history for the ancestry check - name: Verify the tag is on main