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
25 changes: 20 additions & 5 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<title>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 "<title>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"
12 changes: 10 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
<!-- cspell:ignore weisearts gshaw -- the sibling sites' domains -->

**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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exclude: [
"Gemfile.lock",
"LICENSE",
"README.md",
"scripts",
"vendor"
]

Expand Down
23 changes: 23 additions & 0 deletions scripts/deploy-guard.sh
Original file line number Diff line number Diff line change
@@ -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."
40 changes: 40 additions & 0 deletions scripts/pages-status.sh
Original file line number Diff line number Diff line change
@@ -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
Loading