Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/maintenance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ name: "🚧 Maintenance"
# wiki moves to offline/ on the gh-pages branch, untouched. Run it again unchecked to bring
# the wiki back as it was. While the page is up, 🚀 Deploy and ⏪ Rollback still work: they
# publish to the hidden wiki under offline/, so a fix can be checked there before the page
# comes down.
# comes down. If GitHub Pages failed to publish an earlier run, running it again with the
# same choice asks Pages to build the branch again.
on:
workflow_dispatch:
inputs:
Expand All @@ -16,7 +17,7 @@ on:

permissions:
contents: write # push the gh-pages branch
pages: read # check that GitHub Pages is set up
pages: write # check that GitHub Pages is set up, and ask it to build again
deployments: read # wait for GitHub Pages to publish

# Shares the deploy's queue, so it never runs at the same time as a deploy or a rollback.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The wiki is published at https://neotokyorebuild.github.io/ntre-wiki/. Maintaine

To undo a bad deploy, run the ⏪ Rollback workflow with the version to go back to (such as `0.2`). It points `latest` at that version without rebuilding anything. It doesn't change `main`, so fix or revert the change there before the next deploy, which publishes `main` again.

To take the wiki offline, run the 🚧 Maintenance workflow with its box checked. Every address into the wiki then shows a maintenance page, `wiki/maintenance.html`. The wiki itself moves, untouched, to `offline/` on the `gh-pages` branch, where it still works at https://neotokyorebuild.github.io/ntre-wiki/offline/latest/ for anyone who has the address. While the page is up, 🚀 Deploy and ⏪ Rollback still work, on the hidden wiki, so you can check a fix at that address first. Run the workflow again with the box unchecked to take the page down and bring the wiki back, with any deploys made in the meantime.
To take the wiki offline, run the 🚧 Maintenance workflow with its box checked. Every address into the wiki then shows a maintenance page, `wiki/maintenance.html`. The wiki itself moves, untouched, to `offline/` on the `gh-pages` branch, where it still works at https://neotokyorebuild.github.io/ntre-wiki/offline/latest/ for anyone who has the address. While the page is up, 🚀 Deploy and ⏪ Rollback still work, on the hidden wiki, so you can check a fix at that address first. Run the workflow again with the box unchecked to take the page down and bring the wiki back, with any deploys made in the meantime. If a run fails while waiting for GitHub Pages, run it again with the same choice: the branch is already right, so it asks Pages to build it again.

To remove old versions, run these locally. `delete` shows what it will delete and keep, asks first, and never deletes the version `latest` points at:

Expand Down
40 changes: 38 additions & 2 deletions deploy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
# into the wiki shows the page. The wiki still works at offline/latest/ for anyone who
# knows the address: it is out of the way, not secret. `off` moves the site back exactly as
# it was. While the page is up, deploy, rollback, list and delete work on the wiki under
# offline/, and the page stays up.
# offline/, and the page stays up. A run that finds nothing to change still checks that
# GitHub Pages published the branch, and asks Pages to build it again if it didn't.
set -euo pipefail
cd "$(dirname "$0")"

Expand Down Expand Up @@ -304,6 +305,40 @@ commit_pages() {
git update-ref "refs/heads/$BRANCH" "$commit" "$BASE"
}

# The last GitHub Pages build: its status, commit and creation time.
pages_build() { gh api -X GET "repos/$REPO_SLUG/pages/builds/latest" --jq '"\(.status) \(.commit) \(.created_at)"'; }

# The branch can be right while the site isn't: GitHub Pages sometimes fails to publish a
# push, and a run that then finds nothing to change pushes nothing. When the last Pages
# build isn't a good build of the branch's tip, ask Pages to build it again, and wait.
republish_if_needed() {
(( ! DRY_RUN )) || return 0
command -v gh >/dev/null && gh auth status >/dev/null 2>&1 || return 0
local head build before
head=$(git rev-parse "$BRANCH")
build=$(pages_build) || die "couldn't read the last GitHub Pages build: https://github.com/$REPO_SLUG/settings/pages"
case ${build% *} in
"built $head") return 0 ;;
"queued $head"|"building $head") say "GitHub Pages is still publishing $BRANCH: waiting" ;;
*)
say "GitHub Pages hasn't published $BRANCH (its last build: ${build% *}): asking it to build again"
before=${build##* }
gh api -X POST "repos/$REPO_SLUG/pages/builds" >/dev/null \
|| die "couldn't ask GitHub Pages to build again: the token needs pages: write"
;;
esac
for _ in $(seq 1 30); do
sleep 10
build=$(pages_build 2>/dev/null) || continue
[[ -z ${before:-} || ${build##* } != "$before" ]] || continue
case ${build% *} in
"built $head") say "GitHub Pages published $BRANCH"; return 0 ;;
errored*) die "GitHub Pages failed to build $BRANCH again: https://github.com/$REPO_SLUG/actions" ;;
esac
done
die "timed out waiting for GitHub Pages: https://github.com/$REPO_SLUG/actions"
}

# Report a run that changed nothing, in the workflow's summary too.
nothing_to_do() {
[[ -z ${GITHUB_ACTIONS:-} ]] || echo "::notice title=Nothing to do::$1"
Expand All @@ -321,7 +356,7 @@ maintenance() {
site=$(git rev-parse "$BASE:$SITE")

if [[ $1 == off ]]; then
[[ -n $SITE ]] || { nothing_to_do "the maintenance page isn't up"; return 0; }
[[ -n $SITE ]] || { nothing_to_do "the maintenance page isn't up"; republish_if_needed; return 0; }
say "Taking down the maintenance page and bringing the wiki back from $SITE"
commit_pages "$site" "Take down the maintenance page and bring the wiki back"
check_result "" ""
Expand All @@ -340,6 +375,7 @@ maintenance() {
' "$site" "$HIDDEN"; } | git mktree)
if ! commit_pages "$tree" "Put up the maintenance page and hide the wiki under $HIDDEN/"; then
nothing_to_do "the maintenance page is already up, and unchanged"
republish_if_needed
return 0
fi
say "Putting up the maintenance page and hiding the wiki under $HIDDEN/"
Expand Down
Loading