@se-studio/site-check 2.22.1 → 2.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +1 -1
- package/develop-published-gate.mjs +236 -68
- package/docs/develop-published.md +10 -2
- package/package.json +3 -2
- package/templates/develop-published/develop-published-gate.yml +27 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 55c2a3b: develop-published-gate: the develop-vs-production compare is now on demand only. It is off by default and runs only with `--compare` (alias `--prod-compare`). Without it the stage reports exactly `compare: not run (on-demand)` and counts as neither a pass nor a fail (recorded in `--json` as `ok: null, skipped: true`), and `--prod-url` is no longer required. `--compare-timeout-minutes` and `GATE_COMPARE_TIMEOUT_MINUTES` apply only when the compare runs. Every other stage (exact commit, noindex, draft canary, full smoke, content smoke, sitemap slug-guard parity) runs unchanged on every deployment; parity fetches the build's own sitemap and never depended on the compare. The workflow template gains a `workflow_dispatch` boolean input `compare` (default false) that passes `--compare` only for a manual run; the deployment.ready path never does. Manual compare runs are never skipped as already green, have their own concurrency group, and post the same status context with the description noting whether the compare ran. Note for gate consumers: a green `develop-published gate` no longer includes a prod compare unless `--compare` was passed.
|
|
8
|
+
|
|
9
|
+
## 2.24.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 57e556e: develop-published-gate: the spawned prod compare limit is configurable and defaults to 25 minutes again. `--compare-timeout-minutes <n>` sets it, `GATE_COMPARE_TIMEOUT_MINUTES` overrides the default when it is a positive number, and the flag wins. The published gate had hard-coded 10 minutes, which contradicted the 25 minutes in the docs and the earlier changelog and would have killed healthy compares (HSD takes about 20, Pedestal about 30). Also adds `--no-draft-canary` for sites with no draft-only page: the draft-canary stage passes with a `SKIPPED` detail instead of failing for lack of `--draft-canary`. With these, the vendored gate copies (HSD, Eagle, Pedestal, Headwater, Brightline, BLK) can be replaced by the `develop-published-gate` bin.
|
|
14
|
+
|
|
15
|
+
## 2.23.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [53ee13b]
|
|
20
|
+
- @se-studio/core-ui@1.48.5
|
|
21
|
+
|
|
22
|
+
## 2.23.0
|
|
23
|
+
|
|
24
|
+
### Minor Changes
|
|
25
|
+
|
|
26
|
+
- 161a183: `develop-published-gate` adds a sitemap-parity stage: any path in the build's sitemap that fails core's impossible-slug guard (`pathnameHasImpossibleCmsSlug`, imported from `@se-studio/core-ui/impossible-cms-slug`) now FAILS the gate instead of passing silently. An unreadable build sitemap also fails. Adds `@se-studio/core-ui` as a dependency.
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [161a183]
|
|
31
|
+
- @se-studio/core-ui@1.48.4
|
|
32
|
+
|
|
3
33
|
## 2.22.1
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -259,7 +259,7 @@ Optional per-case HTML checks for release verification (key blocks must render,
|
|
|
259
259
|
|
|
260
260
|
### develop-published gate (`develop-published-gate`)
|
|
261
261
|
|
|
262
|
-
Promote gate against a persistent published-content build of develop: exact commit, noindex, draft canary, full smoke, content smoke and
|
|
262
|
+
Promote gate against a persistent published-content build of develop: exact commit, noindex, draft canary, full smoke, content smoke and sitemap slug-guard parity in one command; the prod compare runs only on demand (`--compare`). Workflow templates are in `templates/develop-published/`. See [docs/develop-published.md](./docs/develop-published.md).
|
|
263
263
|
|
|
264
264
|
### Publish-state check (CDA vs CPA)
|
|
265
265
|
|
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* develop-published promote gate.
|
|
5
5
|
*
|
|
6
|
-
* Runs the full smoke, the content smoke (cases with `contentAssert` only)
|
|
7
|
-
*
|
|
6
|
+
* Runs the full smoke, the content smoke (cases with `contentAssert` only), the sitemap slug-guard parity
|
|
7
|
+
* and the draft canary against the `develop-published` deployment of the exact commit being promoted.
|
|
8
|
+
* The develop-vs-production compare (sitemap pages exist, page text) is ON DEMAND ONLY: it runs just when
|
|
9
|
+
* `--compare` (alias `--prod-compare`) is given. Without it that stage reports `compare: not run (on-demand)`
|
|
10
|
+
* and counts as neither a pass nor a fail.
|
|
8
11
|
* Run it from the app root (where smoke.cases.json and vercel.json live).
|
|
9
12
|
*
|
|
10
13
|
* Usage:
|
|
@@ -12,10 +15,17 @@
|
|
|
12
15
|
*
|
|
13
16
|
* Options:
|
|
14
17
|
* --url <url> develop-published deployment URL (or DEPLOYMENT_URL)
|
|
15
|
-
* --prod-
|
|
18
|
+
* --compare, --prod-compare run the develop-vs-production compare (off by default, on demand only)
|
|
19
|
+
* --prod-url <url> production site for the compare (or PRODUCTION_SITE_URL). Required with
|
|
20
|
+
* --compare (or --sitemap-roots); not needed otherwise
|
|
16
21
|
* --expect-sha <sha> commit being promoted (default: git HEAD)
|
|
17
22
|
* --deployment-sha <sha> commit the deployment was built from (the Vercel dispatch payload sha)
|
|
18
23
|
* --draft-canary <path> path that exists only as a draft; must 404 on the deployment (repeatable)
|
|
24
|
+
* --no-draft-canary skip the canary stage (site has no draft-only page). Without it, giving no
|
|
25
|
+
* --draft-canary fails the gate. Ignored when a --draft-canary is also given
|
|
26
|
+
* --compare-timeout-minutes <n> kill the spawned prod compare after n minutes (default 25, or the
|
|
27
|
+
* GATE_COMPARE_TIMEOUT_MINUTES env when it is a positive number; the flag wins).
|
|
28
|
+
* Only used when --compare is given
|
|
19
29
|
* --sitemap-roots <list> sitemap roots this app owns, comma-separated paths or absolute URLs on the production
|
|
20
30
|
* site (e.g. /marketing/sitemap.xml); repeatable. The prod compare walks only these
|
|
21
31
|
* roots (an index is followed one level). Default: the full production sitemap
|
|
@@ -30,6 +40,7 @@
|
|
|
30
40
|
* --json <file> write the result summary as JSON
|
|
31
41
|
*
|
|
32
42
|
* Env: VERCEL_PROTECTION_BYPASS_TOKEN (deployment protection bypass; never printed).
|
|
43
|
+
* GATE_COMPARE_TIMEOUT_MINUTES (compare kill limit in minutes, default 25; ignored unless > 0).
|
|
33
44
|
* Exit 0 only when every stage passes, 1 when a stage fails, 2 on a usage or runtime error.
|
|
34
45
|
* See docs/develop-published.md.
|
|
35
46
|
*/
|
|
@@ -38,6 +49,7 @@ import fs from 'node:fs';
|
|
|
38
49
|
import os from 'node:os';
|
|
39
50
|
import path from 'node:path';
|
|
40
51
|
import { fileURLToPath } from 'node:url';
|
|
52
|
+
import { pathnameHasImpossibleCmsSlug } from '@se-studio/core-ui/impossible-cms-slug';
|
|
41
53
|
|
|
42
54
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
43
55
|
const SMOKE_LIVE = path.join(here, 'smoke-test-live.mjs');
|
|
@@ -61,7 +73,14 @@ export function parseArgs(argv) {
|
|
|
61
73
|
else if (a === '--expect-sha') o.expectSha = next();
|
|
62
74
|
else if (a === '--deployment-sha') o.deploymentSha = next();
|
|
63
75
|
else if (a === '--draft-canary') o.canaries.push(next());
|
|
64
|
-
else if (a === '--
|
|
76
|
+
else if (a === '--no-draft-canary') o.noCanary = true;
|
|
77
|
+
else if (a === '--compare' || a === '--prod-compare') o.compare = true;
|
|
78
|
+
else if (a === '--compare-timeout-minutes') {
|
|
79
|
+
const minutes = Number(next());
|
|
80
|
+
if (!Number.isFinite(minutes) || minutes <= 0)
|
|
81
|
+
throw new Error('--compare-timeout-minutes needs a positive number of minutes');
|
|
82
|
+
o.compareTimeoutMinutes = minutes;
|
|
83
|
+
} else if (a === '--sitemap-roots') {
|
|
65
84
|
const roots = splitRoots(next());
|
|
66
85
|
if (roots.length === 0) throw new Error('--sitemap-roots needs at least one root');
|
|
67
86
|
o.sitemapRoots.push(...roots);
|
|
@@ -163,8 +182,19 @@ function bypassHeaders(url) {
|
|
|
163
182
|
/** Per-request limit for every prod-compare / sitemap fetch (headers and body), so a stall cannot hang the run. */
|
|
164
183
|
export const FETCH_TIMEOUT_MS = 30_000;
|
|
165
184
|
|
|
166
|
-
/**
|
|
167
|
-
export const
|
|
185
|
+
/** Default whole-process limit for the spawned site-check compare (a healthy HSD compare takes ~20 minutes). */
|
|
186
|
+
export const DEFAULT_COMPARE_TIMEOUT_MINUTES = 25;
|
|
187
|
+
export const COMPARE_TIMEOUT_MS = DEFAULT_COMPARE_TIMEOUT_MINUTES * 60_000;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Whole-process limit for the spawned site-check compare, so a stall inside it cannot hang the run either.
|
|
191
|
+
* `--compare-timeout-minutes` wins, then a positive GATE_COMPARE_TIMEOUT_MINUTES, else the 25-minute default.
|
|
192
|
+
*/
|
|
193
|
+
export function resolveCompareTimeoutMs(flagMinutes, env = process.env) {
|
|
194
|
+
if (flagMinutes !== undefined) return flagMinutes * 60_000;
|
|
195
|
+
const fromEnv = Number(env.GATE_COMPARE_TIMEOUT_MINUTES);
|
|
196
|
+
return (fromEnv > 0 ? fromEnv : DEFAULT_COMPARE_TIMEOUT_MINUTES) * 60_000;
|
|
197
|
+
}
|
|
168
198
|
|
|
169
199
|
/** fetch() with a hard per-request timeout. The abort surfaces as a TimeoutError, which withRetry treats as transient. */
|
|
170
200
|
export function fetchWithTimeout(url, init = {}, timeoutMs = FETCH_TIMEOUT_MS) {
|
|
@@ -280,7 +310,7 @@ export function isNonPageUrl(url) {
|
|
|
280
310
|
* throws: the compare never passes on an empty or unreadable root.
|
|
281
311
|
* `fetchText(url)` resolves {status, text}.
|
|
282
312
|
*/
|
|
283
|
-
export async function collectRootPageUrls(rootUrls, fetchText) {
|
|
313
|
+
export async function collectRootPageUrls(rootUrls, fetchText, { rebaseChildren = false } = {}) {
|
|
284
314
|
const pages = [];
|
|
285
315
|
for (const root of rootUrls) {
|
|
286
316
|
const origin = new URL(root).origin;
|
|
@@ -293,9 +323,11 @@ export async function collectRootPageUrls(rootUrls, fetchText) {
|
|
|
293
323
|
if (!isIndex) {
|
|
294
324
|
rootPages.push(...locs);
|
|
295
325
|
} else {
|
|
296
|
-
for (const
|
|
297
|
-
|
|
298
|
-
|
|
326
|
+
for (const loc of locs) {
|
|
327
|
+
const childUrl = new URL(loc);
|
|
328
|
+
if (childUrl.origin !== origin && !rebaseChildren)
|
|
329
|
+
throw new Error(`child sitemap ${loc} of ${root} is not on ${origin}`);
|
|
330
|
+
const child = rebaseChildren ? `${origin}${childUrl.pathname}${childUrl.search}` : loc;
|
|
299
331
|
const c = await fetchText(child);
|
|
300
332
|
if (c.status < 200 || c.status >= 300)
|
|
301
333
|
throw new Error(`child sitemap ${child} of ${root} returned HTTP ${c.status}`);
|
|
@@ -372,6 +404,83 @@ export async function compareSitemapRoots({
|
|
|
372
404
|
};
|
|
373
405
|
}
|
|
374
406
|
|
|
407
|
+
/**
|
|
408
|
+
* Sitemap paths the core guard would 404. The guard is core's `pathnameHasImpossibleCmsSlug` (not a copy), so
|
|
409
|
+
* the sitemap and the routes cannot drift: a URL the sitemap advertises must never be one the app refuses.
|
|
410
|
+
* Returns the offending pathnames (decoded as listed), de-duplicated, in sitemap order.
|
|
411
|
+
*/
|
|
412
|
+
export function findImpossibleSitemapPaths(urls, isImpossible = pathnameHasImpossibleCmsSlug) {
|
|
413
|
+
const bad = [];
|
|
414
|
+
for (const u of urls) {
|
|
415
|
+
let pathname;
|
|
416
|
+
try {
|
|
417
|
+
pathname = new URL(u).pathname;
|
|
418
|
+
} catch {
|
|
419
|
+
bad.push(u);
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (isImpossible(pathname)) bad.push(pathname);
|
|
423
|
+
}
|
|
424
|
+
return [...new Set(bad)];
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Sitemap-parity stage: every page the deployment's own sitemap lists must pass the core slug guard. Roots are
|
|
429
|
+
* the build's sitemap roots (default `/sitemap.xml`, plus `/sitemap-unindexed.xml` when the build serves it; a 5xx on it fails). Index children are fetched from the build origin even when the build's sitemap lists them on the production domain.
|
|
430
|
+
* A sitemap that cannot be read FAILS (never a silent pass). `fetchText(url)` resolves {status, text}.
|
|
431
|
+
*/
|
|
432
|
+
export async function checkSitemapSlugParity({
|
|
433
|
+
rootUrls,
|
|
434
|
+
fetchText,
|
|
435
|
+
optionalRootUrls = [],
|
|
436
|
+
isImpossible = pathnameHasImpossibleCmsSlug,
|
|
437
|
+
}) {
|
|
438
|
+
let urls;
|
|
439
|
+
try {
|
|
440
|
+
const rebase = { rebaseChildren: true };
|
|
441
|
+
urls = await collectRootPageUrls(rootUrls, fetchText, rebase);
|
|
442
|
+
for (const root of optionalRootUrls) {
|
|
443
|
+
const probe = await fetchText(root);
|
|
444
|
+
if (probe.status >= 500)
|
|
445
|
+
throw new Error(`optional sitemap ${root} returned HTTP ${probe.status}`);
|
|
446
|
+
if (probe.status >= 200 && probe.status < 300)
|
|
447
|
+
urls = [...new Set([...urls, ...(await collectRootPageUrls([root], fetchText, rebase))])];
|
|
448
|
+
}
|
|
449
|
+
} catch (err) {
|
|
450
|
+
return {
|
|
451
|
+
ok: false,
|
|
452
|
+
offenders: [],
|
|
453
|
+
detail: `could not read the build sitemap: ${err instanceof Error ? err.message : String(err)}`,
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
const offenders = findImpossibleSitemapPaths(urls, isImpossible);
|
|
457
|
+
if (offenders.length > 0) {
|
|
458
|
+
const shown = offenders.slice(0, 10).join(', ');
|
|
459
|
+
return {
|
|
460
|
+
ok: false,
|
|
461
|
+
offenders,
|
|
462
|
+
detail: `${offenders.length} sitemap path(s) fail the core impossible-slug guard and would 404: ${shown}${offenders.length > 10 ? ', …' : ''}`,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
ok: true,
|
|
467
|
+
offenders: [],
|
|
468
|
+
detail: `${urls.length} sitemap URL(s) all pass the core slug guard`,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** Build sitemap roots: the configured roots rebased onto the deployment origin, else the default index. */
|
|
473
|
+
export function buildSitemapRoots(roots, prodUrl, devUrl) {
|
|
474
|
+
const dev = new URL(devUrl).origin;
|
|
475
|
+
if (roots.length === 0)
|
|
476
|
+
return { rootUrls: [`${dev}/sitemap.xml`], optionalRootUrls: [`${dev}/sitemap-unindexed.xml`] };
|
|
477
|
+
const rebased = resolveSitemapRoots(roots, prodUrl).map((r) => {
|
|
478
|
+
const u = new URL(r);
|
|
479
|
+
return `${dev}${u.pathname}${u.search}`;
|
|
480
|
+
});
|
|
481
|
+
return { rootUrls: rebased, optionalRootUrls: [] };
|
|
482
|
+
}
|
|
483
|
+
|
|
375
484
|
/** ": <reason>" when the roots compare itself failed (unreadable root), else "". Only the roots path prints this marker. */
|
|
376
485
|
function sitemapRootsError(out) {
|
|
377
486
|
const m = out.match(/^Sitemap roots failed: (.+)$/m);
|
|
@@ -514,10 +623,38 @@ async function headStatus(url) {
|
|
|
514
623
|
throw new Error(`Too many redirects from ${url}`);
|
|
515
624
|
}
|
|
516
625
|
|
|
626
|
+
/** Detail (and console line) of the prod-compare stage when the compare was not asked for. */
|
|
627
|
+
export const COMPARE_NOT_RUN = 'compare: not run (on-demand)';
|
|
628
|
+
|
|
629
|
+
/** The prod-compare stage when `--compare` was not given: neither a pass nor a fail (`ok: null`, `skipped: true`). */
|
|
630
|
+
export function compareNotRunStage() {
|
|
631
|
+
return { name: 'prod compare', ok: null, skipped: true, detail: COMPARE_NOT_RUN };
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/** The gate passes when every stage that ran passed. A skipped stage counts as neither a pass nor a fail. */
|
|
635
|
+
export function gateOk(stages) {
|
|
636
|
+
return stages.filter((x) => !x.skipped).every((x) => x.ok);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/** The draft-canary stage when no --draft-canary path was given: a failure, unless --no-draft-canary opts out. */
|
|
640
|
+
export function noCanaryStage(noCanary) {
|
|
641
|
+
return noCanary
|
|
642
|
+
? {
|
|
643
|
+
ok: true,
|
|
644
|
+
detail:
|
|
645
|
+
'SKIPPED (--no-draft-canary): this site has no draft-only page, published-only is not proven by a canary',
|
|
646
|
+
}
|
|
647
|
+
: { ok: false, detail: 'no --draft-canary given, published-only is unproven' };
|
|
648
|
+
}
|
|
649
|
+
|
|
517
650
|
export async function main(argv) {
|
|
518
651
|
const o = parseArgs(argv);
|
|
519
652
|
if (!o.url) throw new Error('--url (or DEPLOYMENT_URL) is required');
|
|
520
|
-
|
|
653
|
+
// The production URL is only used by the compare (and to resolve --sitemap-roots paths).
|
|
654
|
+
if (!o.prodUrl && (o.compare || o.sitemapRoots.length > 0))
|
|
655
|
+
throw new Error(
|
|
656
|
+
'--prod-url (or PRODUCTION_SITE_URL) is required with --compare or --sitemap-roots',
|
|
657
|
+
);
|
|
521
658
|
if (!o.hostPrefix)
|
|
522
659
|
throw new Error(
|
|
523
660
|
'--host-prefix is required (the bypass token is only sent to a matching *.vercel.app host)',
|
|
@@ -534,6 +671,8 @@ export async function main(argv) {
|
|
|
534
671
|
stages.push({ name, ok, detail });
|
|
535
672
|
console.log(`${ok ? 'PASS' : 'FAIL'} ${name}: ${detail}`);
|
|
536
673
|
};
|
|
674
|
+
let sitemapWarnings = [];
|
|
675
|
+
let pages = [];
|
|
537
676
|
|
|
538
677
|
// 0. exact commit
|
|
539
678
|
const commit = checkExactCommit(o.deploymentSha, expect);
|
|
@@ -558,8 +697,10 @@ export async function main(argv) {
|
|
|
558
697
|
`HTTP ${r.status} (404 means the draft is not served)`,
|
|
559
698
|
);
|
|
560
699
|
}
|
|
561
|
-
if (o.canaries.length === 0)
|
|
562
|
-
|
|
700
|
+
if (o.canaries.length === 0) {
|
|
701
|
+
const stage = noCanaryStage(o.noCanary);
|
|
702
|
+
add('draft canary', stage.ok, stage.detail);
|
|
703
|
+
}
|
|
563
704
|
|
|
564
705
|
// 2. full smoke
|
|
565
706
|
const smoke = run(process.execPath, [SMOKE_LIVE, '--url', o.url, o.cases], {
|
|
@@ -610,70 +751,97 @@ export async function main(argv) {
|
|
|
610
751
|
// 4a. prod compare: every production sitemap page that is live on production exists on the deployment.
|
|
611
752
|
// Pages that 404 on production itself are dead sitemap entries: a warning, not a gate failure.
|
|
612
753
|
// With --sitemap-roots only the roots this app owns are walked; without it the full production index is.
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
754
|
+
// Off unless --compare: then the stage is reported as not run, neither a pass nor a fail.
|
|
755
|
+
if (o.compare) {
|
|
756
|
+
const cmp =
|
|
757
|
+
o.sitemapRoots.length > 0
|
|
758
|
+
? await compareSitemapRoots({
|
|
759
|
+
rootUrls: resolveSitemapRoots(o.sitemapRoots, o.prodUrl),
|
|
760
|
+
devUrl: o.url,
|
|
761
|
+
fetchText: async (u) => {
|
|
762
|
+
const r = await get(u);
|
|
763
|
+
return { status: r.status, text: r.text };
|
|
764
|
+
},
|
|
765
|
+
headStatus,
|
|
766
|
+
})
|
|
767
|
+
: await runCompareWithRetry(() =>
|
|
768
|
+
run(
|
|
769
|
+
process.execPath,
|
|
770
|
+
[
|
|
771
|
+
SITE_CHECK,
|
|
772
|
+
o.prodUrl,
|
|
773
|
+
'--check-against',
|
|
774
|
+
o.url,
|
|
775
|
+
...(process.env.VERCEL_PROTECTION_BYPASS_TOKEN ? ['--vercel-bypass'] : []),
|
|
776
|
+
],
|
|
777
|
+
{},
|
|
778
|
+
resolveCompareTimeoutMs(o.compareTimeoutMinutes),
|
|
779
|
+
),
|
|
780
|
+
);
|
|
781
|
+
const sitemap = await judgeSitemapCompare(cmp, async (devUrl) => {
|
|
782
|
+
const u = new URL(devUrl);
|
|
783
|
+
return (await get(`${o.prodUrl}${u.pathname}${u.search}`)).status;
|
|
784
|
+
});
|
|
785
|
+
sitemapWarnings = sitemap.warnings;
|
|
786
|
+
for (const w of sitemap.warnings)
|
|
787
|
+
console.log(`WARN prod sitemap lists dead URL: ${w} (404/410 on production too)`);
|
|
788
|
+
add('prod compare: sitemap pages exist', sitemap.ok, sitemap.detail);
|
|
789
|
+
} else {
|
|
790
|
+
stages.push(compareNotRunStage());
|
|
791
|
+
console.log(COMPARE_NOT_RUN);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// 4a'. sitemap parity: no path the build's sitemap lists may fail the core impossible-slug guard. A hard
|
|
795
|
+
// failure (not a warning): such a path would 404 for crawlers and users while the sitemap advertises it.
|
|
796
|
+
const parity = await checkSitemapSlugParity({
|
|
797
|
+
...buildSitemapRoots(o.sitemapRoots, o.prodUrl, o.url),
|
|
798
|
+
fetchText: async (u) => {
|
|
799
|
+
const r = await get(u);
|
|
800
|
+
return { status: r.status, text: r.text };
|
|
801
|
+
},
|
|
641
802
|
});
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
803
|
+
add('sitemap slug guard parity', parity.ok, parity.detail);
|
|
804
|
+
|
|
805
|
+
// 4b. prod compare: text of representative pages (release rule 3). Part of the compare: only with --compare.
|
|
806
|
+
if (o.compare) {
|
|
807
|
+
const paths = asserting
|
|
808
|
+
.map((x) => x.path)
|
|
809
|
+
.filter((p, i, a) => a.indexOf(p) === i)
|
|
810
|
+
.slice(0, o.pages);
|
|
811
|
+
pages = [];
|
|
812
|
+
for (const p of paths) {
|
|
813
|
+
const [prod, dev] = await Promise.all([get(`${o.prodUrl}${p}`), get(`${o.url}${p}`)]);
|
|
814
|
+
const sim =
|
|
815
|
+
prod.status === 200 && dev.status === 200
|
|
816
|
+
? similarity(visibleLines(prod.text), visibleLines(dev.text))
|
|
817
|
+
: 0;
|
|
818
|
+
pages.push({
|
|
819
|
+
path: p,
|
|
820
|
+
prod: prod.status,
|
|
821
|
+
dev: dev.status,
|
|
822
|
+
similarity: Number(sim.toFixed(3)),
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
const bad = pages.filter((x) => x.similarity < o.minSimilarity);
|
|
826
|
+
add(
|
|
827
|
+
'prod compare: page text',
|
|
828
|
+
pages.length >= 3 && bad.length === 0,
|
|
829
|
+
`${pages.length} pages, min similarity ${Math.min(...pages.map((x) => x.similarity))} (threshold ${o.minSimilarity})`,
|
|
830
|
+
);
|
|
831
|
+
for (const p of pages)
|
|
832
|
+
console.log(` ${p.path} prod ${p.prod} dev ${p.dev} similarity ${p.similarity}`);
|
|
659
833
|
}
|
|
660
|
-
const bad = pages.filter((x) => x.similarity < o.minSimilarity);
|
|
661
|
-
add(
|
|
662
|
-
'prod compare: page text',
|
|
663
|
-
pages.length >= 3 && bad.length === 0,
|
|
664
|
-
`${pages.length} pages, min similarity ${Math.min(...pages.map((x) => x.similarity))} (threshold ${o.minSimilarity})`,
|
|
665
|
-
);
|
|
666
|
-
for (const p of pages)
|
|
667
|
-
console.log(` ${p.path} prod ${p.prod} dev ${p.dev} similarity ${p.similarity}`);
|
|
668
834
|
|
|
669
|
-
const ok = stages
|
|
835
|
+
const ok = gateOk(stages);
|
|
670
836
|
const result = {
|
|
671
837
|
ok,
|
|
672
838
|
url: o.url,
|
|
673
839
|
expectSha: expect,
|
|
674
840
|
deploymentSha: o.deploymentSha ?? null,
|
|
675
841
|
stages,
|
|
676
|
-
|
|
842
|
+
compare: !!o.compare,
|
|
843
|
+
warnings: sitemapWarnings.map((u) => `prod sitemap lists dead URL: ${u}`),
|
|
844
|
+
sitemapSlugOffenders: parity.offenders,
|
|
677
845
|
pages,
|
|
678
846
|
smoke: s,
|
|
679
847
|
contentSmoke: c,
|
|
@@ -21,13 +21,21 @@ One persistent Vercel preview build of a site's integration branch that reads **
|
|
|
21
21
|
|
|
22
22
|
## The gate
|
|
23
23
|
|
|
24
|
+
**The develop-vs-production compare is on demand only.** The gate runs the exact-commit, noindex, draft-canary, full smoke, content smoke and sitemap slug-guard parity stages on every `vercel.deployment.ready` event. The compare against production (sitemap pages exist, and page text) does not run unless `--compare` (alias `--prod-compare`) is passed. Without it the stage prints exactly `compare: not run (on-demand)`, is recorded in `--json` as `{name: "prod compare", ok: null, skipped: true}`, and counts as neither a pass nor a fail (a skipped stage never fails the gate and never rescues a failed one). `--prod-url` is then not needed (it is still required with `--compare`, and with `--sitemap-roots`, which resolves its paths against production). A green default gate therefore does **not** include a prod compare; ask for one when you want it (below).
|
|
25
|
+
|
|
24
26
|
```bash
|
|
25
27
|
develop-published-gate --url https://<project>-git-develop-published-<team>.vercel.app \
|
|
26
28
|
--prod-url https://www.example.com --host-prefix <project>- \
|
|
27
|
-
--deployment-sha <built sha> --expect-sha <promoted sha> --draft-canary /a-draft-only-path/
|
|
29
|
+
--deployment-sha <built sha> --expect-sha <promoted sha> --draft-canary /a-draft-only-path/ [--compare]
|
|
28
30
|
```
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
**Running the compare on demand.** In the workflow template, `workflow_dispatch` has a boolean input `compare` (default false). The gate step passes `--compare` only when the run is a manual one with `compare` ticked (`COMPARE_FLAG` env); the `repository_dispatch` deployment.ready path never does. A manual run is never skipped by skip-if-green. It posts the same `develop-published gate` status context as the normal gate, with the description saying whether the compare ran (`... (prod compare not run, on-demand)` or `... and prod compare (manual) ...`), so the promote PR keeps reading one context. A manual compare that fails posts `failure`, and being newest it re-opens the gate; one that passes posts `success`. A manual compare run has its own concurrency group (`...-compare`), so a later deployment.ready event for the same SHA cannot cancel it. The job `timeout-minutes: 35` is the same for both and stays above the compare's own 25 minute limit.
|
|
33
|
+
|
|
34
|
+
**Sitemap parity does not depend on the compare.** The slug-guard parity stage fetches the build's own sitemap (`<deployment>/sitemap.xml`, plus `/sitemap-unindexed.xml` when served, or the `--sitemap-roots` rebased onto the deployment) with its own requests; it never reads the compare's output or the production sitemap, so it runs unchanged with the compare off.
|
|
35
|
+
|
|
36
|
+
Options for sites that differ from the default: `--no-draft-canary` skips the draft-canary stage (recorded as a passing, clearly labelled `SKIPPED` stage) for a site with no draft-only page; it is ignored when a `--draft-canary` is also given, and giving neither still fails the gate. `--compare-timeout-minutes <n>` (or the `GATE_COMPARE_TIMEOUT_MINUTES` env, used only when it is a positive number; the flag wins) sets how long the spawned prod compare may run before it is killed; both apply only when `--compare` is given. The default is 25 minutes, which suits compares of up to about 20 minutes; give a slower site more (Pedestal, whose cold compare takes about 30 minutes, uses 45) and raise the job `timeout-minutes` above it.
|
|
37
|
+
|
|
38
|
+
Stages (exit 0 only if every stage that ran passes): exact commit (built from the promoted SHA, or from an ancestor when every file changed since is in `vercel.json`'s `ignoreCommand` pathspec); noindex; draft canary 404s; full smoke; content smoke (cases with `contentAssert`); prod compare, **only with `--compare`** (every production sitemap page that is live (200) on production exists on the build; a page that is 404/410 on production too is a "prod sitemap lists dead URL" warning, not a failure; transient fetch errors are retried 3 times with backoff; and the visible text of up to 5 representative pages matches, similarity >= 0.9). `--sitemap-roots <paths>` (comma-separated or repeated, default none) limits the sitemap compare to the sitemap roots this app owns, e.g. `--sitemap-roots /marketing/sitemap.xml` when the production domain is shared with other apps; without it the full production sitemap index (`/sitemap.xml` and `/sitemap-unindexed.xml`) is compared. An index root is followed one level; an unreadable, nested-index or empty root fails the stage. `--json` writes the result. `--host-prefix` is required. The bypass token goes only to the deployment host, which must be `<host-prefix>*.vercel.app`, the gate's own requests follow redirects by hand so a redirect off that host never carries it, and in compare mode `site-check` sends the bypass to the deployment only, never to production. (`site-check` itself still follows redirects automatically, so a deployment that redirects a sitemap path to another host would carry the header there; the Vercel deployment hosts do not.) **Sitemap slug guard parity** (a hard failure, not a warning): every path in the build's own sitemap (the `--sitemap-roots` rebased onto the deployment, else `/sitemap.xml` plus `/sitemap-unindexed.xml` when served) must pass core's `pathnameHasImpossibleCmsSlug` from `@se-studio/core-ui/impossible-cms-slug`, so the sitemap never advertises a path the app would 404; an unreadable build sitemap also fails. Noindex is read from `robots.txt` (disallow all) or the home page (`x-robots-tag` or meta robots).
|
|
31
39
|
|
|
32
40
|
The workflow template runs this when Vercel reports a `develop-published` deployment ready and posts commit status `develop-published gate` on the promoted SHA, which a develop -> main promote PR shows (its head is develop's head).
|
|
33
41
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@se-studio/site-check",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.25.0",
|
|
4
4
|
"description": "Validate SE marketing sites (sitemap, llms.txt) and download markdown files preserving structure",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -111,7 +111,8 @@
|
|
|
111
111
|
},
|
|
112
112
|
"dependencies": {
|
|
113
113
|
"@se-studio/contentful-rest-api": "2.9.2",
|
|
114
|
-
"@se-studio/core-data-types": "2.2.0"
|
|
114
|
+
"@se-studio/core-data-types": "2.2.0",
|
|
115
|
+
"@se-studio/core-ui": "1.48.5"
|
|
115
116
|
},
|
|
116
117
|
"devDependencies": {
|
|
117
118
|
"@biomejs/biome": "^2.6.8",
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
# project name), __PROD_URL__ and __DRAFT_CANARY__ (a draft-only path), and check the integration branch.
|
|
3
3
|
# If one repo gates several apps, copy the file per app and give each copy its own GATE_CONTEXT (e.g.
|
|
4
4
|
# `develop-published gate (<project>)`) and workflow name; the skip-if-green check reads that context.
|
|
5
|
-
# Promote gate: full smoke, content smoke and
|
|
5
|
+
# Promote gate: full smoke, content smoke, sitemap slug-guard parity and the draft canary against the
|
|
6
|
+
# develop-published build. The develop-vs-production compare is ON DEMAND ONLY: it never runs on a Vercel
|
|
7
|
+
# deployment.ready event, only on a manual run with the `compare` input ticked.
|
|
6
8
|
# Runs when Vercel finishes a develop-published deployment, and on demand. Posts a commit status
|
|
7
9
|
# `develop-published gate` on the exact commit, so a develop -> main promote PR (whose head is
|
|
8
10
|
# develop's head) shows it.
|
|
@@ -26,6 +28,11 @@ on:
|
|
|
26
28
|
description: Commit being promoted (default = deployment_sha)
|
|
27
29
|
required: false
|
|
28
30
|
type: string
|
|
31
|
+
compare:
|
|
32
|
+
description: Also run the full develop-vs-production compare (slow, on demand only)
|
|
33
|
+
required: false
|
|
34
|
+
type: boolean
|
|
35
|
+
default: false
|
|
29
36
|
|
|
30
37
|
permissions:
|
|
31
38
|
contents: read
|
|
@@ -33,9 +40,11 @@ permissions:
|
|
|
33
40
|
|
|
34
41
|
# One gate run per commit. A develop-published SHA is normally built twice (the branch push and the deploy
|
|
35
42
|
# hook), and each READY deployment sends its own vercel.deployment.ready event; the newer run cancels the
|
|
36
|
-
# older one. Events the job would skip anyway get a unique group so they can never cancel a real run.
|
|
43
|
+
# older one. Events the job would skip anyway get a unique group so they can never cancel a real run. A
|
|
44
|
+
# manual compare run has its own group (suffix -compare), so a later deployment.ready event for the same
|
|
45
|
+
# SHA can never cancel a ~20 minute compare, and the compare never cancels the normal gate run.
|
|
37
46
|
concurrency:
|
|
38
|
-
group: develop-published-gate-${{ github.event_name == 'workflow_dispatch' && (inputs.promote_sha || inputs.deployment_sha) || (github.event.client_payload.project.name == '__PROJECT_NAME__' && github.event.client_payload.git.ref == 'develop-published' && github.event.client_payload.environment == 'preview' && github.event.client_payload.git.sha) || github.run_id }}
|
|
47
|
+
group: develop-published-gate-${{ github.event_name == 'workflow_dispatch' && format('{0}{1}', inputs.promote_sha || inputs.deployment_sha, inputs.compare == true && '-compare' || '') || (github.event.client_payload.project.name == '__PROJECT_NAME__' && github.event.client_payload.git.ref == 'develop-published' && github.event.client_payload.environment == 'preview' && github.event.client_payload.git.sha) || github.run_id }}
|
|
39
48
|
cancel-in-progress: true
|
|
40
49
|
|
|
41
50
|
jobs:
|
|
@@ -49,18 +58,23 @@ jobs:
|
|
|
49
58
|
github.event.client_payload.environment == 'preview'
|
|
50
59
|
)
|
|
51
60
|
runs-on: ubuntu-latest
|
|
52
|
-
# A healthy prod compare of a large sitemap takes about 20 minutes
|
|
53
|
-
#
|
|
61
|
+
# A healthy prod compare of a large sitemap takes about 20 minutes (only on a manual run with compare
|
|
62
|
+
# on; the default gate takes a few minutes); this only stops a hung run. Kept at 35 for both so it stays
|
|
63
|
+
# above the compare's own 25 minute kill limit. A timed-out job counts as cancelled, so it posts no
|
|
64
|
+
# status (the promote PR shows none, not green).
|
|
54
65
|
timeout-minutes: 35
|
|
55
66
|
env:
|
|
56
67
|
GATE_CONTEXT: develop-published gate
|
|
57
68
|
DEPLOYMENT_URL: ${{ github.event_name == 'workflow_dispatch' && inputs.deployment_url || github.event.client_payload.url }}
|
|
58
69
|
DEPLOYMENT_SHA: ${{ github.event_name == 'workflow_dispatch' && inputs.deployment_sha || github.event.client_payload.git.sha }}
|
|
59
70
|
PROMOTE_SHA: ${{ github.event_name == 'workflow_dispatch' && (inputs.promote_sha || inputs.deployment_sha) || github.event.client_payload.git.sha }}
|
|
71
|
+
# `--compare` only for a manual run that ticked `compare`. The deployment.ready path never gets it.
|
|
72
|
+
COMPARE_FLAG: ${{ github.event_name == 'workflow_dispatch' && inputs.compare == true && '--compare' || '' }}
|
|
60
73
|
steps:
|
|
61
74
|
# A third deploy of a SHA that already passed must not run the gate again. Only a `success` status
|
|
62
75
|
# skips: failure, error, pending or no status runs the gate, and so does an API error. The newest
|
|
63
|
-
# status for the context wins, so a later failure re-opens the gate. Manual runs always run
|
|
76
|
+
# status for the context wins, so a later failure re-opens the gate. Manual runs always run, so a
|
|
77
|
+
# manual compare is never skipped because the default gate is already green.
|
|
64
78
|
- name: Skip when this commit already has a green gate status
|
|
65
79
|
id: already
|
|
66
80
|
if: github.event_name == 'repository_dispatch'
|
|
@@ -102,12 +116,13 @@ jobs:
|
|
|
102
116
|
--deployment-sha "$DEPLOYMENT_SHA" \
|
|
103
117
|
--expect-sha "$PROMOTE_SHA" \
|
|
104
118
|
--draft-canary "__DRAFT_CANARY__" \
|
|
119
|
+
$COMPARE_FLAG \
|
|
105
120
|
--json gate-result.json
|
|
106
121
|
- name: Gate summary
|
|
107
122
|
if: always() && steps.already.outputs.skip != 'true'
|
|
108
123
|
run: |
|
|
109
124
|
if [ -f gate-result.json ]; then
|
|
110
|
-
node -e 'const r=require("./gate-result.json");console.log("## develop-published gate: "+(r.ok?"PASS":"FAIL")+"\n");for(const s of r.stages)console.log("- "+(s.ok?"PASS":"FAIL")+" "+s.name+": "+s.detail)' >> "$GITHUB_STEP_SUMMARY"
|
|
125
|
+
node -e 'const r=require("./gate-result.json");console.log("## develop-published gate: "+(r.ok?"PASS":"FAIL")+"\n");for(const s of r.stages)console.log("- "+(s.skipped?"SKIP":s.ok?"PASS":"FAIL")+" "+s.name+": "+s.detail)' >> "$GITHUB_STEP_SUMMARY"
|
|
111
126
|
fi
|
|
112
127
|
- uses: actions/upload-artifact@v7
|
|
113
128
|
if: always() && steps.already.outputs.skip != 'true'
|
|
@@ -120,10 +135,14 @@ jobs:
|
|
|
120
135
|
env:
|
|
121
136
|
GH_TOKEN: ${{ github.token }}
|
|
122
137
|
STATE: ${{ job.status == 'success' && 'success' || 'failure' }}
|
|
138
|
+
# Same context for both kinds of run (the promote PR and the skip-if-green check read one context).
|
|
139
|
+
# The description says whether the compare ran. A manual compare that fails posts `failure`, and
|
|
140
|
+
# that newest status re-opens the gate; one that passes posts `success` with the compare noted.
|
|
141
|
+
DESCRIPTION: ${{ env.COMPARE_FLAG != '' && 'Smoke, content smoke, slug parity and prod compare (manual) on the develop-published build' || 'Smoke, content smoke and slug parity on the develop-published build (prod compare not run, on-demand)' }}
|
|
123
142
|
run: |
|
|
124
143
|
# On the promoted commit (the promote PR head). Same SHA as the build unless Vercel skipped it.
|
|
125
144
|
gh api "repos/${GITHUB_REPOSITORY}/statuses/${PROMOTE_SHA}" \
|
|
126
145
|
-f state="$STATE" \
|
|
127
146
|
-f context="$GATE_CONTEXT" \
|
|
128
|
-
-f description="
|
|
147
|
+
-f description="$DESCRIPTION" \
|
|
129
148
|
-f target_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
|