Skip to content

Commit 9f1e63e

Browse files
committed
ci: forkのGUI検査基準を上流祖先へ統一
上流同期の未変更GUIまでforkの変更と判定していた。ローカルと同じ公式上流の共通祖先をCIでも解決し、fork側のファイル全体検査は維持する。取得失敗や共通祖先不明は拒否する。 Refs: #357 Agent-Lane: codex
1 parent 1085d27 commit 9f1e63e

2 files changed

Lines changed: 58 additions & 9 deletions

File tree

‎.github/workflows/check.yml‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
- name: Checkout repository
2222
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
2323
with:
24-
# A pull request checks out its merge into the current base; the first parent is that base.
25-
fetch-depth: 2
24+
# Fork PRs need the shared upstream ancestor; keep the upstream job's original shallow checkout.
25+
fetch-depth: ${{ github.repository != 'anomalyco/opencode' && github.event_name == 'pull_request' && '0' || '2' }}
2626

2727
- name: Setup Bun
2828
uses: ./.github/actions/setup-bun
@@ -34,10 +34,25 @@ jobs:
3434
- name: Typecheck (TypeScript 7.1)
3535
run: bun run typecheck:tsc
3636

37+
# Match lint:changed's local upstream/dev merge base. Imported upstream files retain upstream ownership;
38+
# every fork-owned GUI change, including an untracked file, still runs the whole-file warning gate.
39+
- name: Resolve fork lint baseline
40+
id: lint_base
41+
if: github.event_name == 'pull_request' && github.repository != 'anomalyco/opencode'
42+
shell: bash
43+
run: |
44+
set -euo pipefail
45+
git fetch --no-tags https://github.com/anomalyco/opencode.git dev
46+
base="$(git merge-base HEAD FETCH_HEAD)"
47+
test -n "$base"
48+
printf 'base=%s\n' "$base" >> "$GITHUB_OUTPUT"
49+
3750
# Every GUI package file (app, desktop, gui-plugins, the plugin package's GUI SDK, ui, session-ui) a pull request adds or edits must be free of
3851
# oxlint problems, warn-level rules (anti-slop) included. Other packages are not affected.
3952
- name: Lint changed files
4053
if: github.event_name == 'pull_request'
41-
# Against the merge's first parent, so base-branch commits the pull request has not merged are not counted as its
42-
# changes (the event's base SHA can predate them).
43-
run: bun run lint:changed HEAD^1
54+
env:
55+
LINT_BASE: ${{ github.repository == 'anomalyco/opencode' && 'HEAD^1' || steps.lint_base.outputs.base }}
56+
run: |
57+
test -n "$LINT_BASE"
58+
bun run lint:changed "$LINT_BASE"

‎packages/guardrails/profile/src/fork-ci.test.ts‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@ const directory = path.join(root, ".github/workflows")
77
const upstream = "anomalyco/opencode"
88
const fork = "Cor-Incorporated/opencode"
99

10-
type Job = { "runs-on"?: string; if?: string; steps?: { name?: string; if?: string; run?: string; uses?: string }[] }
10+
type Job = {
11+
"runs-on"?: string
12+
if?: string
13+
steps?: {
14+
name?: string
15+
id?: string
16+
if?: string
17+
run?: string
18+
uses?: string
19+
with?: Record<string, string | number>
20+
env?: Record<string, string>
21+
}[]
22+
}
1123

1224
function workflow(...names: string[]) {
1325
const name = names.find((name) => existsSync(path.join(directory, name)))
@@ -17,13 +29,15 @@ function workflow(...names: string[]) {
1729

1830
// These workflow expressions use the shared JavaScript/GitHub subset: property access, strings, ==, && and ||.
1931
// Evaluate the actual YAML expressions, not a second runner-selection implementation.
20-
function evaluate(value: string | undefined, repository: string, name = "linux") {
32+
function evaluate(value: string | number | undefined, repository: string, name = "linux", event = "push", base = "") {
2133
if (value === undefined) return true
34+
if (typeof value === "number") return value
2235
if (!value.includes("${{") && !value.includes("github.")) return value
2336
const expression = value.replace(/^\$\{\{\s*|\s*\}\}$/g, "")
24-
return new Function("github", "matrix", `return (${expression})`)(
25-
{ repository, event_name: "push", ref: "refs/heads/dev" },
37+
return new Function("github", "matrix", "steps", `return (${expression})`)(
38+
{ repository, event_name: event, ref: "refs/heads/dev" },
2639
{ settings: { name, host: `blacksmith-4vcpu-${name === "windows" ? "windows-2025" : "ubuntu-2404"}` } },
40+
{ lint_base: { outputs: { base } } },
2741
) as string | boolean
2842
}
2943

@@ -63,6 +77,26 @@ describe("fork CI runner eligibility", () => {
6377
expect(install).toBeDefined()
6478
expect(steps.indexOf(install!)).toBeLessThan(run)
6579
})
80+
test("fork pull requests keep complete history without changing upstream checkout depth", () => {
81+
const checkout = workflow("check.yml").jobs.check.steps?.find((step) => step.name === "Checkout repository")
82+
expect(evaluate(checkout?.with?.["fetch-depth"], fork, "linux", "pull_request")).toBe("0")
83+
expect(String(evaluate(checkout?.with?.["fetch-depth"], fork))).toBe("2")
84+
expect(String(evaluate(checkout?.with?.["fetch-depth"], upstream, "linux", "pull_request"))).toBe("2")
85+
})
86+
test("only fork pull requests resolve and consume the upstream merge base", () => {
87+
const steps = workflow("check.yml").jobs.check.steps ?? []
88+
const resolve = steps.find((step) => step.id === "lint_base")
89+
const lint = steps.find((step) => step.name === "Lint changed files")
90+
expect(resolve).toBeDefined()
91+
expect(evaluate(resolve?.if, fork, "linux", "pull_request")).toBe(true)
92+
expect(evaluate(resolve?.if, upstream, "linux", "pull_request")).toBe(false)
93+
expect(evaluate(resolve?.if, fork)).toBe(false)
94+
expect(steps.indexOf(resolve!)).toBeLessThan(steps.indexOf(lint!))
95+
const sha = "55276f2108c8853f94cf16dc530e7754a6ce8318"
96+
expect(evaluate(lint?.env?.LINT_BASE, fork, "linux", "pull_request", sha)).toBe(sha)
97+
expect(evaluate(lint?.env?.LINT_BASE, upstream, "linux", "pull_request", sha)).toBe("HEAD^1")
98+
expect(evaluate(lint?.env?.LINT_BASE, fork, "linux", "pull_request")).toBe("")
99+
})
66100
})
67101

68102
describe("upstream-only automation", () => {

0 commit comments

Comments
 (0)