diff --git a/.mise.toml b/.mise.toml
index 244707e..3c70a9d 100644
--- a/.mise.toml
+++ b/.mise.toml
@@ -33,13 +33,28 @@ run = "htmlproofer _site --disable-external --no-check-internal-hash"
[tasks.check]
depends = ["spell", "markdownlint", "links"]
-# Run after a deploy lands. Cloudflare Pages builds on push to main.
+# Run by deploy once Cloudflare Pages has built main.
[tasks.verify]
run = """
-curl -fsS https://birdsnearme.com/ | grep -q "
Birds Near Me" && echo "birdsnearme.com is up"
-test "$(curl -s -o /dev/null -w '%{http_code}' https://birdsnearme.com/no-such-page/)" = 404 && echo "404 page works"
+set -e
+curl -fsS https://birdsnearme.com/ | grep -q "Birds Near Me"
+echo "birdsnearme.com is up"
+test "$(curl -s -o /dev/null -w '%{http_code}' https://birdsnearme.com/no-such-page/)" = 404
+echo "404 page works"
"""
+# The one way to production. See Workshop's Tooling/deploy.md. Cloudflare Pages
+# builds main on push, so the push is the deploy and main may be ahead of origin.
+# The guard runs again after check in case check changed a file.
[tasks.deploy]
-depends = ["check"]
-run = "git push"
+run = [
+ "scripts/deploy-guard.sh --allow-ahead",
+ "mise run check",
+ "scripts/deploy-guard.sh --allow-ahead",
+ "git push origin main",
+ "scripts/pages-status.sh --wait",
+ "mise run verify",
+]
+
+[tasks.deploy-status]
+run = "scripts/pages-status.sh"
diff --git a/AGENTS.md b/AGENTS.md
index 2db2d6f..abd4af5 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -20,8 +20,9 @@ Keep it minimal. Don't add gems, plugins, pages or build steps unless asked.
mise run install # bundle install
mise run dev # serve on :4002 with livereload
mise run check # build + spell + markdownlint + internal links
-mise run verify # curl the live site after a deploy
-mise run deploy # check, then git push
+mise run deploy # guard, check, push, wait for Pages, verify
+mise run verify # curl the live site
+mise run deploy-status # is main live?
```
**Read the counts, not just the exit code.** html-proofer prints `Ran on N files` and cspell
@@ -40,6 +41,13 @@ identical across the five Jekyll sites (gshaw.ca, LandNav, AEDSim, Birds Near Me
weisearts.com): change them in one, then copy both files to the others.
+**Deploy with `mise run deploy`**, never a bare `git push` to `main`.
+`scripts/deploy-guard.sh` refuses unless the branch is `main`, the tree is clean and
+`origin/main` isn't ahead. Then it runs `check`, pushes, waits for the "Cloudflare Pages"
+check run on the commit (`scripts/pages-status.sh --wait`) and runs `verify`. A merged PR
+also deploys, since Pages builds every push to `main`. The rule and the list of sites are
+in [Workshop's deploy note](https://github.com/gshaw/Workshop/blob/main/Tooling/deploy.md).
+
GitHub Actions runs `mise run -c check` on pushes and PRs. It doesn't block Cloudflare.
## Layout
diff --git a/README.md b/README.md
index 3ef9352..0aafe71 100755
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ mise run dev # http://localhost:4002 with livereload
mise run check # build, spell check, markdown lint, internal links
```
-Pushing to `main` publishes the site on Cloudflare Pages. `mise run verify` checks the live site afterwards.
+Deploy with `mise run deploy`. It refuses unless you're on a clean `main` with nothing newer on GitHub, then checks, pushes, waits for Cloudflare Pages and runs `mise run verify`. `mise run deploy-status` says whether `main` is live. The rule is in [Workshop's deploy note](https://github.com/gshaw/Workshop/blob/main/Tooling/deploy.md).
## Powered By
diff --git a/_config.yml b/_config.yml
index 147517b..4977e04 100755
--- a/_config.yml
+++ b/_config.yml
@@ -23,6 +23,7 @@ exclude: [
"Gemfile.lock",
"LICENSE",
"README.md",
+ "scripts",
"vendor"
]
diff --git a/scripts/deploy-guard.sh b/scripts/deploy-guard.sh
new file mode 100755
index 0000000..a10dd4c
--- /dev/null
+++ b/scripts/deploy-guard.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+# Refuses a deploy unless what's on disk is a commit on GitHub's main, so what's
+# live is always one. The same file in every site repo; the rule and the list
+# of sites are in Workshop's Tooling/deploy.md.
+#
+# scripts/deploy-guard.sh # a Worker: main must equal origin/main
+# scripts/deploy-guard.sh --allow-ahead # Cloudflare Pages: the push is the deploy
+set -euo pipefail
+
+refuse() {
+ echo "Deploy refused: $*" >&2
+ exit 1
+}
+
+branch=$(git branch --show-current)
+[[ $branch == main ]] || refuse "on ${branch:-a detached HEAD}, not main."
+[[ -z $(git status --porcelain) ]] || refuse "uncommitted or untracked files."
+git fetch --quiet origin main || refuse "can't fetch origin/main."
+behind=$(git rev-list --count main..origin/main)
+ahead=$(git rev-list --count origin/main..main)
+((behind == 0)) || refuse "main is behind origin/main by $behind. Pull first."
+((ahead == 0)) || [[ ${1:-} == --allow-ahead ]] ||
+ refuse "main is ahead of origin/main by $ahead. Land it through a PR first."
diff --git a/scripts/pages-status.sh b/scripts/pages-status.sh
new file mode 100755
index 0000000..17b64b6
--- /dev/null
+++ b/scripts/pages-status.sh
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+# Says whether main is live, from the "Cloudflare Pages" check run that Pages
+# puts on each commit it builds. See Workshop's Tooling/deploy.md.
+#
+# scripts/pages-status.sh # mise run deploy-status
+# scripts/pages-status.sh --wait # after a push: wait until origin/main is live
+set -euo pipefail
+
+git fetch --quiet origin main
+repo=$(gh repo view --json nameWithOwner --jq .nameWithOwner)
+sha=$(git rev-parse origin/main)
+short=${sha:0:7}
+
+# "completed success", "completed failure", "in_progress null", or nothing
+# before Pages has seen the commit.
+build() {
+ gh api "repos/$repo/commits/$sha/check-runs?check_name=Cloudflare%20Pages" \
+ --jq '.check_runs[0] // empty | "\(.status) \(.conclusion)"'
+}
+
+if [[ ${1:-} == --wait ]]; then
+ for _ in $(seq 60); do
+ case $(build) in
+ "completed success") echo "$short is live." && exit 0 ;;
+ completed*) echo "Cloudflare Pages failed to build $short." >&2 && exit 1 ;;
+ esac
+ sleep 10
+ done
+ echo "Cloudflare Pages hasn't finished $short after 10 minutes." >&2
+ exit 1
+fi
+
+ahead=$(git rev-list --count origin/main..main)
+((ahead == 0)) || echo "main has $ahead commits not pushed, so not live."
+case $(build) in
+ "completed success") echo "origin/main ($short) is live." ;;
+ completed*) echo "origin/main ($short) failed to build. An older commit is live." ;;
+ "") echo "Cloudflare Pages hasn't built origin/main ($short)." ;;
+ *) echo "origin/main ($short) is building." ;;
+esac