Auto-release follows CI instead of testing the release again

A version bump on main ran the whole suite twice: once in CI for the
push, once more in auto-release. Auto-release now starts when CI
finishes on main and releases only if that run was green, tagging the
exact commit CI tested. Started by hand, it still tests first, since
there is no CI result to go by.
This commit is contained in:
Frederic Jung 2026-11-07 10:00:15 +01:00
parent 0342d90657
commit 03523cb16b
No known key found for this signature in database
3 changed files with 34 additions and 14 deletions

View file

@ -5,10 +5,15 @@ name: Auto-release
# as notes, and starts the deploy. Releases created with the workflow token do
# not fire the "released" event, so the deploy is started explicitly, from the
# tag, which keeps the github-pages environment's v* tag rule happy.
#
# It runs when CI finishes on main, so a release never repeats the push's tests:
# CI green on the commit that bumped the version is the go. A red CI releases
# nothing. Started by hand, it has no CI result to go by, so it tests first.
on:
push:
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]
paths: [package.json]
workflow_dispatch:
permissions:
@ -21,6 +26,10 @@ concurrency:
jobs:
check:
# After CI: only a green run of a push to main (not a PR's run, not a release's own call).
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push')
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
@ -29,9 +38,12 @@ jobs:
ver: ${{ steps.v.outputs.ver }}
tag: ${{ steps.v.outputs.tag }}
pre: ${{ steps.v.outputs.pre }}
# The commit CI tested (main may have moved on since); by hand, main as it is now.
sha: ${{ github.event.workflow_run.head_sha || github.sha }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
fetch-depth: 0
- name: Work out the version and whether it is new
@ -58,23 +70,30 @@ jobs:
case "$ver" in *-*) echo "pre=true" >> "$GITHUB_OUTPUT";; *) echo "pre=false" >> "$GITHUB_OUTPUT";; esac
echo "skip=false" >> "$GITHUB_OUTPUT"
# The same tests as every push, split over several runners (ci.yml), before anything is tagged.
# Only when started by hand: after a push, CI has already tested this commit.
tests:
needs: check
if: needs.check.outputs.skip == 'false'
if: needs.check.outputs.skip == 'false' && github.event_name == 'workflow_dispatch'
uses: ./.github/workflows/ci.yml
with:
ref: ${{ needs.check.outputs.sha }}
release:
needs: [check, tests]
if: needs.check.outputs.skip == 'false'
if: >-
always() && needs.check.result == 'success' && needs.check.outputs.skip == 'false' &&
(needs.tests.result == 'success' || needs.tests.result == 'skipped')
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.check.outputs.tag }}
VER: ${{ needs.check.outputs.ver }}
PRE: ${{ needs.check.outputs.pre }}
SHA: ${{ needs.check.outputs.sha }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.check.outputs.sha }}
- name: Publish the release
run: |
@ -82,11 +101,11 @@ jobs:
awk -v v="$VER" 'index($0,"## ["v"]")==1{f=1;next} /^## \[/{f=0} f' CHANGELOG.md | sed -e '/./,$!d' > notes.md
pre=(); [ "$PRE" = "true" ] && pre=(--prerelease)
gh release create "$TAG" --repo "$GITHUB_REPOSITORY" \
--target "$GITHUB_SHA" --title "$VER" --notes-file notes.md "${pre[@]}"
--target "$SHA" --title "$VER" --notes-file notes.md "${pre[@]}"
- name: Deploy it
# Pre-releases are for testing and never go live. The tag was just tested above, so the deploy does not
# test it again (tested=true).
# Pre-releases are for testing and never go live. CI (or the tests above) already passed on this commit,
# so the deploy does not test it again (tested=true).
if: env.PRE == 'false'
run: gh workflow run release.yml --repo "$GITHUB_REPOSITORY" --ref "$TAG" -f tag="$TAG" -f tested=true