Skip to content

Commit b8490b4

Browse files
committed
chore(media-use): merge main into the theSVG logos branch
2 parents fe0a4b6 + ca4af78 commit b8490b4

11 files changed

Lines changed: 184 additions & 22 deletions

‎.github/workflows/catalog-publish.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
workflow_dispatch:
77

88
permissions:
9+
actions: write
910
contents: write
1011
pull-requests: write
1112

‎.github/workflows/ci.yml‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env:
1010
HYPERFRAMES_NO_TELEMETRY: "1"
1111

1212
on:
13+
workflow_dispatch:
1314
pull_request:
1415
# `edited` is required so the workflow re-fires when a PR's base ref is
1516
# set back to `main` after a Graphite stack restack momentarily flips
@@ -56,7 +57,7 @@ jobs:
5657
runs-on: ubuntu-latest
5758
timeout-minutes: 2
5859
outputs:
59-
code: ${{ steps.filter.outputs.code }}
60+
code: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.code == 'true' }}
6061
docs_catalog: ${{ steps.filter.outputs.docs_catalog }}
6162
cli: ${{ steps.filter.outputs.cli }}
6263
skills: ${{ steps.filter.outputs.skills }}
@@ -232,7 +233,7 @@ jobs:
232233
run: node scripts/check-catalog-source-pr.mjs origin/main
233234
- name: Generate and validate catalog
234235
env:
235-
PUBLISH_PR: ${{ github.head_ref == 'bot/catalog-publish' }}
236+
PUBLISH_PR: ${{ (github.head_ref || github.ref_name) == 'bot/catalog-publish' }}
236237
run: |
237238
if [ "$PUBLISH_PR" = "true" ]; then
238239
bun run check:catalog-drift --committed
@@ -1062,15 +1063,31 @@ jobs:
10621063
10631064
semantic-pr-title:
10641065
name: Semantic PR title
1065-
if: github.event_name == 'pull_request'
1066+
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
10661067
runs-on: ubuntu-latest
10671068
timeout-minutes: 5
10681069
steps:
1069-
- uses: amannn/action-semantic-pull-request@e32d7e603df1aa1ba07e981f2a23455dee596825 # v5
1070+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
1071+
- id: pr
1072+
run: node scripts/ci/resolve-workflow-pr.mjs
10701073
env:
1071-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1074+
GH_TOKEN: ${{ github.token }}
1075+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
1076+
with:
1077+
repository: amannn/action-semantic-pull-request
1078+
ref: e32d7e603df1aa1ba07e981f2a23455dee596825 # v5
1079+
path: .semantic-pr-action
1080+
persist-credentials: false
1081+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
10721082
with:
1073-
types: |
1083+
node-version: 22
1084+
- name: Validate PR title
1085+
run: GITHUB_EVENT_PATH="$PR_EVENT_PATH" node .semantic-pr-action/dist/index.js
1086+
env:
1087+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1088+
PR_EVENT_PATH: ${{ steps.pr.outputs.event_path }}
1089+
INPUT_GITHUBBASEURL: ${{ github.api_url }}
1090+
INPUT_TYPES: |
10741091
feat
10751092
fix
10761093
docs

‎.github/workflows/codeql.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
name: CodeQL
1212

1313
on:
14+
workflow_dispatch:
1415
push:
1516
branches: [main]
1617
pull_request:

‎.github/workflows/pr-captures.yml‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ permissions:
66

77
# Runs on every PR (no path filter) so it can be a required check; the script passes when neither package changed.
88
on:
9+
workflow_dispatch:
910
pull_request:
1011
types: [opened, synchronize, reopened, edited]
1112
branches: [main]
1213

1314
concurrency:
14-
group: pr-captures-${{ github.event.pull_request.number }}
15+
group: pr-captures-${{ github.event.pull_request.number || github.ref }}
1516
cancel-in-progress: true
1617

1718
jobs:
@@ -23,12 +24,16 @@ jobs:
2324
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
2425
with:
2526
fetch-depth: 0
27+
- id: pr
28+
run: node scripts/ci/resolve-workflow-pr.mjs
29+
env:
30+
GH_TOKEN: ${{ github.token }}
2631
- name: Require Before and After captures
2732
env:
28-
PR_BODY: ${{ github.event.pull_request.body }}
29-
PR_NUMBER: ${{ github.event.pull_request.number }}
30-
BASE_REF: ${{ github.event.pull_request.base.ref }}
31-
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
33+
PR_BODY: ${{ fromJSON(steps.pr.outputs.pr).body }}
34+
PR_NUMBER: ${{ fromJSON(steps.pr.outputs.pr).number }}
35+
BASE_REF: ${{ fromJSON(steps.pr.outputs.pr).base.ref }}
36+
HEAD_REPO: ${{ fromJSON(steps.pr.outputs.pr).head.repo.full_name }}
3237
BASE_REPO: ${{ github.repository }}
33-
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
38+
HEAD_SHA: ${{ fromJSON(steps.pr.outputs.pr).head.sha }}
3439
run: node scripts/check-pr-captures.mjs --base "origin/$BASE_REF" --head "$HEAD_SHA"

‎.github/workflows/regression.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
on:
18+
workflow_dispatch:
1819
pull_request:
1920
# Re-run when Graphite changes only the PR base for the same head SHA.
2021
types: [opened, synchronize, reopened, edited]
@@ -28,7 +29,7 @@ jobs:
2829
runs-on: ubuntu-latest
2930
timeout-minutes: 2
3031
outputs:
31-
code: ${{ steps.filter.outputs.code }}
32+
code: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.code == 'true' }}
3233
matrix: ${{ steps.shards.outputs.matrix }}
3334
steps:
3435
# Force git-based change detection instead of the pull_request REST API.

‎.github/workflows/windows-render.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ on:
3030
ref:
3131
description: "Git ref to render (branch / tag / SHA)."
3232
required: false
33-
default: "main"
33+
default: ""
3434

3535
concurrency:
3636
group: windows-render-${{ github.ref }}
@@ -71,7 +71,7 @@ jobs:
7171
steps:
7272
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
7373
with:
74-
ref: ${{ github.event.inputs.ref }}
74+
ref: ${{ inputs.ref || github.sha }}
7575
- uses: ./.github/actions/preflight
7676

7777
render-windows:
@@ -90,7 +90,7 @@ jobs:
9090
- name: Checkout
9191
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
9292
with:
93-
ref: ${{ github.event.inputs.ref }}
93+
ref: ${{ inputs.ref || github.sha }}
9494
lfs: true
9595

9696
- name: Show platform info
@@ -416,7 +416,7 @@ jobs:
416416
- name: Checkout
417417
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
418418
with:
419-
ref: ${{ github.event.inputs.ref }}
419+
ref: ${{ inputs.ref || github.sha }}
420420
lfs: true
421421

422422
# -----------------------------------------------------------------

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"player:perf": "bun run --filter @hyperframes/player perf",
5353
"format:check": "oxfmt --check .",
5454
"knip": "knip",
55-
"test:scripts": "node --import tsx --test scripts/animejs-v4-guidance.test.mjs scripts/check-tracked-artifacts.test.mjs scripts/check-registry-set-delta.test.mjs scripts/check-no-main-deletions.test.mjs scripts/check-pr-captures.test.mjs scripts/check-docs-snippet-motion.test.mjs scripts/registry-target-paths.test.mjs scripts/check-workspace-contracts.test.mjs scripts/check-media-use-copy-parity.test.mjs scripts/check-svg-sanitize-parity.test.mjs scripts/check-media-use-svg-sanitize-generated.test.mjs scripts/check-package-cycles.test.mjs scripts/check-cli-process-ownership.test.mjs scripts/check-large-files.test.mjs scripts/package-subpaths.test.mjs scripts/validate-release-channel.test.mjs scripts/publish-workflow.test.mjs scripts/install-workspace-dependencies.test.mjs scripts/draft-changelog.test.ts scripts/set-version.test.ts scripts/release-prepare.test.ts scripts/cli-options.test.ts scripts/changelog-weekly.test.ts scripts/claude-plugin-compression.test.ts scripts/catalog-payload-assets.test.ts scripts/host-registry-assets.test.ts scripts/catalog-preview-temp.test.ts scripts/catalog-hosted-files.test.ts scripts/player-cdn-pin.test.ts scripts/studio-runtime-smoke.test.mjs scripts/verify-packed-manifests.test.mjs scripts/lint-skills.test.mjs scripts/creator-editing-recipes.test.mjs packages/gcp-cloud-run/check-dockerfile-workspaces.test.mjs packages/core/scripts/writeGeneratedFile.test.ts scripts/catalog-publication.test.mjs scripts/check-catalog-source-pr.test.mjs scripts/generate-registry-items.test.ts scripts/catalog-drift.test.ts scripts/catalog-fetch-mirror.test.ts scripts/catalog-script-inlining.test.ts scripts/catalog-detail.test.ts scripts/generate-catalog-pages.test.ts scripts/verify-catalog-payloads.test.ts scripts/registry-skill-files.test.ts scripts/creator-editing-capabilities.test.mjs scripts/generate-catalog-previews.test.ts scripts/registry-primitive-payloads.test.ts registry/components/pan-stations/pan-stations.test.mjs && vitest run scripts/catalog/ scripts/contrastRatchet.test.ts scripts/generate-catalog-payloads.test.ts",
55+
"test:scripts": "node --import tsx --test scripts/animejs-v4-guidance.test.mjs scripts/check-tracked-artifacts.test.mjs scripts/check-registry-set-delta.test.mjs scripts/check-no-main-deletions.test.mjs scripts/check-pr-captures.test.mjs scripts/check-docs-snippet-motion.test.mjs scripts/registry-target-paths.test.mjs scripts/check-workspace-contracts.test.mjs scripts/check-media-use-copy-parity.test.mjs scripts/check-svg-sanitize-parity.test.mjs scripts/check-media-use-svg-sanitize-generated.test.mjs scripts/check-package-cycles.test.mjs scripts/check-cli-process-ownership.test.mjs scripts/check-large-files.test.mjs scripts/package-subpaths.test.mjs scripts/validate-release-channel.test.mjs scripts/publish-workflow.test.mjs scripts/install-workspace-dependencies.test.mjs scripts/draft-changelog.test.ts scripts/set-version.test.ts scripts/release-prepare.test.ts scripts/cli-options.test.ts scripts/changelog-weekly.test.ts scripts/claude-plugin-compression.test.ts scripts/catalog-payload-assets.test.ts scripts/host-registry-assets.test.ts scripts/catalog-preview-temp.test.ts scripts/catalog-hosted-files.test.ts scripts/player-cdn-pin.test.ts scripts/studio-runtime-smoke.test.mjs scripts/verify-packed-manifests.test.mjs scripts/lint-skills.test.mjs scripts/creator-editing-recipes.test.mjs packages/gcp-cloud-run/check-dockerfile-workspaces.test.mjs packages/core/scripts/writeGeneratedFile.test.ts scripts/catalog-publication.test.mjs scripts/ci/resolve-workflow-pr.test.mjs scripts/check-catalog-source-pr.test.mjs scripts/generate-registry-items.test.ts scripts/catalog-drift.test.ts scripts/catalog-fetch-mirror.test.ts scripts/catalog-script-inlining.test.ts scripts/catalog-detail.test.ts scripts/generate-catalog-pages.test.ts scripts/verify-catalog-payloads.test.ts scripts/registry-skill-files.test.ts scripts/creator-editing-capabilities.test.mjs scripts/generate-catalog-previews.test.ts scripts/registry-primitive-payloads.test.ts registry/components/pan-stations/pan-stations.test.mjs && vitest run scripts/catalog/ scripts/contrastRatchet.test.ts scripts/generate-catalog-payloads.test.ts",
5656
"typecheck:scripts": "tsc --noEmit -p scripts/tsconfig.json",
5757
"test:skills": "node --test 'skills/**/*.test.mjs' 'packages/cli/src/media-use/**/*.test.mjs'",
5858
"generate:previews": "tsx scripts/generate-template-previews.ts",

‎scripts/catalog-publication.test.mjs‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ test("oversized API files fail before any publication", () => {
8282
);
8383
});
8484

85-
function publicationFixture(t, changed) {
85+
function publicationFixture(t, changed, apiEnv = {}) {
8686
const root = mkdtempSync(join(tmpdir(), "catalog-publication-api-"));
8787
t.after(() => rmSync(root, { recursive: true, force: true }));
8888
const git = (...args) => execFileSync("git", args, { cwd: root, encoding: "utf8" }).trim();
@@ -116,11 +116,14 @@ const endpoint = args[1];
116116
const method = args[args.indexOf("--method") + 1];
117117
const body = args.includes("--input") ? JSON.parse(fs.readFileSync(0, "utf8")) : undefined;
118118
fs.appendFileSync(process.env.API_CALLS, JSON.stringify({ endpoint, method, body }) + "\\n");
119-
if (endpoint === "graphql" || method === "DELETE") {
119+
if (!process.env.PUBLISH_SUCCESS && (endpoint === "graphql" || method === "DELETE")) {
120120
console.error(endpoint === "graphql" ? "commit rejected" : "cleanup rejected");
121121
process.exit(1);
122122
}
123-
if (endpoint.endsWith("/ref/heads/main")) console.log(process.env.BASE);
123+
if (endpoint === "graphql") console.log("c".repeat(40));
124+
else if (endpoint.includes("/runs?")) console.log(JSON.stringify({ workflow_runs: JSON.parse(process.env.WORKFLOW_RUNS || "[]") }));
125+
else if (endpoint.endsWith("/dispatches") && process.env.DISPATCH_FAIL) process.exit(1);
126+
else if (endpoint.endsWith("/ref/heads/main")) console.log(process.env.BASE);
124127
else if (endpoint.includes("/matching-refs/")) console.log("refs/heads/bot/catalog-publish");
125128
else if (endpoint.includes("/ref/heads/bot/catalog-publish")) console.log("a".repeat(40));
126129
else if (endpoint.includes("/commits/")) console.log("b".repeat(40));
@@ -155,6 +158,7 @@ catch (error) {
155158
GITHUB_REPOSITORY: "test/catalog",
156159
GITHUB_RUN_ID: "123",
157160
GITHUB_RUN_ATTEMPT: "1",
161+
...apiEnv,
158162
},
159163
stdio: ["pipe", "pipe", "pipe"],
160164
},
@@ -213,3 +217,34 @@ test("publication refuses symlinks instead of reading outside the generated arti
213217
symlinkSync(unrelated, artifact);
214218
assert.throws(() => catalogChanges(fixture.root, "HEAD"), /ELOOP|symbolic link/);
215219
});
220+
221+
test("publication dispatches every required workflow after updating its branch and PR", (t) => {
222+
const fixture = publicationFixture(t, true, { PUBLISH_SUCCESS: "1" });
223+
fixture.run();
224+
const calls = fixture.calls();
225+
const dispatches = calls.filter((call) => call.endpoint.endsWith("/dispatches"));
226+
assert.deepEqual(
227+
dispatches.map((call) => call.endpoint.split("/").at(-2)),
228+
["ci.yml", "regression.yml", "windows-render.yml", "pr-captures.yml", "codeql.yml"],
229+
);
230+
for (const call of dispatches) assert.deepEqual(call.body, { ref: "bot/catalog-publish" });
231+
assert.ok(
232+
calls.indexOf(dispatches[0]) >
233+
calls.findIndex((call) => call.endpoint.endsWith("/pulls/42") && call.method === "PATCH"),
234+
);
235+
});
236+
237+
test("publication leaves existing successful workflows at the same head alone", (t) => {
238+
const fixture = publicationFixture(t, true, {
239+
PUBLISH_SUCCESS: "1",
240+
WORKFLOW_RUNS: JSON.stringify([{ status: "completed", conclusion: "success" }]),
241+
});
242+
fixture.run();
243+
assert.equal(fixture.calls().filter((call) => call.endpoint.endsWith("/dispatches")).length, 0);
244+
});
245+
246+
test("dispatch rejection fails publication and still cleans up the staging branch", (t) => {
247+
const fixture = publicationFixture(t, true, { PUBLISH_SUCCESS: "1", DISPATCH_FAIL: "1" });
248+
assert.throws(fixture.run);
249+
assert.equal(fixture.calls().at(-1).method, "DELETE");
250+
});

‎scripts/ci/resolve-workflow-pr.mjs‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { execFileSync } from "node:child_process";
2+
import { appendFileSync, readFileSync, writeFileSync } from "node:fs";
3+
import { join } from "node:path";
4+
import { pathToFileURL } from "node:url";
5+
6+
export function dispatchedPullRequest(pulls, repository, branch, sha) {
7+
const matches = pulls.filter(
8+
(pr) => pr.state === "open" && pr.head.repo?.full_name === repository && pr.head.ref === branch,
9+
);
10+
if (matches.length !== 1)
11+
throw new Error("Dispatch requires exactly one open PR for this branch.");
12+
const pr = matches[0];
13+
if (pr.head.sha !== sha)
14+
throw new Error("PR head changed after dispatch; run checks on the new head.");
15+
return pr;
16+
}
17+
18+
function main() {
19+
const event = JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"));
20+
if (process.env.GITHUB_EVENT_NAME === "workflow_dispatch") {
21+
const repository = process.env.GITHUB_REPOSITORY;
22+
const branch = process.env.GITHUB_REF_NAME;
23+
const owner = repository.split("/")[0];
24+
const raw = execFileSync(
25+
"gh",
26+
[
27+
"api",
28+
`repos/${repository}/pulls?state=open&head=${encodeURIComponent(`${owner}:${branch}`)}&per_page=100`,
29+
],
30+
{ encoding: "utf8", timeout: 60_000 },
31+
);
32+
event.pull_request = dispatchedPullRequest(
33+
JSON.parse(raw),
34+
repository,
35+
branch,
36+
process.env.GITHUB_SHA,
37+
);
38+
}
39+
if (!event.pull_request) throw new Error("This check requires an open pull request.");
40+
const path = join(process.env.RUNNER_TEMP, "workflow-pr-event.json");
41+
writeFileSync(path, JSON.stringify(event));
42+
appendFileSync(
43+
process.env.GITHUB_OUTPUT,
44+
`event_path=${path}\npr=${JSON.stringify(event.pull_request)}\n`,
45+
);
46+
}
47+
48+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) main();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import assert from "node:assert/strict";
2+
import { test } from "node:test";
3+
import { dispatchedPullRequest } from "./resolve-workflow-pr.mjs";
4+
5+
const pr = {
6+
state: "open",
7+
number: 7,
8+
head: { repo: { full_name: "owner/repo" }, ref: "bot/catalog-publish", sha: "a".repeat(40) },
9+
};
10+
const resolve = (pulls, sha = pr.head.sha) =>
11+
dispatchedPullRequest(pulls, "owner/repo", pr.head.ref, sha);
12+
13+
test("uses the PR for the dispatched repository, branch and exact head", () => {
14+
assert.equal(
15+
resolve([{ ...pr, head: { ...pr.head, repo: { full_name: "fork/repo" } } }, pr]),
16+
pr,
17+
);
18+
});
19+
test("refuses a dispatch without an open PR", () => {
20+
assert.throws(() => resolve([{ ...pr, state: "closed" }]), /exactly one/);
21+
});
22+
test("refuses ambiguous PRs", () => {
23+
assert.throws(() => resolve([pr, { ...pr, number: 8 }]), /exactly one/);
24+
});
25+
test("refuses a PR which advanced after dispatch", () => {
26+
assert.throws(() => resolve([pr], "b".repeat(40)), /head changed/);
27+
});

0 commit comments

Comments
 (0)