Skip to content

Commit 272f954

Browse files
fix(ci): rebuild GitHub Pages after a release is published (#385)
1 parent dd22631 commit 272f954

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎.github/workflows/go.yml‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ jobs:
354354
contents: write
355355
id-token: write
356356
attestations: write
357+
# Needed to start the GitHub Pages rebuild after the release is public
358+
# (#370). Pages cannot be started by the release event itself, because
359+
# GITHUB_TOKEN events do not trigger other workflows.
360+
actions: write
357361

358362
steps:
359363
# GoReleaser and gh take the token from the environment, so the checkout
@@ -426,6 +430,35 @@ jobs:
426430
shell: bash
427431
run: gh release edit "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" --draft=false
428432

433+
# pages.yml has a `release: published` trigger, but GitHub does not start a
434+
# workflow for an event caused by GITHUB_TOKEN, so a GoReleaser publish
435+
# never fires it (#370). Start the rebuild directly. It checks out main and
436+
# the header reads the latest release from the Pages metadata, so the site
437+
# shows the tag that was just published.
438+
- name: Rebuild GitHub Pages
439+
env:
440+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
441+
shell: bash
442+
run: |
443+
set -euo pipefail
444+
before=$(date -u -d '10 seconds ago' +%Y-%m-%dT%H:%M:%SZ)
445+
gh workflow run "GitHub Pages" --repo "${GITHUB_REPOSITORY}" --ref main
446+
run_id=""
447+
for _ in $(seq 1 10); do
448+
run_id=$(gh run list --repo "${GITHUB_REPOSITORY}" --workflow "GitHub Pages" \
449+
--event workflow_dispatch --limit 10 --json databaseId,createdAt \
450+
| jq -r --arg before "$before" '[.[] | select(.createdAt > $before)][0].databaseId // empty')
451+
if [ -n "${run_id}" ]; then
452+
break
453+
fi
454+
sleep 3
455+
done
456+
if [ -z "${run_id}" ]; then
457+
echo "GitHub Pages workflow run did not start" >&2
458+
exit 1
459+
fi
460+
gh run watch "${run_id}" --repo "${GITHUB_REPOSITORY}" --exit-status
461+
429462
# Publishes a multi-arch image to GHCR once the release itself is public
430463
# (#40). The Dockerfile cross-compiles in a build-platform builder stage, so
431464
# arm64 needs no QEMU. `latest` only moves for non-prerelease tags.

‎.github/workflows/pages.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ name: GitHub Pages
44
# header shows the new tag. Docs for a feature that is on main but not
55
# released yet go live with that push; docs/_data/unreleased.yml tags them
66
# "unreleased" until the release (#213).
7+
#
8+
# The `release` trigger below only fires for a release published outside the
9+
# release workflow. GoReleaser publishes with GITHUB_TOKEN, and GitHub does not
10+
# start a workflow for an event caused by that token, so go.yml starts this
11+
# workflow directly after the release is public (#370).
712
on:
813
push:
914
branches:

0 commit comments

Comments
 (0)