Skip to content

Commit c26d3cf

Browse files
authored
fix(ci): skip Periphery scans for unrelated PR changes (#107991)
* fix(ci): scope Periphery to PR merge changes * test(ci): align Periphery changed-test routing
1 parent 8631832 commit c26d3cf

8 files changed

Lines changed: 281 additions & 213 deletions

‎.github/workflows/ios-periphery.yml‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,11 @@ jobs:
2626
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
2727
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
2828
with:
29-
fetch-depth: 1
29+
fetch-depth: 2
3030
fetch-tags: false
3131
persist-credentials: false
3232
submodules: false
3333

34-
- name: Ensure base commit
35-
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
36-
uses: ./.github/actions/ensure-base-commit
37-
with:
38-
base-sha: ${{ github.event.pull_request.base.sha }}
39-
fetch-ref: ${{ github.event.pull_request.base.ref }}
40-
4134
- name: Detect changed paths
4235
id: scope
4336
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
@@ -52,14 +45,12 @@ jobs:
5245
return;
5346
}
5447
55-
const baseSha = context.payload.pull_request?.base?.sha;
56-
if (!baseSha) {
57-
throw new Error("missing pull request base SHA");
58-
}
48+
// pull_request checks out GitHub's synthetic merge commit. Its first
49+
// parent is the exact base tree used to produce the tested result.
5950
const result = await exec.getExecOutput("git", [
6051
"diff",
6152
"--quiet",
62-
baseSha,
53+
"HEAD^1",
6354
"HEAD",
6455
"--",
6556
"apps/ios/",

‎.github/workflows/macos-periphery.yml‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,11 @@ jobs:
2626
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
2727
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
2828
with:
29-
fetch-depth: 1
29+
fetch-depth: 2
3030
fetch-tags: false
3131
persist-credentials: false
3232
submodules: false
3333

34-
- name: Ensure base commit
35-
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
36-
uses: ./.github/actions/ensure-base-commit
37-
with:
38-
base-sha: ${{ github.event.pull_request.base.sha }}
39-
fetch-ref: ${{ github.event.pull_request.base.ref }}
40-
4134
- name: Detect changed paths
4235
id: scope
4336
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
@@ -52,14 +45,12 @@ jobs:
5245
return;
5346
}
5447
55-
const baseSha = context.payload.pull_request?.base?.sha;
56-
if (!baseSha) {
57-
throw new Error("missing pull request base SHA");
58-
}
48+
// pull_request checks out GitHub's synthetic merge commit. Its first
49+
// parent is the exact base tree used to produce the tested result.
5950
const result = await exec.getExecOutput("git", [
6051
"diff",
6152
"--quiet",
62-
baseSha,
53+
"HEAD^1",
6354
"HEAD",
6455
"--",
6556
"apps/macos/",

‎.github/workflows/shared-openclawkit-periphery.yml‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,11 @@ jobs:
2626
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
2727
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
2828
with:
29-
fetch-depth: 1
29+
fetch-depth: 2
3030
fetch-tags: false
3131
persist-credentials: false
3232
submodules: false
3333

34-
- name: Ensure base commit
35-
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
36-
uses: ./.github/actions/ensure-base-commit
37-
with:
38-
base-sha: ${{ github.event.pull_request.base.sha }}
39-
fetch-ref: ${{ github.event.pull_request.base.ref }}
40-
4134
- name: Detect changed paths
4235
id: scope
4336
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
@@ -52,14 +45,12 @@ jobs:
5245
return;
5346
}
5447
55-
const baseSha = context.payload.pull_request?.base?.sha;
56-
if (!baseSha) {
57-
throw new Error("missing pull request base SHA");
58-
}
48+
// pull_request checks out GitHub's synthetic merge commit. Its first
49+
// parent is the exact base tree used to produce the tested result.
5950
const result = await exec.getExecOutput("git", [
6051
"diff",
6152
"--quiet",
62-
baseSha,
53+
"HEAD^1",
6354
"HEAD",
6455
"--",
6556
"apps/ios/",

‎scripts/test-projects.test-support.mjs‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,26 @@ const GITHUB_WORKFLOW_OWNER_TEST_TARGETS = new Map([
520520
".github/workflows/ios-periphery-comment.yml",
521521
["test/scripts/ios-periphery-comment-workflow.test.ts"],
522522
],
523-
[".github/workflows/ios-periphery.yml", ["test/scripts/ios-periphery-comment-workflow.test.ts"]],
523+
[
524+
".github/workflows/ios-periphery.yml",
525+
[
526+
"test/scripts/ios-periphery-comment-workflow.test.ts",
527+
"test/scripts/periphery-scope-workflows.test.ts",
528+
],
529+
],
524530
[
525531
".github/workflows/macos-periphery.yml",
526-
["test/scripts/ios-periphery-comment-workflow.test.ts"],
532+
[
533+
"test/scripts/ios-periphery-comment-workflow.test.ts",
534+
"test/scripts/periphery-scope-workflows.test.ts",
535+
],
527536
],
528537
[
529538
".github/workflows/shared-openclawkit-periphery.yml",
530-
["test/scripts/periphery-intersection.test.ts"],
539+
[
540+
"test/scripts/periphery-intersection.test.ts",
541+
"test/scripts/periphery-scope-workflows.test.ts",
542+
],
531543
],
532544
[
533545
".github/workflows/live-media-runner-image.yml",

‎test/scripts/ios-periphery-comment-workflow.test.ts‎

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -88,74 +88,6 @@ function commenterScript(): string {
8888
return script;
8989
}
9090

91-
function scopeScript(): string {
92-
const workflow = parse(readFileSync(PRODUCER_WORKFLOW_PATH, "utf8")) as ProducerWorkflow;
93-
const step = workflow.jobs?.scope?.steps?.find((candidate) => candidate.id === "scope");
94-
const script = step?.with?.script;
95-
if (!script) {
96-
throw new Error("missing iOS Periphery scope script");
97-
}
98-
return script;
99-
}
100-
101-
async function runScope(options: {
102-
diffExitCode?: number;
103-
draft?: boolean;
104-
eventName?: string;
105-
files?: Array<string | { filename: string; previous_filename?: string }>;
106-
}): Promise<string | undefined> {
107-
const outputs = new Map<string, string>();
108-
const core = {
109-
setOutput(name: string, value: string) {
110-
outputs.set(name, value);
111-
},
112-
};
113-
const context = {
114-
eventName: options.eventName ?? "pull_request",
115-
payload: {
116-
pull_request: {
117-
base: { sha: "base-sha" },
118-
draft: options.draft ?? false,
119-
number: 123,
120-
},
121-
},
122-
repo: {
123-
owner: "openclaw",
124-
repo: "openclaw",
125-
},
126-
};
127-
const exec = {
128-
async getExecOutput(command: string, args: string[]) {
129-
if (command !== "git" || args.slice(0, 5).join(" ") !== "diff --quiet base-sha HEAD --") {
130-
throw new Error(`unexpected scope command: ${command} ${args.join(" ")}`);
131-
}
132-
if (options.diffExitCode !== undefined) {
133-
return { exitCode: options.diffExitCode };
134-
}
135-
const pathspecs = args.slice(5);
136-
const filenames = (options.files ?? []).flatMap((file) =>
137-
typeof file === "string"
138-
? [file]
139-
: [file.filename, file.previous_filename].filter((name): name is string => Boolean(name)),
140-
);
141-
const changed = filenames.some((filename) =>
142-
pathspecs.some((pathspec) =>
143-
pathspec.endsWith("/") ? filename.startsWith(pathspec) : filename === pathspec,
144-
),
145-
);
146-
return { exitCode: changed ? 1 : 0 };
147-
},
148-
};
149-
const execute = compileFunction(`return (async () => {\n${scopeScript()}\n})();`, [
150-
"context",
151-
"core",
152-
"exec",
153-
]) as (context: unknown, core: unknown, exec: unknown) => Promise<void>;
154-
155-
await execute(context, core, exec);
156-
return outputs.get("should-scan");
157-
}
158-
15991
async function runCommenter(
16092
artifact: Artifact,
16193
archiveData: Buffer,
@@ -476,69 +408,6 @@ describe("iOS Periphery comment workflow", () => {
476408
expect(workflow.jobs?.scan?.["runs-on"]).toContain("github.run_attempt > 1");
477409
}
478410
});
479-
480-
it("runs scope detection for PR transitions that can clear stale findings", () => {
481-
const workflow = parse(readFileSync(PRODUCER_WORKFLOW_PATH, "utf8")) as ProducerWorkflow;
482-
483-
expect(workflow.on?.pull_request?.types).toContain("converted_to_draft");
484-
expect(workflow.on?.pull_request?.paths).toBeUndefined();
485-
expect(() =>
486-
compileFunction(`return (async () => {\n${scopeScript()}\n})();`, [
487-
"context",
488-
"core",
489-
"exec",
490-
]),
491-
).not.toThrow();
492-
expect(scopeScript()).toContain("exec.getExecOutput");
493-
expect(scopeScript()).not.toContain("pulls.listFiles");
494-
});
495-
496-
it.each([
497-
{
498-
expected: "false",
499-
files: ["apps/ios/Sources/Test.swift"],
500-
name: "draft pull request",
501-
options: { draft: true },
502-
},
503-
{
504-
expected: "true",
505-
files: ["apps/ios/Sources/Test.swift"],
506-
name: "iOS change",
507-
options: {},
508-
},
509-
{
510-
expected: "false",
511-
files: ["docs/index.md"],
512-
name: "out-of-scope change",
513-
options: {},
514-
},
515-
{
516-
expected: "true",
517-
files: [
518-
{
519-
filename: "docs/Moved.swift",
520-
previous_filename: "apps/ios/Sources/Moved.swift",
521-
},
522-
],
523-
name: "iOS file renamed out of scope",
524-
options: {},
525-
},
526-
{
527-
expected: "true",
528-
files: [],
529-
name: "manual dispatch",
530-
options: { eventName: "workflow_dispatch" },
531-
},
532-
])("sets scope output for $name", async ({ expected, files, options }) => {
533-
await expect(runScope({ ...options, files })).resolves.toBe(expected);
534-
});
535-
536-
it("fails closed when git cannot compare the base and head", async () => {
537-
await expect(runScope({ diffExitCode: 128 })).rejects.toThrow(
538-
"git diff failed with exit code 128",
539-
);
540-
});
541-
542411
it("accepts a valid small Periphery artifact", async () => {
543412
const archive = makeZip({
544413
"periphery.json": "[]\n",

‎test/scripts/periphery-intersection.test.ts‎

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
22
import { tmpdir } from "node:os";
33
import { dirname, join } from "node:path";
4-
import { compileFunction } from "node:vm";
54
import { describe, expect, it } from "vitest";
65
import { parse } from "yaml";
76
import {
@@ -167,43 +166,4 @@ describe("shared OpenClawKit Periphery workflow", () => {
167166
);
168167
expect(macosScan?.run).not.toContain("--exclude-tests");
169168
});
170-
171-
it("scopes native consumer, shared package, and workflow changes", async () => {
172-
const script = workflow.jobs?.scope?.steps?.find((step) => step.id === "scope")?.with?.script;
173-
expect(script).toBeTruthy();
174-
const execute = compileFunction(`return (async () => {\n${script}\n})();`, [
175-
"context",
176-
"core",
177-
"exec",
178-
]) as (context: unknown, core: unknown, exec: unknown) => Promise<void>;
179-
180-
for (const filename of [
181-
"apps/ios/Sources/App.swift",
182-
"apps/macos/Sources/OpenClaw/App.swift",
183-
"apps/shared/OpenClawKit/Sources/OpenClawKit/Example.swift",
184-
WORKFLOW_PATH,
185-
]) {
186-
const outputs = new Map<string, string>();
187-
await execute(
188-
{
189-
eventName: "pull_request",
190-
payload: { pull_request: { base: { sha: "base-sha" }, draft: false, number: 1 } },
191-
repo: {},
192-
},
193-
{ setOutput: (name: string, value: string) => outputs.set(name, value) },
194-
{
195-
async getExecOutput(command: string, args: string[]) {
196-
expect(command).toBe("git");
197-
expect(args.slice(0, 5)).toEqual(["diff", "--quiet", "base-sha", "HEAD", "--"]);
198-
const pathspecs = args.slice(5);
199-
const changed = pathspecs.some((pathspec) =>
200-
pathspec.endsWith("/") ? filename.startsWith(pathspec) : filename === pathspec,
201-
);
202-
return { exitCode: changed ? 1 : 0 };
203-
},
204-
},
205-
);
206-
expect(outputs.get("should-scan"), filename).toBe("true");
207-
}
208-
});
209169
});

0 commit comments

Comments
 (0)