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
21 changes: 17 additions & 4 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,20 @@ invalid JSON), even when the project data would match. It never writes.
`npm test` runs it offline against `test/fixtures/pages/` with a negative case
for each check.

Last verified 2026-10-13 via the API: production branch `main`,
automatic production deployments enabled, preview deployments `all`,
build output `landing`, no build command, domains `patchling.pages.dev` and
`patchling.app`, latest production deployment = `main` @ `58a3858` (#5).
## Verify a production merge

After an intended production merge without `[CF-Pages-Skip]`, pass the full
merge commit SHA. The verifier checks the active deployment and succeeds once
Cloudflare reports a successful GitHub `main` deployment of that exact commit.
The same flag works on a saved API response.

```sh
CF_ACCOUNT_ID=9a79801cc6e129d0ab3447ff14820c4a \
node scripts/check-pages-settings.mjs --expect-production-sha "$MERGE_SHA"
```

A preview can build the same `landing/` files while the production deployment
still serves an earlier commit. On 2026-11-19, Cloudflare reported production
at `b8b7936` and recorded explicit commit-message skips on the four newer
merges. The `042959c6.patchling.pages.dev` preview served all seven files from
the `landing/` tree at `main` commit `25c5d21`.
30 changes: 27 additions & 3 deletions scripts/check-pages-settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* node scripts/check-pages-settings.mjs # live: CLOUDFLARE_API_TOKEN + CF_ACCOUNT_ID
* node scripts/check-pages-settings.mjs --from-file r.json # a saved API response
* node scripts/check-pages-settings.mjs --from-file - # the response on stdin
* node scripts/check-pages-settings.mjs --expect-production-sha <merge SHA>
*/
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
Expand All @@ -26,9 +27,10 @@ export const EXPECTED = Object.freeze({
* Compare a Pages project API response (`{ result }` or the bare project)
* to {@link EXPECTED}.
* @param {any} response
* @param {string} [expectedProductionSha] Exact merge commit to verify, if supplied.
* @returns {{ ok: boolean, checks: { name: string, ok: boolean, got: unknown, want: unknown }[], info: string }}
*/
export function checkPagesProject(response) {
export function checkPagesProject(response, expectedProductionSha) {
const r = (response && response.result) || response || {};
const src = (r.source && r.source.config) || {};
const bc = r.build_config || {};
Expand Down Expand Up @@ -56,7 +58,23 @@ export function checkPagesProject(response) {
checks.push({ name: 'source.productionBranch', ok: false, got: src.production_branch, want: EXPECTED.productionBranch });
}
const dep = r.canonical_deployment || {};
const meta = (dep.deployment_trigger && dep.deployment_trigger.metadata) || {};
const trigger = dep.deployment_trigger || {};
const meta = trigger.metadata || {};
if (expectedProductionSha !== undefined) {
const deploymentChecks = {
productionCommit: [meta.commit_hash, expectedProductionSha],
productionRef: [meta.branch, EXPECTED.productionBranch],
productionCommitDirty: [meta.commit_dirty, false],
deploymentEnvironment: [dep.environment, 'production'],
deploymentStage: [dep.latest_stage?.name, 'deploy'],
deploymentStatus: [dep.latest_stage?.status, 'success'],
deploymentTrigger: [trigger.type, 'github:push'],
deploymentSkipped: [dep.is_skipped, false],
};
for (const [name, [got, want]] of Object.entries(deploymentChecks)) {
checks.push({ name, ok: got === want, got: got ?? null, want });
}
}
const info = `latest production: ${meta.branch ?? '?'} @ ${String(meta.commit_hash || '').slice(0, 7)} ${dep.created_on || ''}`.trim();
return { ok: checks.every((c) => c.ok), checks, info };
}
Expand Down Expand Up @@ -116,7 +134,13 @@ async function load(argv) {

if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
try {
const report = checkPagesProject(unwrapEnvelope(await load(process.argv.slice(2))));
const args = process.argv.slice(2);
const shaIndex = args.indexOf('--expect-production-sha');
const expectedProductionSha = shaIndex < 0 ? undefined : args[shaIndex + 1];
if (shaIndex >= 0 && !/^[a-f0-9]{40}$/.test(expectedProductionSha ?? '')) {
throw new Error('--expect-production-sha needs a full 40-character Git commit SHA');
}
const report = checkPagesProject(unwrapEnvelope(await load(args)), expectedProductionSha);
console.log(formatReport(report));
process.exit(report.ok ? 0 : 1);
} catch (err) {
Expand Down
36 changes: 36 additions & 0 deletions test/check_pages_settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,42 @@ test('CLI: stdin with preview none exits 1', () => {
assert.match(run.stdout, /FAIL previewDeploymentSetting = "none"/);
});

test('CLI verifies the exact successful production deployment when requested', () => {
const sha = 'b8b7936a2f38f0e3536f29206c3b0b29ba1a57a2';
const response = ok();
const deployment = {
environment: 'production',
is_skipped: false,
latest_stage: { name: 'deploy', status: 'success' },
deployment_trigger: { type: 'github:push', metadata: { branch: 'main', commit_hash: sha, commit_dirty: false } },
};
response.result.canonical_deployment = deployment;
const run = (expected) => spawnSync(process.execPath,
[script, '--from-file', '-', '--expect-production-sha', expected],
{ input: JSON.stringify(response), encoding: 'utf8', env: {} });

assert.equal(run(sha).status, 0);
const stale = run('a'.repeat(40));
assert.equal(stale.status, 1);
assert.match(stale.stdout, /FAIL productionCommit/);
assert.equal(run(sha.slice(0, 7)).status, 2);

for (const [name, changed, expectedFailure] of [
['preview', { environment: 'preview' }, /FAIL deploymentEnvironment/],
['skipped', { is_skipped: true }, /FAIL deploymentSkipped/],
['build only', { latest_stage: { name: 'build', status: 'success' } }, /FAIL deploymentStage/],
['failed', { latest_stage: { name: 'deploy', status: 'failure' } }, /FAIL deploymentStatus/],
['manual upload', { deployment_trigger: { ...deployment.deployment_trigger, type: 'ad_hoc' } }, /FAIL deploymentTrigger/],
['dirty source', { deployment_trigger: { ...deployment.deployment_trigger,
metadata: { ...deployment.deployment_trigger.metadata, commit_dirty: true } } }, /FAIL productionCommitDirty/],
]) {
response.result.canonical_deployment = { ...deployment, ...changed };
const result = run(sha);
assert.equal(result.status, 1, name);
assert.match(result.stdout, expectedFailure);
}
});

test('docs/deploy.md table matches EXPECTED exactly', () => {
const doc = readFileSync(new URL('../docs/deploy.md', import.meta.url), 'utf8');
const rows = {
Expand Down
Loading