@rathnasgala2/adapter-github-pages 0.1.0 → 0.1.1

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 CHANGED
@@ -8,6 +8,45 @@ and this project adheres to
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ### Fixed
12
+
13
+ - Accept GitHub's `deployment_queued` Pages deployment status as temporary (keep
14
+ polling). It is in GitHub's REST reference but was missing from the accepted
15
+ vocabulary, so a real publish on 2026-10-06 stopped with
16
+ `PAGES_DEPLOYMENT_STATUS_UNKNOWN` and held the destination fence.
17
+
18
+ ## [0.1.1] - 2026-09-26
19
+
20
+ ### Added
21
+
22
+ - **PUB-L1:** `REDACTION_PLACEHOLDER` now comes from
23
+ `@rathnasgala2/adapter-protocol`, the one redaction sentinel every package
24
+ uses, instead of this package's own `'[redacted]'` literal. The value changes
25
+ from `'[redacted]'` to `'[REDACTED]'`; this constant is internal and was not
26
+ part of the published root export.
27
+ - **PUB-M11:** the manifest declares `"sideEffects": false`, so a bundler can
28
+ tree-shake an unused re-export from this package's barrel entry point instead
29
+ of conservatively retaining the whole thing.
30
+ - **PUB-L5:** `verifyPagesOidcToken` now checks the token's `exp`, `iat` and
31
+ (when present) `nbf` claims, each within a new `PAGES_OIDC_CLOCK_SKEW_SECONDS`
32
+ (300s) tolerance, raising `PAGES_OIDC_TOKEN_EXPIRED` or
33
+ `PAGES_OIDC_TOKEN_NOT_YET_VALID`. This is a belt-and-braces check: GitHub
34
+ Pages remains the authoritative relying party for token staleness (this
35
+ module's own trust-boundary documentation is unchanged), but failing here
36
+ first costs nothing and produces a far clearer diagnostic than a Pages-side
37
+ rejection.
38
+ - **PUB-M5:** `computeArtifactDigest` (marker-coordinate exclusion aside) now
39
+ delegates to `@rathnasgala2/adapter-protocol`'s implementation of the same
40
+ name instead of restating the `GALA-ARTIFACT-V2 ` formula locally.
41
+ - **PUB-H6:** every refusal this package raises is now a typed
42
+ `PagesAdapterError` (`src/errors.js`, exported from the package root) carrying
43
+ a stable `code` property (e.g.
44
+ `error.code === 'PAGES_OIDC_SUBJECT_MISMATCH'`), instead of a bare `Error` a
45
+ caller had to parse `CODE: detail` out of. `.message` is unchanged, so this is
46
+ additive, not breaking.
47
+
48
+ ## [0.1.0] - 2026-09-22
49
+
11
50
  ### Changed
12
51
 
13
52
  - **PUBLISH-S4-6a — `ADAPTER_VERSION` is the installed package version.**
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -6,10 +6,10 @@ declares exactly the DEC-097 section 7 `github-pages` capability row.
6
6
 
7
7
  ## What it does
8
8
 
9
- 1. **stage** builds one deterministic gzip/POSIX.1-1988 ustar carrier from the
10
- frozen artifact plus the reserved public generation marker, and hands it to
11
- the caller-supplied Actions-artifact publisher. Nothing public changes:
12
- `staging: private` is literal.
9
+ 1. **stage** builds one deterministic uncompressed POSIX.1-1988 ustar carrier
10
+ from the frozen artifact plus the reserved public generation marker, and
11
+ hands it to the caller-supplied Actions-artifact publisher. Nothing public
12
+ changes: `staging: private` is literal.
13
13
  2. **activate** re-reads the served generation, checks the mandatory activation
14
14
  fence, re-derives the artifact digest from the carrier bytes that will
15
15
  actually be deployed, verifies the caller-supplied Pages OIDC token's
@@ -158,11 +158,12 @@ separately, so the deploy script can run it before `stage` uploads a carrier.
158
158
 
159
159
  ## The exact status vocabulary and poll schedule
160
160
 
161
- The eleven accepted statuses, their temporary/terminal partition (with
162
- `deployment_attempt_error` temporary, because GitHub retries it automatically)
163
- and the exact `5, 8, 12, 18, 27, 30`-then-`30` poll schedule live in
164
- `src/constants.js` and are asserted in `test/index.test.js`. An unknown,
165
- malformed or ambiguous status can never release the destination fence.
161
+ The twelve accepted statuses, their temporary/terminal partition (with
162
+ `deployment_queued` and `deployment_attempt_error` temporary; the latter because
163
+ GitHub retries it automatically) and the exact `5, 8, 12, 18, 27, 30`-then-`30`
164
+ poll schedule live in `src/constants.js` and are asserted in
165
+ `test/index.test.js`. An unknown, malformed or ambiguous status can never
166
+ release the destination fence.
166
167
 
167
168
  ## Destination shape
168
169
 
@@ -194,6 +195,20 @@ untars the carrier this adapter produced, and serves the result from a separate
194
195
  public origin. `test/carrier.test.js` holds the codec goldens. What none of that
195
196
  can prove is the live GitHub Pages deployment API itself; that is backlog W4-16.
196
197
 
198
+ ## Errors
199
+
200
+ Every refusal this package raises is a `PagesAdapterError` (`src/errors.js`,
201
+ exported from the package root), never a bare `Error`: it carries a stable,
202
+ machine-readable `code` property alongside the ordinary `Error` message, so a
203
+ caller can write `error.code === 'PAGES_OIDC_SUBJECT_MISMATCH'` instead of
204
+ parsing `.message`. `.message` is `${code}: ${detail}`, so a caller matching a
205
+ code inside the message still works. The code vocabulary is closed and stable:
206
+ `grep -rn "new PagesAdapterError(" src` lists every code this package can raise,
207
+ grouped by the module that raises it (OIDC verification, the REST catalog, the
208
+ request catalog, carrier/capability construction, recovery). A new code is an
209
+ additive change; renaming or removing one is breaking and belongs in
210
+ `CHANGELOG.md`.
211
+
197
212
  ## Commands
198
213
 
199
214
  ```sh
package/package.json CHANGED
@@ -1,39 +1,59 @@
1
1
  {
2
2
  "name": "@rathnasgala2/adapter-github-pages",
3
- "version": "0.1.0",
4
- "description": "Managed GitHub Pages deployment adapter: deterministic gzip/ustar Pages carrier, raw Pages deployment REST catalog, bounded status polling and credential-free public verification.",
3
+ "version": "0.1.1",
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",
7
+ "sideEffects": false,
7
8
  "engines": {
8
- "node": "24.18.0",
9
- "npm": "11.16.0"
9
+ "node": ">=24.0.0"
10
10
  },
11
11
  "exports": {
12
12
  ".": {
13
- "types": "./src/index.d.ts",
13
+ "types": "./types/index.d.ts",
14
14
  "import": "./src/index.js"
15
15
  },
16
16
  "./package.json": "./package.json"
17
17
  },
18
- "types": "./src/index.d.ts",
18
+ "types": "./types/index.d.ts",
19
19
  "files": [
20
20
  "src/",
21
+ "types/",
21
22
  "README.md",
22
23
  "CHANGELOG.md",
23
24
  "LICENSE"
24
25
  ],
25
26
  "scripts": {
26
27
  "typecheck": "tsc -p tsconfig.json",
27
- "test": "node --test"
28
+ "test": "node --test",
29
+ "declarations:generate": "tsc -p tsconfig.declarations.json",
30
+ "declarations:check": "node ../../scripts/check-declarations.mjs adapter-github-pages"
28
31
  },
29
32
  "publishConfig": {
30
- "access": "public"
33
+ "access": "public",
34
+ "provenance": true
31
35
  },
32
36
  "dependencies": {
33
- "@rathnasgala2/adapter-protocol": "0.2.0",
34
- "@rathnasgala2/schemas": "2.11.0"
37
+ "@rathnasgala2/adapter-protocol": "^0.2.1",
38
+ "@rathnasgala2/schemas": "3.8.0"
35
39
  },
36
40
  "devDependencies": {
37
- "@rathnasgala2/adapter-conformance-kit": "0.1.0"
38
- }
41
+ "@rathnasgala2/adapter-conformance-kit": "0.1.1"
42
+ },
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/rathnasgala2/publish.git",
46
+ "directory": "packages/adapter-github-pages"
47
+ },
48
+ "homepage": "https://github.com/rathnasgala2/publish/tree/main/packages/adapter-github-pages#readme",
49
+ "bugs": {
50
+ "url": "https://github.com/rathnasgala2/publish/issues"
51
+ },
52
+ "keywords": [
53
+ "gala",
54
+ "galascribe",
55
+ "publish",
56
+ "adapter",
57
+ "github-pages"
58
+ ]
39
59
  }
@@ -15,7 +15,11 @@
15
15
  * @module
16
16
  */
17
17
 
18
- import { domainDigest, sha256Hex } from '@rathnasgala2/adapter-protocol';
18
+ import {
19
+ computeArtifactDigest as computeArtifactDigestFromFiles,
20
+ domainDigest,
21
+ sha256Hex,
22
+ } from '@rathnasgala2/adapter-protocol';
19
23
 
20
24
  import { DOMAIN_ARTIFACT, GENERATION_MARKER_PATH } from './constants.js';
21
25
 
@@ -66,13 +70,16 @@ export function digestEntries(entries) {
66
70
  * composition root, or a conformance fixture) can pass `stage` a truthful
67
71
  * `artifactDigest` without restating the projection.
68
72
  *
73
+ * PUB-M5: excluding the marker is this package's own contribution; the
74
+ * digest formula itself delegates to `@rathnasgala2/adapter-protocol`'s
75
+ * `computeArtifactDigest`, the single implementation every S2 destination
76
+ * adapter verifies against.
77
+ *
69
78
  * @param {readonly Readonly<{path: string, bytes: Buffer}>[]} files the file set
70
79
  * @returns {string} the artifact digest
71
80
  */
72
81
  export function computeArtifactDigest(files) {
73
- return digestEntries(
74
- files
75
- .filter((file) => file.path !== GENERATION_MARKER_PATH)
76
- .map((file) => projectEntry(file.path, file.bytes)),
82
+ return computeArtifactDigestFromFiles(
83
+ files.filter((file) => file.path !== GENERATION_MARKER_PATH),
77
84
  );
78
85
  }
package/src/capability.js CHANGED
@@ -15,6 +15,7 @@
15
15
  * @module
16
16
  */
17
17
 
18
+ import { PagesAdapterError } from './errors.js';
18
19
  import {
19
20
  ROLLBACK,
20
21
  assertValidCapabilityDeclaration,
@@ -48,12 +49,15 @@ import {
48
49
  * (2.8.1). The inventory is typed as an open record, so the profile is
49
50
  * required here once, by name, and its absence is a refusal rather than an
50
51
  * `undefined` digest.
52
+ *
53
+ * @type {NonNullable<(typeof ACTIVE_DIGEST_PROFILES)['providerCallClassBinding']>}
51
54
  */
52
55
  export const CALL_CLASS_BINDING_PROFILE = (() => {
53
56
  const profile = ACTIVE_DIGEST_PROFILES.providerCallClassBinding;
54
57
  if (profile === undefined) {
55
- throw new Error(
56
- 'PAGES_DIGEST_PROFILE_MISSING: @rathnasgala2/schemas/digest-profiles exports no providerCallClassBinding profile',
58
+ throw new PagesAdapterError(
59
+ 'PAGES_DIGEST_PROFILE_MISSING',
60
+ '@rathnasgala2/schemas/digest-profiles exports no providerCallClassBinding profile',
57
61
  );
58
62
  }
59
63
  return profile;
@@ -61,7 +65,8 @@ export const CALL_CLASS_BINDING_PROFILE = (() => {
61
65
 
62
66
  const ROW_OR_UNDEFINED = getCapabilityRow('github-pages');
63
67
  if (ROW_OR_UNDEFINED === undefined) {
64
- throw new Error(
68
+ throw new PagesAdapterError(
69
+ 'PAGES_CAPABILITY_ROW_MISSING',
65
70
  'adapter-protocol does not declare a github-pages capability row',
66
71
  );
67
72
  }
package/src/carrier.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
- * The deterministic Pages carrier codec (slice brief section 2.3: "its
3
- * deterministic one-member gzip/POSIX.1-1988 ustar bytes"). The carrier is
2
+ * The deterministic Pages carrier codec (slice brief section 2.3, as
3
+ * amended by a measurement: the bytes are an UNCOMPRESSED POSIX.1-1988 ustar
4
+ * tar). The carrier is
4
5
  * the *only* thing this adapter ever hands the provider, and it is
5
6
  * byte-deterministic for a given file set: identical inputs always produce
6
7
  * identical carrier bytes, so a lost create response can be recovered
@@ -8,19 +9,36 @@
8
9
  *
9
10
  * Determinism comes from fixing every field a tar writer would normally
10
11
  * take from the ambient environment: modification time `0`, owner/group id
11
- * `0`, empty owner/group names, a fixed file mode, no PAX or GNU extension
12
- * records, entries emitted in ascending UTF-8 path order, and a gzip member
13
- * written with a zeroed MTIME/OS byte.
12
+ * `0`, owner/group names fixed to `root`, a fixed file mode, no PAX or GNU
13
+ * extension records, and entries emitted in one deterministic order (below).
14
+ *
15
+ * Entry order: every entry, directory or file, is sorted by its full path
16
+ * string (directories carry their trailing `/`) in ascending code-unit order,
17
+ * so a directory entry always precedes everything inside it. The order is
18
+ * independent of the input order.
19
+ *
20
+ * Measured on GitHub Pages (actions/deploy-pages as oracle, same site files):
21
+ * a tar holding only file entries with EMPTY uname/gname is refused
22
+ * ("Deployment failed"); the same files with a directory entry (typeflag `5`,
23
+ * mode 0755) for every parent directory AND uname/gname `root` deploy. Which
24
+ * of the two matters is not yet separated, so both are emitted; both are
25
+ * harmless to an extractor.
26
+ *
27
+ * Measured on GitHub (actions/deploy-pages as oracle): Pages processes a
28
+ * deployment only when the artifact is a standard Actions artifact (the zip
29
+ * wrapper upload-artifact adds by default) whose single member is an
30
+ * uncompressed tar of the site. A gzip-compressed tar fails ("Deployment
31
+ * failed"), so this codec never compresses.
14
32
  *
15
33
  * @module
16
34
  */
17
35
 
18
- import { gunzipSync, gzipSync } from 'node:zlib';
19
-
20
36
  const BLOCK_BYTES = 512;
21
37
  const NAME_FIELD_BYTES = 100;
22
38
  const PREFIX_FIELD_BYTES = 155;
23
39
  const FILE_MODE = '0000644';
40
+ const DIRECTORY_MODE = '0000755';
41
+ const OWNER_NAME = 'root';
24
42
  const USTAR_MAGIC = 'ustar\0' + '00';
25
43
 
26
44
  /**
@@ -81,9 +99,9 @@ export function splitUstarPath(entryPath) {
81
99
  *
82
100
  * The carrier is extracted by the provider, not by this process, so the
83
101
  * only place an escaping member can be stopped is here, at the point it is
84
- * written. Only regular-file entries are ever emitted (typeflag `0`): this
85
- * codec has no link, device or directory entry, so a symlink/hardlink
86
- * member cannot exist to be followed.
102
+ * written. Only regular-file (typeflag `0`) and directory (typeflag `5`)
103
+ * entries are ever emitted: this codec has no link or device entry, so a
104
+ * symlink/hardlink member cannot exist to be followed.
87
105
  *
88
106
  * @param {string} entryPath the artifact-relative POSIX path
89
107
  * @returns {string} the accepted path
@@ -107,25 +125,30 @@ export function requireContainedPath(entryPath) {
107
125
  }
108
126
 
109
127
  /**
110
- * Build one 512-byte ustar header block for a regular file.
128
+ * Build one 512-byte ustar header block for a regular file or a directory.
111
129
  *
112
- * @param {string} entryPath the artifact-relative POSIX path
113
- * @param {number} byteLength the member's byte length
130
+ * @param {string} entryPath the artifact-relative POSIX path; a directory
131
+ * carries a trailing `/`
132
+ * @param {number} byteLength the member's byte length (`0` for a directory)
133
+ * @param {boolean} isDirectory whether this is a directory entry
114
134
  * @returns {Buffer} the header block, with its checksum applied
115
135
  */
116
- function buildHeaderBlock(entryPath, byteLength) {
136
+ function buildHeaderBlock(entryPath, byteLength, isDirectory) {
117
137
  const block = Buffer.alloc(BLOCK_BYTES);
118
- const { name, prefix } = splitUstarPath(requireContainedPath(entryPath));
138
+ requireContainedPath(isDirectory ? entryPath.slice(0, -1) : entryPath);
139
+ const { name, prefix } = splitUstarPath(entryPath);
119
140
 
120
141
  writeField(block, 0, NAME_FIELD_BYTES, name);
121
- writeField(block, 100, 8, FILE_MODE);
142
+ writeField(block, 100, 8, isDirectory ? DIRECTORY_MODE : FILE_MODE);
122
143
  writeField(block, 108, 8, '0000000');
123
144
  writeField(block, 116, 8, '0000000');
124
145
  writeField(block, 124, 12, byteLength.toString(8).padStart(11, '0'));
125
146
  writeField(block, 136, 12, '00000000000');
126
147
  block.fill(0x20, 148, 156);
127
- block.write('0', 156, 1, 'ascii');
148
+ block.write(isDirectory ? '5' : '0', 156, 1, 'ascii');
128
149
  writeField(block, 257, 8, USTAR_MAGIC);
150
+ writeField(block, 265, 32, OWNER_NAME);
151
+ writeField(block, 297, 32, OWNER_NAME);
129
152
  writeField(block, 345, PREFIX_FIELD_BYTES, prefix);
130
153
 
131
154
  let checksum = 0;
@@ -137,21 +160,39 @@ function buildHeaderBlock(entryPath, byteLength) {
137
160
  }
138
161
 
139
162
  /**
140
- * Encode a complete file set as deterministic one-member gzip/ustar carrier
141
- * bytes.
163
+ * Encode a complete file set as deterministic uncompressed ustar
164
+ * carrier bytes (never gzip; see the module comment).
142
165
  *
143
166
  * @param {readonly CarrierFile[]} files the complete artifact file set,
144
167
  * including the reserved public generation marker
145
168
  * @returns {Buffer} the carrier bytes
146
169
  */
147
170
  export function encodeCarrier(files) {
148
- const ordered = [...files].sort((left, right) =>
171
+ /** @type {Set<string>} */
172
+ const directories = new Set();
173
+ for (const file of files) {
174
+ const segments = file.path.split('/');
175
+ for (let depth = 1; depth < segments.length; depth += 1) {
176
+ directories.add(`${segments.slice(0, depth).join('/')}/`);
177
+ }
178
+ }
179
+ /** @type {{path: string, bytes: Buffer, isDirectory: boolean}[]} */
180
+ const ordered = [
181
+ ...[...directories].map((path) => ({
182
+ path,
183
+ bytes: Buffer.alloc(0),
184
+ isDirectory: true,
185
+ })),
186
+ ...files.map((file) => ({ ...file, isDirectory: false })),
187
+ ].sort((left, right) =>
149
188
  left.path < right.path ? -1 : left.path > right.path ? 1 : 0,
150
189
  );
151
190
  /** @type {Buffer[]} */
152
191
  const blocks = [];
153
192
  for (const file of ordered) {
154
- blocks.push(buildHeaderBlock(file.path, file.bytes.byteLength));
193
+ blocks.push(
194
+ buildHeaderBlock(file.path, file.bytes.byteLength, file.isDirectory),
195
+ );
155
196
  blocks.push(file.bytes);
156
197
  const remainder = file.bytes.byteLength % BLOCK_BYTES;
157
198
  if (remainder !== 0) {
@@ -160,12 +201,7 @@ export function encodeCarrier(files) {
160
201
  }
161
202
  blocks.push(Buffer.alloc(BLOCK_BYTES * 2));
162
203
 
163
- const gzipped = gzipSync(Buffer.concat(blocks), { level: 9 });
164
- // Zero the gzip header's MTIME (bytes 4..7) and OS (byte 9) fields, the
165
- // only two places zlib is permitted to record ambient facts.
166
- gzipped.writeUInt32LE(0, 4);
167
- gzipped.writeUInt8(0xff, 9);
168
- return gzipped;
204
+ return Buffer.concat(blocks);
169
205
  }
170
206
 
171
207
  /**
@@ -175,10 +211,16 @@ export function encodeCarrier(files) {
175
211
  * codec golden test — can prove the round trip is lossless.
176
212
  *
177
213
  * @param {Buffer} carrier the carrier bytes
178
- * @returns {CarrierFile[]} the decoded file set, in carrier order
214
+ * @returns {CarrierFile[]} the decoded file set, in carrier order; directory
215
+ * entries (typeflag `5`) are skipped
179
216
  */
180
217
  export function decodeCarrier(carrier) {
181
- const tar = gunzipSync(carrier);
218
+ if (carrier.byteLength >= 2 && carrier[0] === 0x1f && carrier[1] === 0x8b) {
219
+ throw new RangeError(
220
+ 'PAGES_CARRIER_GZIP_REFUSED: the Pages carrier must be an uncompressed ustar tar; GitHub Pages fails a gzip-compressed artifact',
221
+ );
222
+ }
223
+ const tar = carrier;
182
224
  /** @type {CarrierFile[]} */
183
225
  const files = [];
184
226
  let offset = 0;
@@ -194,10 +236,12 @@ export function decodeCarrier(carrier) {
194
236
  8,
195
237
  );
196
238
  offset += BLOCK_BYTES;
197
- files.push({
198
- path: prefix === '' ? name : `${prefix}/${name}`,
199
- bytes: Buffer.from(tar.subarray(offset, offset + size)),
200
- });
239
+ if (String.fromCharCode(Number(header[156])) !== '5') {
240
+ files.push({
241
+ path: prefix === '' ? name : `${prefix}/${name}`,
242
+ bytes: Buffer.from(tar.subarray(offset, offset + size)),
243
+ });
244
+ }
201
245
  offset += Math.ceil(size / BLOCK_BYTES) * BLOCK_BYTES;
202
246
  }
203
247
  return files;