@patronage/factory-ci 1.0.0-alpha.4 → 1.0.0-alpha.40
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/README.md +712 -10
- package/dist/.build-fingerprint.json +3 -0
- package/dist/alchemy/index.d.ts +1174 -0
- package/dist/alchemy/index.js +2142 -0
- package/dist/bundle-alchemy-entry-CT5hCphA.js +112 -0
- package/dist/execute-alchemy-entry-B397GSk5.d.ts +134 -0
- package/dist/execute-alchemy-entry-CZ7Knz4q.js +160 -0
- package/dist/index.d.ts +1205 -87
- package/dist/index.js +2752 -317
- package/package.json +28 -10
- package/src/actions.ts +13 -0
- package/src/alchemy/child-diagnostics.ts +148 -0
- package/src/alchemy/credential-preflight.ts +428 -0
- package/src/alchemy/destroy-postcondition.ts +103 -0
- package/src/alchemy/evaluate-stack.ts +153 -0
- package/src/alchemy/first-deploy-authorization.ts +194 -0
- package/src/alchemy/index.ts +144 -0
- package/src/alchemy/lifecycle-failure.ts +174 -0
- package/src/alchemy/lifecycle.ts +1330 -0
- package/src/alchemy/local-emulation.ts +89 -0
- package/src/alchemy/plan-effects.ts +510 -0
- package/src/alchemy/retained-identity.ts +248 -0
- package/src/alchemy/secret-name-policy.ts +96 -0
- package/src/alchemy/stage-policy.ts +269 -0
- package/src/alchemy/state-tree.ts +168 -0
- package/src/alchemy/url-implies-auth.ts +264 -0
- package/src/alchemy-baseline.ts +75 -0
- package/src/bundle-alchemy-entry.ts +5 -0
- package/src/candidate-impact-workflow.ts +110 -0
- package/src/candidate-lifecycle.ts +29 -0
- package/src/cursor-oidc.ts +33 -0
- package/src/execute-alchemy-entry.ts +128 -8
- package/src/factory-workflow.ts +83 -40
- package/src/github-app-token.ts +92 -18
- package/src/github-transport.ts +186 -0
- package/src/impact-demand-condition.ts +67 -0
- package/src/index.ts +174 -0
- package/src/lifecycle-contract-lane.ts +113 -0
- package/src/merge-freeze-job.ts +253 -0
- package/src/pinned-action.ts +30 -0
- package/src/pr-status-hud-workflow.ts +96 -0
- package/src/preview-cleanup-topology.ts +115 -0
- package/src/preview-proof-inventory.ts +1092 -0
- package/src/preview-proof-lifecycle.ts +328 -0
- package/src/preview-receipt-workflow.ts +83 -0
- package/src/production-impact-workflow.ts +181 -0
- package/src/proof-reuse-gate.ts +223 -48
- package/src/proof-reuse-presentation.ts +131 -0
- package/src/push-identity-workflow.ts +463 -0
- package/src/runnable-cli.ts +27 -0
- package/src/verify-runner-policy.ts +290 -0
- package/src/vitest-profile-reader.test.ts +208 -0
- package/src/vitest-profile-reader.ts +225 -0
- package/src/vitest-profile.ts +631 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import { UPLOAD_ARTIFACT } from "./actions.ts";
|
|
2
|
+
import type { PinnedAction } from "./actions.ts";
|
|
3
|
+
import type { WorkflowStep } from "./factory-workflow.ts";
|
|
4
|
+
import { assertPinnedAction } from "./pinned-action.ts";
|
|
5
|
+
|
|
6
|
+
/** `owner/repo` slice of the catalog's `UPLOAD_ARTIFACT` pin, derived rather
|
|
7
|
+
* than repeated as a literal, so a repository rename here cannot drift from
|
|
8
|
+
* the pin it validates against. */
|
|
9
|
+
const UPLOAD_ARTIFACT_REPOSITORY = UPLOAD_ARTIFACT.uses.slice(
|
|
10
|
+
0,
|
|
11
|
+
UPLOAD_ARTIFACT.uses.indexOf("@")
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const FACTORY_PUSH_IDENTITY_SCHEMA_VERSION = 1;
|
|
15
|
+
/**
|
|
16
|
+
* The artifact prefix and the five step IDs are module-private. Alpha.13
|
|
17
|
+
* removed them from the public surface (#719). A caller reads a step ID from
|
|
18
|
+
* the builder's returned `steps` (`step.id`) or from `artifactName`.
|
|
19
|
+
*/
|
|
20
|
+
const FACTORY_PUSH_IDENTITY_ARTIFACT_PREFIX = "factory-push-identity";
|
|
21
|
+
const FACTORY_PUSH_IDENTITY_RECORD_STEP_ID = "factory_push_identity_record";
|
|
22
|
+
const FACTORY_PUSH_IDENTITY_LOOKUP_STEP_ID = "factory_push_identity_lookup";
|
|
23
|
+
const FACTORY_PUSH_IDENTITY_DOWNLOAD_STEP_ID = "factory_push_identity_download";
|
|
24
|
+
const FACTORY_PUSH_IDENTITY_CHECKOUT_STEP_ID = "factory_push_identity_checkout";
|
|
25
|
+
const FACTORY_PUSH_IDENTITY_VALIDATE_STEP_ID = "factory_push_identity";
|
|
26
|
+
|
|
27
|
+
/** Versioned document uploaded by a push-triggered verification run. */
|
|
28
|
+
export interface FactoryPushIdentityEnvelope {
|
|
29
|
+
readonly after: string;
|
|
30
|
+
readonly before: string;
|
|
31
|
+
readonly repository: string;
|
|
32
|
+
readonly runId: string;
|
|
33
|
+
readonly schemaVersion: typeof FACTORY_PUSH_IDENTITY_SCHEMA_VERSION;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type FactoryPushIdentityDisposition = "refused" | "usable";
|
|
37
|
+
|
|
38
|
+
const ARTIFACT_MAX_BYTES = 16_384;
|
|
39
|
+
const ENVELOPE_MAX_BYTES = 4096;
|
|
40
|
+
|
|
41
|
+
const expression = (value: string): string => `\${{ ${value} }}`;
|
|
42
|
+
const artifactName = (runId: string): string =>
|
|
43
|
+
`${FACTORY_PUSH_IDENTITY_ARTIFACT_PREFIX}-${runId}`;
|
|
44
|
+
|
|
45
|
+
const producerScript = String.raw`identity="$RUNNER_TEMP/factory-push-identity.json"
|
|
46
|
+
produced=false
|
|
47
|
+
reason='producer_error'
|
|
48
|
+
before=''
|
|
49
|
+
event_after=''
|
|
50
|
+
rm -f "$identity"
|
|
51
|
+
|
|
52
|
+
is_hex_sha() {
|
|
53
|
+
[ "$(printf '%s' "$1" | wc -c | tr -d '[:space:]')" -eq 40 ] &&
|
|
54
|
+
case "$1" in *[!0-9a-f]*) false;; *) true;; esac
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
is_nonzero_sha() {
|
|
58
|
+
is_hex_sha "$1" && [ "$1" != '0000000000000000000000000000000000000000' ]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if [ "$GITHUB_EVENT_NAME" != 'push' ]; then
|
|
62
|
+
reason='not_push_event'
|
|
63
|
+
elif ! printf '%s' "$GITHUB_REPOSITORY" | grep -Eq '^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$'; then
|
|
64
|
+
reason='repository_invalid'
|
|
65
|
+
elif ! printf '%s' "$GITHUB_RUN_ID" | grep -Eq '^[1-9][0-9]*$'; then
|
|
66
|
+
reason='run_id_invalid'
|
|
67
|
+
elif ! before="$(jq -er '.before | select(type == "string")' "$GITHUB_EVENT_PATH" 2>/dev/null)"; then
|
|
68
|
+
reason='event_before_missing'
|
|
69
|
+
elif ! event_after="$(jq -er '.after | select(type == "string")' "$GITHUB_EVENT_PATH" 2>/dev/null)"; then
|
|
70
|
+
reason='event_after_missing'
|
|
71
|
+
elif ! is_hex_sha "$before"; then
|
|
72
|
+
reason='event_before_invalid'
|
|
73
|
+
elif ! is_nonzero_sha "$event_after" || ! is_nonzero_sha "$GITHUB_SHA"; then
|
|
74
|
+
reason='event_after_invalid'
|
|
75
|
+
elif [ "$event_after" != "$GITHUB_SHA" ]; then
|
|
76
|
+
reason='event_after_mismatch'
|
|
77
|
+
elif jq -cn \
|
|
78
|
+
--argjson schemaVersion '${FACTORY_PUSH_IDENTITY_SCHEMA_VERSION}' \
|
|
79
|
+
--arg repository "$GITHUB_REPOSITORY" \
|
|
80
|
+
--arg runId "$GITHUB_RUN_ID" \
|
|
81
|
+
--arg before "$before" \
|
|
82
|
+
--arg after "$event_after" \
|
|
83
|
+
'{schemaVersion: $schemaVersion, repository: $repository, runId: $runId, before: $before, after: $after}' > "$identity"; then
|
|
84
|
+
produced=true
|
|
85
|
+
reason='produced'
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
printf 'produced=%s\nreason=%s\n' "$produced" "$reason" >> "$GITHUB_OUTPUT"
|
|
89
|
+
{
|
|
90
|
+
printf '## Exact push identity producer\n\n'
|
|
91
|
+
printf -- '- Status: %s\n' "$reason"
|
|
92
|
+
printf -- '- Repository/run: %s / %s\n' "$GITHUB_REPOSITORY" "$GITHUB_RUN_ID"
|
|
93
|
+
if [ "$produced" = true ]; then
|
|
94
|
+
printf -- '- Bound push: %s → %s\n' "$before" "$event_after"
|
|
95
|
+
else
|
|
96
|
+
printf -- '- Identity transport was not produced; downstream classification will refuse withdrawal.\n'
|
|
97
|
+
fi
|
|
98
|
+
} >> "$GITHUB_STEP_SUMMARY"`;
|
|
99
|
+
|
|
100
|
+
const lookupScript = String.raw`status='refused'
|
|
101
|
+
reason='artifact_lookup_failed'
|
|
102
|
+
artifact_id=''
|
|
103
|
+
matches="$RUNNER_TEMP/factory-push-identity-artifacts.tsv"
|
|
104
|
+
artifact_name='${FACTORY_PUSH_IDENTITY_ARTIFACT_PREFIX}-'"$EXPECTED_RUN_ID"
|
|
105
|
+
rm -f "$matches"
|
|
106
|
+
|
|
107
|
+
is_sha() {
|
|
108
|
+
[ "$(printf '%s' "$1" | wc -c | tr -d '[:space:]')" -eq 40 ] &&
|
|
109
|
+
[ "$1" != '0000000000000000000000000000000000000000' ] &&
|
|
110
|
+
case "$1" in *[!0-9a-f]*) false;; *) true;; esac
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if [ "$EXPECTED_EVENT_NAME" != 'workflow_run' ]; then
|
|
114
|
+
reason='event_not_workflow_run'
|
|
115
|
+
elif [ "$EXPECTED_WORKFLOW_EVENT" != 'push' ]; then
|
|
116
|
+
reason='triggering_workflow_not_push'
|
|
117
|
+
elif [ "$EXPECTED_CONCLUSION" != 'success' ]; then
|
|
118
|
+
reason='triggering_workflow_not_successful'
|
|
119
|
+
elif [ "$EXPECTED_WORKFLOW_REPOSITORY" != "$EXPECTED_REPOSITORY" ]; then
|
|
120
|
+
reason='triggering_repository_mismatch'
|
|
121
|
+
elif ! printf '%s' "$EXPECTED_REPOSITORY" | grep -Eq '^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$'; then
|
|
122
|
+
reason='triggering_repository_invalid'
|
|
123
|
+
elif ! printf '%s' "$EXPECTED_RUN_ID" | grep -Eq '^[1-9][0-9]*$'; then
|
|
124
|
+
reason='triggering_run_id_invalid'
|
|
125
|
+
elif ! is_sha "$EXPECTED_AFTER_SHA"; then
|
|
126
|
+
reason='triggering_head_sha_invalid'
|
|
127
|
+
elif ! gh api --paginate \
|
|
128
|
+
"repos/$EXPECTED_REPOSITORY/actions/runs/$EXPECTED_RUN_ID/artifacts?per_page=100" \
|
|
129
|
+
--jq ".artifacts[] | select(.name == \"$artifact_name\") | [.id, .size_in_bytes, .expired] | @tsv" \
|
|
130
|
+
> "$matches" 2>/dev/null; then
|
|
131
|
+
reason='artifact_lookup_failed'
|
|
132
|
+
else
|
|
133
|
+
count="$(awk 'END { print NR + 0 }' "$matches")"
|
|
134
|
+
if [ "$count" -eq 0 ]; then
|
|
135
|
+
reason='artifact_missing'
|
|
136
|
+
elif [ "$count" -ne 1 ]; then
|
|
137
|
+
reason='artifact_duplicate'
|
|
138
|
+
else
|
|
139
|
+
IFS="$(printf '\t')" read -r artifact_id artifact_size artifact_expired < "$matches" || true
|
|
140
|
+
if ! printf '%s' "$artifact_id" | grep -Eq '^[1-9][0-9]*$' ||
|
|
141
|
+
! printf '%s' "$artifact_size" | grep -Eq '^[0-9]+$' ||
|
|
142
|
+
{ [ "$artifact_expired" != 'false' ] && [ "$artifact_expired" != 'true' ]; }; then
|
|
143
|
+
reason='artifact_metadata_invalid'
|
|
144
|
+
artifact_id=''
|
|
145
|
+
elif [ "$artifact_expired" = 'true' ]; then
|
|
146
|
+
reason='artifact_expired'
|
|
147
|
+
artifact_id=''
|
|
148
|
+
elif [ "$artifact_size" -gt '${ARTIFACT_MAX_BYTES}' ]; then
|
|
149
|
+
reason='artifact_oversized'
|
|
150
|
+
artifact_id=''
|
|
151
|
+
else
|
|
152
|
+
status='available'
|
|
153
|
+
reason='artifact_available'
|
|
154
|
+
fi
|
|
155
|
+
fi
|
|
156
|
+
fi
|
|
157
|
+
|
|
158
|
+
printf 'status=%s\nreason=%s\nartifact_id=%s\n' "$status" "$reason" "$artifact_id" >> "$GITHUB_OUTPUT"`;
|
|
159
|
+
|
|
160
|
+
const validationScript = String.raw`disposition='refused'
|
|
161
|
+
reason='validation_error'
|
|
162
|
+
before=''
|
|
163
|
+
after=''
|
|
164
|
+
identity_directory="$RUNNER_TEMP/factory-push-identity"
|
|
165
|
+
identity="$identity_directory/factory-push-identity.json"
|
|
166
|
+
artifact_name='${FACTORY_PUSH_IDENTITY_ARTIFACT_PREFIX}-'"$EXPECTED_RUN_ID"
|
|
167
|
+
|
|
168
|
+
is_sha() {
|
|
169
|
+
[ "$(printf '%s' "$1" | wc -c | tr -d '[:space:]')" -eq 40 ] &&
|
|
170
|
+
[ "$1" != '0000000000000000000000000000000000000000' ] &&
|
|
171
|
+
case "$1" in *[!0-9a-f]*) false;; *) true;; esac
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if [ "$EXPECTED_EVENT_NAME" != 'workflow_run' ]; then
|
|
175
|
+
reason='event_not_workflow_run'
|
|
176
|
+
elif [ "$EXPECTED_WORKFLOW_EVENT" != 'push' ]; then
|
|
177
|
+
reason='triggering_workflow_not_push'
|
|
178
|
+
elif [ "$EXPECTED_CONCLUSION" != 'success' ]; then
|
|
179
|
+
reason='triggering_workflow_not_successful'
|
|
180
|
+
elif [ "$EXPECTED_WORKFLOW_REPOSITORY" != "$EXPECTED_REPOSITORY" ]; then
|
|
181
|
+
reason='triggering_repository_mismatch'
|
|
182
|
+
elif ! printf '%s' "$EXPECTED_REPOSITORY" | grep -Eq '^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$'; then
|
|
183
|
+
reason='triggering_repository_invalid'
|
|
184
|
+
elif ! printf '%s' "$EXPECTED_RUN_ID" | grep -Eq '^[1-9][0-9]*$'; then
|
|
185
|
+
reason='triggering_run_id_invalid'
|
|
186
|
+
elif ! is_sha "$EXPECTED_AFTER_SHA"; then
|
|
187
|
+
reason='triggering_head_sha_invalid'
|
|
188
|
+
elif [ "$LOOKUP_STATUS" != 'available' ]; then
|
|
189
|
+
if [ -n "$LOOKUP_REASON" ]; then
|
|
190
|
+
reason="$LOOKUP_REASON"
|
|
191
|
+
else
|
|
192
|
+
reason='artifact_lookup_failed'
|
|
193
|
+
fi
|
|
194
|
+
elif [ "$DOWNLOAD_OUTCOME" != 'success' ]; then
|
|
195
|
+
reason='artifact_download_failed'
|
|
196
|
+
elif [ "$CHECKOUT_OUTCOME" != 'success' ]; then
|
|
197
|
+
reason='checkout_failed'
|
|
198
|
+
elif [ ! -d "$identity_directory" ]; then
|
|
199
|
+
reason='artifact_contents_missing'
|
|
200
|
+
else
|
|
201
|
+
entry_count="$(find "$identity_directory" -mindepth 1 -maxdepth 1 -print 2>/dev/null | awk 'END { print NR + 0 }')"
|
|
202
|
+
if [ "$entry_count" -ne 1 ] || [ ! -f "$identity" ] || [ -L "$identity" ]; then
|
|
203
|
+
reason='artifact_contents_invalid'
|
|
204
|
+
else
|
|
205
|
+
envelope_size="$(wc -c < "$identity" | tr -d '[:space:]')"
|
|
206
|
+
if ! printf '%s' "$envelope_size" | grep -Eq '^[0-9]+$'; then
|
|
207
|
+
reason='envelope_size_unreadable'
|
|
208
|
+
elif [ "$envelope_size" -gt '${ENVELOPE_MAX_BYTES}' ]; then
|
|
209
|
+
reason='envelope_oversized'
|
|
210
|
+
elif ! jq -e --argjson schemaVersion '${FACTORY_PUSH_IDENTITY_SCHEMA_VERSION}' '
|
|
211
|
+
type == "object" and
|
|
212
|
+
keys == ["after", "before", "repository", "runId", "schemaVersion"] and
|
|
213
|
+
.schemaVersion == $schemaVersion and
|
|
214
|
+
(.repository | type == "string") and
|
|
215
|
+
(.runId | type == "string" and test("^[1-9][0-9]*$")) and
|
|
216
|
+
(.before | type == "string" and test("^[0-9a-f]{40}$") and (test("^0{40}$") | not)) and
|
|
217
|
+
(.after | type == "string" and test("^[0-9a-f]{40}$") and (test("^0{40}$") | not))
|
|
218
|
+
' "$identity" >/dev/null 2>&1; then
|
|
219
|
+
reason='envelope_malformed'
|
|
220
|
+
else
|
|
221
|
+
repository="$(jq -r '.repository' "$identity")"
|
|
222
|
+
run_id="$(jq -r '.runId' "$identity")"
|
|
223
|
+
before="$(jq -r '.before' "$identity")"
|
|
224
|
+
after="$(jq -r '.after' "$identity")"
|
|
225
|
+
|
|
226
|
+
if [ "$repository" != "$EXPECTED_REPOSITORY" ]; then
|
|
227
|
+
reason='envelope_repository_mismatch'
|
|
228
|
+
elif [ "$run_id" != "$EXPECTED_RUN_ID" ]; then
|
|
229
|
+
reason='envelope_run_id_mismatch'
|
|
230
|
+
elif [ "$after" != "$EXPECTED_AFTER_SHA" ]; then
|
|
231
|
+
reason='envelope_after_mismatch'
|
|
232
|
+
elif ! actual_head="$(git rev-parse --verify HEAD 2>/dev/null)" || [ "$actual_head" != "$EXPECTED_AFTER_SHA" ]; then
|
|
233
|
+
reason='checkout_head_mismatch'
|
|
234
|
+
elif ! git cat-file -e "$before^{commit}" 2>/dev/null || ! git cat-file -e "$after^{commit}" 2>/dev/null; then
|
|
235
|
+
reason='envelope_commit_unreachable'
|
|
236
|
+
elif [ "$before" = "$after" ]; then
|
|
237
|
+
reason='envelope_commits_contradictory'
|
|
238
|
+
elif ! git merge-base --is-ancestor "$before" "$after"; then
|
|
239
|
+
reason='before_not_ancestor'
|
|
240
|
+
else
|
|
241
|
+
disposition='usable'
|
|
242
|
+
reason='identity_bound'
|
|
243
|
+
fi
|
|
244
|
+
fi
|
|
245
|
+
fi
|
|
246
|
+
fi
|
|
247
|
+
|
|
248
|
+
if [ "$disposition" != 'usable' ]; then
|
|
249
|
+
before=''
|
|
250
|
+
after=''
|
|
251
|
+
fi
|
|
252
|
+
|
|
253
|
+
provenance="$(jq -cn \
|
|
254
|
+
--argjson schemaVersion '${FACTORY_PUSH_IDENTITY_SCHEMA_VERSION}' \
|
|
255
|
+
--arg disposition "$disposition" \
|
|
256
|
+
--arg reason "$reason" \
|
|
257
|
+
--arg repository "$EXPECTED_REPOSITORY" \
|
|
258
|
+
--arg runId "$EXPECTED_RUN_ID" \
|
|
259
|
+
--arg expectedAfter "$EXPECTED_AFTER_SHA" \
|
|
260
|
+
--arg artifactName "$artifact_name" \
|
|
261
|
+
--arg artifactId "$ARTIFACT_ID" \
|
|
262
|
+
--arg before "$before" \
|
|
263
|
+
--arg after "$after" \
|
|
264
|
+
'{schemaVersion: $schemaVersion, disposition: $disposition, reason: $reason, repository: $repository, runId: $runId, expectedAfter: $expectedAfter, artifactName: $artifactName, artifactId: (if $artifactId == "" then null else $artifactId end), before: (if $before == "" then null else $before end), after: (if $after == "" then null else $after end)}')"
|
|
265
|
+
|
|
266
|
+
printf 'disposition=%s\nreason=%s\nbefore=%s\nafter=%s\nprovenance=%s\n' \
|
|
267
|
+
"$disposition" "$reason" "$before" "$after" "$provenance" >> "$GITHUB_OUTPUT"
|
|
268
|
+
{
|
|
269
|
+
printf '## Exact push identity\n\n'
|
|
270
|
+
printf -- '- Disposition: %s\n' "$disposition"
|
|
271
|
+
printf -- '- Reason: %s\n' "$reason"
|
|
272
|
+
printf -- '- Repository/run: %s / %s\n' "$EXPECTED_REPOSITORY" "$EXPECTED_RUN_ID"
|
|
273
|
+
printf -- '- Expected verified head: %s\n' "$EXPECTED_AFTER_SHA"
|
|
274
|
+
if [ "$disposition" = 'usable' ]; then
|
|
275
|
+
printf -- '- Bound push: %s → %s\n' "$before" "$after"
|
|
276
|
+
else
|
|
277
|
+
printf -- '- Production impact classification refused; every consumer-owned production target remains demanded.\n'
|
|
278
|
+
fi
|
|
279
|
+
printf '\nFactory telemetry provenance: %s\n' "$provenance"
|
|
280
|
+
} >> "$GITHUB_STEP_SUMMARY"`;
|
|
281
|
+
|
|
282
|
+
export interface FactoryPushIdentityProducerOptions {
|
|
283
|
+
/**
|
|
284
|
+
* Explicit caller-owned upload-artifact pin from its workflow artifact.
|
|
285
|
+
* Pass factory-ci's `UPLOAD_ARTIFACT` catalog export (or another
|
|
286
|
+
* `actions/upload-artifact` pin); the caller wires the step, the catalog
|
|
287
|
+
* only names the pin.
|
|
288
|
+
*/
|
|
289
|
+
readonly uploadArtifact: PinnedAction;
|
|
290
|
+
/** Optional consumer trigger policy combined with the required push event. */
|
|
291
|
+
readonly if?: string;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export interface FactoryPushIdentityProducer {
|
|
295
|
+
readonly artifactName: string;
|
|
296
|
+
readonly steps: readonly WorkflowStep[];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Record and upload the exact push-event identity without changing the Verify
|
|
301
|
+
* result when transport is unavailable. Place these steps after verification.
|
|
302
|
+
*/
|
|
303
|
+
export const factoryPushIdentityProducer = (
|
|
304
|
+
options: FactoryPushIdentityProducerOptions
|
|
305
|
+
): FactoryPushIdentityProducer => {
|
|
306
|
+
assertPinnedAction(
|
|
307
|
+
"uploadArtifact",
|
|
308
|
+
options.uploadArtifact,
|
|
309
|
+
UPLOAD_ARTIFACT_REPOSITORY
|
|
310
|
+
);
|
|
311
|
+
const condition = options.if
|
|
312
|
+
? `github.event_name == 'push' && (${options.if})`
|
|
313
|
+
: "github.event_name == 'push'";
|
|
314
|
+
const name = artifactName(expression("github.run_id"));
|
|
315
|
+
return Object.freeze({
|
|
316
|
+
artifactName: name,
|
|
317
|
+
steps: Object.freeze([
|
|
318
|
+
{
|
|
319
|
+
continueOnError: true,
|
|
320
|
+
id: FACTORY_PUSH_IDENTITY_RECORD_STEP_ID,
|
|
321
|
+
if: condition,
|
|
322
|
+
name: "Record exact push identity",
|
|
323
|
+
run: producerScript,
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
continueOnError: true,
|
|
327
|
+
if: `${condition} && steps.${FACTORY_PUSH_IDENTITY_RECORD_STEP_ID}.outputs.produced == 'true'`,
|
|
328
|
+
name: "Upload exact push identity",
|
|
329
|
+
uses: options.uploadArtifact.uses,
|
|
330
|
+
with: {
|
|
331
|
+
"if-no-files-found": "error",
|
|
332
|
+
name,
|
|
333
|
+
path: `${expression("runner.temp")}/factory-push-identity.json`,
|
|
334
|
+
"retention-days": "7",
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
]),
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export interface FactoryPushIdentityConsumer {
|
|
342
|
+
/** Job outputs suitable for a caller-owned decision job and telemetry. */
|
|
343
|
+
readonly outputs: Readonly<
|
|
344
|
+
Record<"after" | "before" | "disposition" | "provenance" | "reason", string>
|
|
345
|
+
>;
|
|
346
|
+
readonly requiredPermissions: Readonly<{
|
|
347
|
+
actions: "read";
|
|
348
|
+
contents: "read";
|
|
349
|
+
}>;
|
|
350
|
+
readonly steps: readonly WorkflowStep[];
|
|
351
|
+
/** Run classification only when exact identity transport is usable. */
|
|
352
|
+
readonly usableIf: string;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface FactoryPushIdentityConsumerOptions {
|
|
356
|
+
/** Explicit caller-owned checkout pin from its action family. */
|
|
357
|
+
readonly checkout: PinnedAction;
|
|
358
|
+
/** Explicit caller-owned download-artifact pin from its workflow artifact. */
|
|
359
|
+
readonly downloadArtifact: PinnedAction;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Download and validate identity from exactly the triggering workflow run in
|
|
364
|
+
* the current repository. Every failure becomes a typed refusal; consumers
|
|
365
|
+
* retain deploy policy, credentials, commands, topology, and convergence.
|
|
366
|
+
*/
|
|
367
|
+
export const factoryPushIdentityConsumer = (
|
|
368
|
+
options: FactoryPushIdentityConsumerOptions
|
|
369
|
+
): FactoryPushIdentityConsumer => {
|
|
370
|
+
assertPinnedAction("checkout", options.checkout, "actions/checkout");
|
|
371
|
+
assertPinnedAction(
|
|
372
|
+
"downloadArtifact",
|
|
373
|
+
options.downloadArtifact,
|
|
374
|
+
"actions/download-artifact"
|
|
375
|
+
);
|
|
376
|
+
const currentRepository = expression("github.repository");
|
|
377
|
+
const triggeringRun = expression("github.event.workflow_run.id");
|
|
378
|
+
const triggeringHead = expression("github.event.workflow_run.head_sha");
|
|
379
|
+
const lookupOutput = (name: string): string =>
|
|
380
|
+
expression(`steps.${FACTORY_PUSH_IDENTITY_LOOKUP_STEP_ID}.outputs.${name}`);
|
|
381
|
+
const validateOutput = (name: string): string =>
|
|
382
|
+
expression(
|
|
383
|
+
`steps.${FACTORY_PUSH_IDENTITY_VALIDATE_STEP_ID}.outputs.${name}`
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
const contextEnvironment = {
|
|
387
|
+
EXPECTED_AFTER_SHA: triggeringHead,
|
|
388
|
+
EXPECTED_CONCLUSION: expression("github.event.workflow_run.conclusion"),
|
|
389
|
+
EXPECTED_EVENT_NAME: expression("github.event_name"),
|
|
390
|
+
EXPECTED_REPOSITORY: currentRepository,
|
|
391
|
+
EXPECTED_RUN_ID: triggeringRun,
|
|
392
|
+
EXPECTED_WORKFLOW_EVENT: expression("github.event.workflow_run.event"),
|
|
393
|
+
EXPECTED_WORKFLOW_REPOSITORY: expression(
|
|
394
|
+
"github.event.workflow_run.repository.full_name"
|
|
395
|
+
),
|
|
396
|
+
};
|
|
397
|
+
const steps: readonly WorkflowStep[] = [
|
|
398
|
+
{
|
|
399
|
+
continueOnError: true,
|
|
400
|
+
env: {
|
|
401
|
+
GH_TOKEN: expression("github.token"),
|
|
402
|
+
...contextEnvironment,
|
|
403
|
+
},
|
|
404
|
+
id: FACTORY_PUSH_IDENTITY_LOOKUP_STEP_ID,
|
|
405
|
+
name: "Resolve exact push identity artifact",
|
|
406
|
+
run: lookupScript,
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
continueOnError: true,
|
|
410
|
+
id: FACTORY_PUSH_IDENTITY_DOWNLOAD_STEP_ID,
|
|
411
|
+
if: `steps.${FACTORY_PUSH_IDENTITY_LOOKUP_STEP_ID}.outputs.status == 'available'`,
|
|
412
|
+
name: "Download exact push identity",
|
|
413
|
+
uses: options.downloadArtifact.uses,
|
|
414
|
+
with: {
|
|
415
|
+
"artifact-ids": lookupOutput("artifact_id"),
|
|
416
|
+
"github-token": expression("github.token"),
|
|
417
|
+
path: `${expression("runner.temp")}/factory-push-identity`,
|
|
418
|
+
repository: currentRepository,
|
|
419
|
+
"run-id": triggeringRun,
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
continueOnError: true,
|
|
424
|
+
id: FACTORY_PUSH_IDENTITY_CHECKOUT_STEP_ID,
|
|
425
|
+
if: `steps.${FACTORY_PUSH_IDENTITY_LOOKUP_STEP_ID}.outputs.status == 'available'`,
|
|
426
|
+
name: "Checkout exact verified head",
|
|
427
|
+
uses: options.checkout.uses,
|
|
428
|
+
with: { "fetch-depth": "0", ref: triggeringHead },
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
continueOnError: true,
|
|
432
|
+
env: {
|
|
433
|
+
ARTIFACT_ID: lookupOutput("artifact_id"),
|
|
434
|
+
CHECKOUT_OUTCOME: expression(
|
|
435
|
+
`steps.${FACTORY_PUSH_IDENTITY_CHECKOUT_STEP_ID}.outcome`
|
|
436
|
+
),
|
|
437
|
+
DOWNLOAD_OUTCOME: expression(
|
|
438
|
+
`steps.${FACTORY_PUSH_IDENTITY_DOWNLOAD_STEP_ID}.outcome`
|
|
439
|
+
),
|
|
440
|
+
LOOKUP_REASON: lookupOutput("reason"),
|
|
441
|
+
LOOKUP_STATUS: lookupOutput("status"),
|
|
442
|
+
...contextEnvironment,
|
|
443
|
+
},
|
|
444
|
+
id: FACTORY_PUSH_IDENTITY_VALIDATE_STEP_ID,
|
|
445
|
+
if: "always()",
|
|
446
|
+
name: "Validate exact push identity",
|
|
447
|
+
run: validationScript,
|
|
448
|
+
},
|
|
449
|
+
];
|
|
450
|
+
|
|
451
|
+
return Object.freeze({
|
|
452
|
+
outputs: Object.freeze({
|
|
453
|
+
after: validateOutput("after"),
|
|
454
|
+
before: validateOutput("before"),
|
|
455
|
+
disposition: validateOutput("disposition"),
|
|
456
|
+
provenance: validateOutput("provenance"),
|
|
457
|
+
reason: validateOutput("reason"),
|
|
458
|
+
}),
|
|
459
|
+
requiredPermissions: Object.freeze({ actions: "read", contents: "read" }),
|
|
460
|
+
steps: Object.freeze(steps),
|
|
461
|
+
usableIf: `steps.${FACTORY_PUSH_IDENTITY_VALIDATE_STEP_ID}.outputs.disposition == 'usable'`,
|
|
462
|
+
});
|
|
463
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@patronage/software-factory` publishes two dist entries. `dist/index.js` is
|
|
3
|
+
* the package export: consumers import it, so it runs no command. `dist/cli.js`
|
|
4
|
+
* is the bin, and it is the only entry that runs one (software-factory#386).
|
|
5
|
+
*
|
|
6
|
+
* A workflow step that invokes `dist/index.js` therefore loads a library and
|
|
7
|
+
* exits 0 — a green step that did nothing. This guard makes a generator refuse
|
|
8
|
+
* that `cli` at generation time, where the failure is loud, instead of letting
|
|
9
|
+
* it reach CI where the failure is silent. Invoke the bin by name (`psf`,
|
|
10
|
+
* `pnpm exec psf`, `pnpm dlx psf`) or by the `dist/cli.js` path.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// A token match, not a shell parser. The terminator admits the quote
|
|
14
|
+
// characters as well as whitespace, so `node "…/dist/index.js"` and the
|
|
15
|
+
// single-quoted form are caught too. It stays deliberately short of parsing
|
|
16
|
+
// the command: a `cli` string that hides the path from this scan is out of
|
|
17
|
+
// scope for a text guard.
|
|
18
|
+
const INERT_ENTRY_PATTERN = /(?:^|[/\\])dist[/\\]index\.js(?:["'\s]|$)/u;
|
|
19
|
+
|
|
20
|
+
/** Shared validator for every `cli` string a factory-ci generator emits. */
|
|
21
|
+
export const assertRunnableCli = (name: string, cli: string): void => {
|
|
22
|
+
if (INERT_ENTRY_PATTERN.test(cli)) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`${name} must invoke the software-factory bin, not the package entry dist/index.js, which imports as a library and exits 0 without running the command. Use the bin name (for example "pnpm exec psf") or dist/cli.js. Got "${cli}".`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
};
|