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
12 changes: 11 additions & 1 deletion .github/workflows/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
- name: Check live Pages availability
shell: bash
run: |
# Probe every URL before failing so the log shows how many pages broke
# (one path vs every path); runbooks/availability-failure.md relies on it.
probed=0
failed=0
for url in https://hivecommons.dev/ https://hivecommons.dev/stories/ \
https://hivecommons.dev/docs/ https://hivecommons.dev/code/ \
https://hivecommons.dev/discord/ https://hivecommons.dev/join/ \
Expand All @@ -38,12 +42,18 @@ jobs:
status=$(curl --silent --show-error --output /dev/null \
--write-out '%{http_code}' --connect-timeout 10 --max-time 30 \
--retry 2 --retry-delay 5 "$url" || true)
probed=$((probed + 1))
if [[ "$status" != 200 ]]; then
echo "::error::Live page $url returned HTTP $status (expected 200)"
exit 1
failed=$((failed + 1))
continue
fi
echo "$url returned HTTP $status"
done
if (( failed > 0 )); then
echo "::error::$failed of $probed probed pages did not return HTTP 200"
exit 1
fi

links:
if: github.event_name != 'schedule' || github.event.schedule == '17 9 * * 1'
Expand Down
6 changes: 4 additions & 2 deletions runbooks/availability-failure.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ probe runs (about 12 hours) should be treated as an outage, not a blip.

## Triage

1. Read the failing step's log: the `::error::` line names the URL and the HTTP status.
A connection or TLS error (no status) points at DNS, certificate or network; a
1. Read the failing step's log: each `::error::` line names a URL and its HTTP status,
and the final `N of M probed pages did not return HTTP 200` line tells one path from
every path directly.
A connection or TLS error (`HTTP 000`) points at DNS, certificate or network; a
`404` on one path points at content; a `404` or other error on every path points
at Pages or the custom domain.
2. Re-run the probe to rule out a transient fault:
Expand Down
25 changes: 25 additions & 0 deletions scripts/availability-probes.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ export function runbookProbedPaths(markdown) {
return paths;
}

// Text of the availability loop from `do` to its closing `done`, and what
// follows it. Returns null when the job or the loop is absent.
export function probeLoopParts(yaml) {
const job = /^\s{2}availability:\s*$([\s\S]*?)(?=^\s{2}\S|(?![\s\S]))/m.exec(yaml);
if (!job) return null;
const loop = /for\s+url\s+in\s+[\s\S]*?;\s*do\b([\s\S]*?)^\s*done\b([\s\S]*)$/m.exec(job[1]);
return loop ? { body: loop[1], after: loop[2] } : null;
}

export function sitemapLocs(xml) {
return [...xml.matchAll(/<loc>\s*([^<\s]+)\s*<\/loc>/g)].map((m) => m[1]);
}
Expand Down Expand Up @@ -369,3 +378,19 @@ test("runbooks/availability-failure.md names exactly the paths the links.yml ava
"the availability runbook's probe list drifted from .github/workflows/links.yml; update the runbook intro (or, if a probe was dropped, the workflow)",
);
});

test("fixture: probeLoopParts separates the loop body from the code after done", () => {
const yaml = "jobs:\n availability:\n steps:\n - run: |\n for url in a b; do\n exit 1\n done\n exit 2\n";
const parts = probeLoopParts(yaml);
assert.match(parts.body, /exit 1/);
assert.match(parts.after, /exit 2/);
assert.equal(probeLoopParts("jobs:\n other:\n"), null);
assert.equal(probeLoopParts("jobs:\n availability:\n steps:\n - run: curl -fsS a\n"), null, "job without a for-loop");
});

test("links.yml availability loop probes every URL: `exit` only after `done`, never inside the loop", () => {
const parts = probeLoopParts(readFileSync(WORKFLOW, "utf8"));
assert.ok(parts, "availability job has no `for url in ...; do ... done` loop");
assert.doesNotMatch(parts.body, /^[^#\n]*\bexit\b/m, "exit inside the loop stops at the first failing URL; count failures and exit after done");
assert.match(parts.after, /\bexit\s+1\b/, "the job must still fail after done when any probe failed");
});
Loading