@rathnasgala2/adapter-github-pages 0.1.2 → 0.1.4
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 +24 -0
- package/package.json +1 -1
- package/src/deployment.js +11 -3
- package/src/index.js +110 -13
- package/types/deployment.d.ts +4 -1
- package/types/index.d.ts +36 -0
- package/types/public-read.d.ts +9 -1
- package/types/store.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,30 @@ and this project adheres to
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.1.4] - 2026-12-06
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- A Pages deployment that ends `deployment_failed` is retried with a fresh
|
|
16
|
+
deployment of the same staged artifact, up to three tries in all with pauses
|
|
17
|
+
of 30 and 60 seconds, after first checking that the failed one was not in fact
|
|
18
|
+
served. Every try is returned as `deploymentAttempts`; cancellation, content
|
|
19
|
+
failure and loss are not retried, and a refused repeat fails as
|
|
20
|
+
`PAGES_DEPLOYMENT_RETRY_REJECTED`.
|
|
21
|
+
|
|
22
|
+
## [0.1.3] - 2026-10-23
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- The shipped TypeScript declarations (`types/`) are regenerated from `src/`.
|
|
27
|
+
The 0.1.2 package shipped the `observe` CDN wait and the transport error
|
|
28
|
+
policy in `src/` but declarations that predated them, so a TypeScript consumer
|
|
29
|
+
saw no `now` clock on the destination, no `cacheControl` on a public read and
|
|
30
|
+
no `entries` on the staged and certified records. The declarations now carry
|
|
31
|
+
`PagesDestination.now`, the `ObserveProgress` type, `readServedGeneration`,
|
|
32
|
+
`maxAgeSeconds` and the `cacheControl` and `entries` members. There is no
|
|
33
|
+
runtime change from 0.1.2.
|
|
34
|
+
|
|
11
35
|
## [0.1.2] - 2026-10-23
|
|
12
36
|
|
|
13
37
|
### Added
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rathnasgala2/adapter-github-pages",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Managed GitHub Pages deployment adapter: deterministic uncompressed ustar Pages carrier, raw Pages deployment REST catalog, bounded status polling and credential-free public verification.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
package/src/deployment.js
CHANGED
|
@@ -259,8 +259,10 @@ export async function createDeployment(context, input) {
|
|
|
259
259
|
* @param {{
|
|
260
260
|
* sleep?: (seconds: number) => Promise<void>,
|
|
261
261
|
* budgetSeconds?: number,
|
|
262
|
+
* staleFailureGraceSeconds?: number,
|
|
262
263
|
* stage?: string
|
|
263
|
-
* }} options polling controls; `
|
|
264
|
+
* }} options polling controls; `staleFailureGraceSeconds` re-reads a terminal
|
|
265
|
+
* failure seen sooner than that after the first read instead of taking it; `sleep` is injectable so a test proves the
|
|
264
266
|
* schedule without spending it in wall-clock time
|
|
265
267
|
* @returns {Promise<{
|
|
266
268
|
* status: string,
|
|
@@ -300,10 +302,16 @@ export async function pollDeployment(context, pagesDeploymentId, options) {
|
|
|
300
302
|
if (status === SUCCESS_STATUS) {
|
|
301
303
|
return { status, succeeded: true, observedStatuses, waitedSeconds };
|
|
302
304
|
}
|
|
303
|
-
if (
|
|
305
|
+
if (
|
|
306
|
+
TERMINAL_FAILURE_STATUSES.includes(status) &&
|
|
307
|
+
spent >= (options.staleFailureGraceSeconds ?? 0)
|
|
308
|
+
) {
|
|
304
309
|
return { status, succeeded: false, observedStatuses, waitedSeconds };
|
|
305
310
|
}
|
|
306
|
-
if (
|
|
311
|
+
if (
|
|
312
|
+
!TEMPORARY_STATUSES.includes(status) &&
|
|
313
|
+
!TERMINAL_FAILURE_STATUSES.includes(status)
|
|
314
|
+
) {
|
|
307
315
|
throw new PagesAdapterError(
|
|
308
316
|
`PAGES_DEPLOYMENT_STATUS_UNPARTITIONED`,
|
|
309
317
|
`${JSON.stringify(status)} is neither temporary nor terminal`,
|
package/src/index.js
CHANGED
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
GENERATION_MARKER_PATH,
|
|
41
41
|
MAXIMUM_PAGES_CARRIER_BYTES,
|
|
42
42
|
NORMAL_MODE,
|
|
43
|
+
POLL_BUDGET_SECONDS,
|
|
43
44
|
RECOVERY_MODE,
|
|
44
45
|
} from './constants.js';
|
|
45
46
|
import {
|
|
@@ -621,6 +622,40 @@ function requirePagesOidc(destination, input) {
|
|
|
621
622
|
};
|
|
622
623
|
}
|
|
623
624
|
|
|
625
|
+
/** The only terminal status a fresh deployment is created after. */
|
|
626
|
+
const RETRYABLE_STATUS = 'deployment_failed';
|
|
627
|
+
/** Deployments created for one activation, the first included. */
|
|
628
|
+
const DEPLOYMENT_MAX_TRIES = 3;
|
|
629
|
+
/** Seconds to pause before the second and the third deployment. */
|
|
630
|
+
const DEPLOYMENT_RETRY_PAUSES_SECONDS = Object.freeze([30, 60]);
|
|
631
|
+
/**
|
|
632
|
+
* One deadline for every try together, measured from the start of the
|
|
633
|
+
* activation: the first try keeps the whole poll budget as before, a retry
|
|
634
|
+
* gets what is left, and the job's 60 minutes keep a 20 minute margin.
|
|
635
|
+
*/
|
|
636
|
+
const ACTIVATION_DEADLINE_SECONDS = 2400;
|
|
637
|
+
/** A retry is not started with less than this left of the deadline. */
|
|
638
|
+
const MIN_RETRY_SECONDS = 300;
|
|
639
|
+
/**
|
|
640
|
+
* The poll is keyed on the build version, which GitHub documents as an
|
|
641
|
+
* accepted `{pages_deployment_id}` ("You can also give the commit SHA of the
|
|
642
|
+
* deployment") and which a re-create answers with the same id, so a read right
|
|
643
|
+
* after a retry's create can still show the previous deployment's terminal
|
|
644
|
+
* failure. A failure seen within this many seconds of a retry's create is
|
|
645
|
+
* therefore re-read, never taken.
|
|
646
|
+
*/
|
|
647
|
+
const RETRY_STALE_FAILURE_GRACE_SECONDS = 13;
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* @param {number} seconds seconds to wait
|
|
651
|
+
* @returns {Promise<void>} resolves after the wait
|
|
652
|
+
*/
|
|
653
|
+
function retrySleep(seconds) {
|
|
654
|
+
return new Promise((resolve) => {
|
|
655
|
+
setTimeout(resolve, seconds * 1000);
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
|
|
624
659
|
/**
|
|
625
660
|
* `activate`: create exactly one Pages deployment for a staged carrier and
|
|
626
661
|
* poll it to a terminal status (`activation: provider-promotion`).
|
|
@@ -806,24 +841,85 @@ export async function activate(input) {
|
|
|
806
841
|
});
|
|
807
842
|
|
|
808
843
|
state.inFlight.set(input.generationId, pagesBuildVersion);
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
844
|
+
const clock = input.destination.now ?? Date.now;
|
|
845
|
+
const activationStartedMs = clock();
|
|
846
|
+
/** @type {{try: number, status: string, deploymentId: string}[]} */
|
|
847
|
+
const deploymentAttempts = [];
|
|
848
|
+
/** @type {Awaited<ReturnType<typeof createDeployment>> | undefined} */
|
|
849
|
+
let created;
|
|
850
|
+
/** @type {Awaited<ReturnType<typeof pollDeployment>> | undefined} */
|
|
851
|
+
let polled;
|
|
852
|
+
for (let attemptNumber = 1; ; attemptNumber += 1) {
|
|
853
|
+
try {
|
|
854
|
+
created = await createDeployment(context, {
|
|
855
|
+
pagesArtifactId: record.pagesArtifactId,
|
|
856
|
+
pagesBuildVersion,
|
|
857
|
+
oidcToken: oidc.token,
|
|
858
|
+
oidcExpectation: oidc.expectation,
|
|
859
|
+
});
|
|
860
|
+
} catch (failure) {
|
|
861
|
+
if (attemptNumber === 1) {
|
|
862
|
+
throw failure;
|
|
863
|
+
}
|
|
864
|
+
// GitHub refused a repeated create for the same version after a
|
|
865
|
+
// failed deployment: never loop on it, fail clearly instead.
|
|
866
|
+
throw new PagesAdapterError(
|
|
867
|
+
`PAGES_DEPLOYMENT_RETRY_REJECTED`,
|
|
868
|
+
`try ${attemptNumber} of ${DEPLOYMENT_MAX_TRIES}: the provider refused a fresh deployment for ${pagesBuildVersion} after ${deploymentAttempts.map((entry) => entry.status).join(', ')}: ${failure instanceof Error ? failure.message : String(failure)}`,
|
|
869
|
+
);
|
|
870
|
+
}
|
|
871
|
+
const remainingSeconds =
|
|
872
|
+
ACTIVATION_DEADLINE_SECONDS - (clock() - activationStartedMs) / 1000;
|
|
873
|
+
polled = await pollDeployment(context, pagesBuildVersion, {
|
|
874
|
+
...(input.destination.sleep === undefined
|
|
875
|
+
? {}
|
|
876
|
+
: { sleep: input.destination.sleep }),
|
|
877
|
+
...(attemptNumber === 1
|
|
878
|
+
? {}
|
|
879
|
+
: {
|
|
880
|
+
budgetSeconds: Math.min(POLL_BUDGET_SECONDS, remainingSeconds),
|
|
881
|
+
staleFailureGraceSeconds: RETRY_STALE_FAILURE_GRACE_SECONDS,
|
|
882
|
+
}),
|
|
883
|
+
});
|
|
884
|
+
deploymentAttempts.push({
|
|
885
|
+
try: attemptNumber,
|
|
886
|
+
status: polled.status,
|
|
887
|
+
deploymentId: String(created.pagesDeploymentId),
|
|
888
|
+
});
|
|
889
|
+
// Only `deployment_failed` is retried: cancellation (a newer
|
|
890
|
+
// deployment), content failure and loss behave exactly as before.
|
|
891
|
+
if (
|
|
892
|
+
polled.succeeded ||
|
|
893
|
+
polled.status !== RETRYABLE_STATUS ||
|
|
894
|
+
attemptNumber >= DEPLOYMENT_MAX_TRIES
|
|
895
|
+
) {
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
// A failed deployment can still have been served: look before creating
|
|
899
|
+
// another, so a landed generation is never deployed twice.
|
|
900
|
+
const nowServed = await readServedGeneration(input.destination);
|
|
901
|
+
if (nowServed.generationId === input.generationId) {
|
|
902
|
+
polled = { ...polled, succeeded: true };
|
|
903
|
+
break;
|
|
904
|
+
}
|
|
905
|
+
const pause = DEPLOYMENT_RETRY_PAUSES_SECONDS[attemptNumber - 1] ?? 60;
|
|
906
|
+
const leftSeconds =
|
|
907
|
+
ACTIVATION_DEADLINE_SECONDS - (clock() - activationStartedMs) / 1000;
|
|
908
|
+
if (leftSeconds - pause < MIN_RETRY_SECONDS) {
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
await (input.destination.sleep ?? retrySleep)(pause);
|
|
912
|
+
}
|
|
820
913
|
state.inFlight.delete(input.generationId);
|
|
821
914
|
|
|
822
915
|
if (!polled.succeeded) {
|
|
823
|
-
|
|
916
|
+
const failed = new PagesAdapterError(
|
|
824
917
|
`PAGES_DEPLOYMENT_FAILED`,
|
|
825
|
-
`deployment ${pagesBuildVersion} reached terminal status ${polled.status}`,
|
|
918
|
+
`deployment ${pagesBuildVersion} reached terminal status ${polled.status}${deploymentAttempts.length > 1 ? ` after ${deploymentAttempts.length} tries` : ''}`,
|
|
826
919
|
);
|
|
920
|
+
// The journal's failure evidence reads this: every try, not just the last.
|
|
921
|
+
/** @type {any} */ (failed).deploymentAttempts = deploymentAttempts;
|
|
922
|
+
throw failed;
|
|
827
923
|
}
|
|
828
924
|
|
|
829
925
|
state.activations.set(input.generationId, {
|
|
@@ -846,6 +942,7 @@ export async function activate(input) {
|
|
|
846
942
|
pagesDeploymentId: String(created.pagesDeploymentId),
|
|
847
943
|
observedStatuses: Object.freeze(polled.observedStatuses),
|
|
848
944
|
providerIdentity: created,
|
|
945
|
+
deploymentAttempts: Object.freeze(deploymentAttempts),
|
|
849
946
|
...(priorObservation === undefined
|
|
850
947
|
? {}
|
|
851
948
|
: { pagesRecoveryObservation: priorObservation }),
|
package/types/deployment.d.ts
CHANGED
|
@@ -81,8 +81,10 @@ export function createDeployment(context: import("./rest.js").RestContext, input
|
|
|
81
81
|
* @param {{
|
|
82
82
|
* sleep?: (seconds: number) => Promise<void>,
|
|
83
83
|
* budgetSeconds?: number,
|
|
84
|
+
* staleFailureGraceSeconds?: number,
|
|
84
85
|
* stage?: string
|
|
85
|
-
* }} options polling controls; `
|
|
86
|
+
* }} options polling controls; `staleFailureGraceSeconds` re-reads a terminal
|
|
87
|
+
* failure seen sooner than that after the first read instead of taking it; `sleep` is injectable so a test proves the
|
|
86
88
|
* schedule without spending it in wall-clock time
|
|
87
89
|
* @returns {Promise<{
|
|
88
90
|
* status: string,
|
|
@@ -94,6 +96,7 @@ export function createDeployment(context: import("./rest.js").RestContext, input
|
|
|
94
96
|
export function pollDeployment(context: import("./rest.js").RestContext, pagesDeploymentId: string, options: {
|
|
95
97
|
sleep?: (seconds: number) => Promise<void>;
|
|
96
98
|
budgetSeconds?: number;
|
|
99
|
+
staleFailureGraceSeconds?: number;
|
|
97
100
|
stage?: string;
|
|
98
101
|
}): Promise<{
|
|
99
102
|
status: string;
|
package/types/index.d.ts
CHANGED
|
@@ -300,6 +300,7 @@ export type PagesDestination = Readonly<{
|
|
|
300
300
|
fetch?: typeof globalThis.fetch;
|
|
301
301
|
publicFetch?: typeof globalThis.fetch;
|
|
302
302
|
sleep?: (seconds: number) => Promise<void>;
|
|
303
|
+
now?: () => number;
|
|
303
304
|
runId?: string;
|
|
304
305
|
runAttempt?: number;
|
|
305
306
|
headSha?: string;
|
|
@@ -308,6 +309,41 @@ export type StagedFile = Readonly<{
|
|
|
308
309
|
path: string;
|
|
309
310
|
bytes: Buffer;
|
|
310
311
|
}>;
|
|
312
|
+
/**
|
|
313
|
+
* What `observe` keeps between passes so a retry reads only what is still
|
|
314
|
+
* wrong: the routes whose bytes already match the staged entry, the latest
|
|
315
|
+
* bytes of the others, and the marker read until it matches.
|
|
316
|
+
*/
|
|
317
|
+
export type ObserveProgress = {
|
|
318
|
+
matched: Map<string, import("./artifact-projection.js").ArtifactEntry>;
|
|
319
|
+
matchedPass: Map<string, number>;
|
|
320
|
+
latest: Map<string, import("./artifact-projection.js").ArtifactEntry>;
|
|
321
|
+
statuses: Map<string, number>;
|
|
322
|
+
served: Awaited<ReturnType<typeof readServedGeneration>> | null;
|
|
323
|
+
markerPass: number;
|
|
324
|
+
pass: number;
|
|
325
|
+
cursor: number;
|
|
326
|
+
confirmed: boolean;
|
|
327
|
+
errorCode: string | null;
|
|
328
|
+
errorStreak: number;
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Read the generation identity the public origin currently serves, or
|
|
332
|
+
* `null` when nothing has ever been activated. A redirecting origin is
|
|
333
|
+
* reported as the `PAGES_PUBLIC_REDIRECT` failure with the generation
|
|
334
|
+
* unknown, never thrown.
|
|
335
|
+
*
|
|
336
|
+
* @param {PagesDestination} destination the bound destination
|
|
337
|
+
* @returns {Promise<{generationId: string | null, artifactDigest: string | null, findings: string[], cacheControl?: string | null | undefined, failure?: PublicRedirectFailure}>}
|
|
338
|
+
* the observed public generation
|
|
339
|
+
*/
|
|
340
|
+
declare function readServedGeneration(destination: PagesDestination): Promise<{
|
|
341
|
+
generationId: string | null;
|
|
342
|
+
artifactDigest: string | null;
|
|
343
|
+
findings: string[];
|
|
344
|
+
cacheControl?: string | null | undefined;
|
|
345
|
+
failure?: PublicRedirectFailure;
|
|
346
|
+
}>;
|
|
311
347
|
export { EXPECT_NOTHING_SERVED, fenceFor, generateUuidV7 } from "@rathnasgala2/adapter-protocol";
|
|
312
348
|
export { decodeCarrier, encodeCarrier } from "./carrier.js";
|
|
313
349
|
export { GENERATION_MARKER_PATH, ADAPTER_VERSION, NORMAL_MODE, RECOVERY_MODE } from "./constants.js";
|
package/types/public-read.d.ts
CHANGED
|
@@ -12,12 +12,19 @@
|
|
|
12
12
|
* @returns {string} the absolute public URL
|
|
13
13
|
*/
|
|
14
14
|
export function publicUrlFor(publicBaseUrl: string, artifactRelativePath: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* The `max-age` a `Cache-Control` header declares, in seconds.
|
|
17
|
+
*
|
|
18
|
+
* @param {string | null | undefined} cacheControl the header value
|
|
19
|
+
* @returns {number | null} the lifetime, `null` when none is declared
|
|
20
|
+
*/
|
|
21
|
+
export function maxAgeSeconds(cacheControl: string | null | undefined): number | null;
|
|
15
22
|
/**
|
|
16
23
|
* Read one public route.
|
|
17
24
|
*
|
|
18
25
|
* @param {PublicContext} context the public-origin context
|
|
19
26
|
* @param {string} artifactRelativePath the artifact-relative POSIX path
|
|
20
|
-
* @returns {Promise<{status: number | 'redirect', bytes: Buffer | null, etag: string | null, toHost?: string | null, location?: string | null}>}
|
|
27
|
+
* @returns {Promise<{status: number | 'redirect', bytes: Buffer | null, etag: string | null, cacheControl?: string | null | undefined, toHost?: string | null, location?: string | null}>}
|
|
21
28
|
* the bounded observation; `bytes` is `null` for any non-`200` status. A
|
|
22
29
|
* `'redirect'` status carries the `toHost` and absolute `location` the
|
|
23
30
|
* origin named (`null` when it named none that could be read).
|
|
@@ -26,6 +33,7 @@ export function readPublic(context: PublicContext, artifactRelativePath: string)
|
|
|
26
33
|
status: number | "redirect";
|
|
27
34
|
bytes: Buffer | null;
|
|
28
35
|
etag: string | null;
|
|
36
|
+
cacheControl?: string | null | undefined;
|
|
29
37
|
toHost?: string | null;
|
|
30
38
|
location?: string | null;
|
|
31
39
|
}>;
|
package/types/store.d.ts
CHANGED
|
@@ -48,6 +48,7 @@ export type StageRecord = Readonly<{
|
|
|
48
48
|
artifactId: string;
|
|
49
49
|
artifactDigest: string;
|
|
50
50
|
entryPaths: readonly string[];
|
|
51
|
+
entries: readonly import("./artifact-projection.js").ArtifactEntry[];
|
|
51
52
|
carrierBytes: Buffer;
|
|
52
53
|
carrierDigest: string;
|
|
53
54
|
pagesArtifactId: string;
|
|
@@ -61,6 +62,7 @@ export type DestinationState = {
|
|
|
61
62
|
pagesDeploymentId: string;
|
|
62
63
|
certifiedAt: string;
|
|
63
64
|
entryPaths: readonly string[];
|
|
65
|
+
entries: readonly import("./artifact-projection.js").ArtifactEntry[];
|
|
64
66
|
}>;
|
|
65
67
|
inFlight: Map<string, string>;
|
|
66
68
|
};
|