@@ -7,7 +7,19 @@ const directory = path.join(root, ".github/workflows")
77const upstream = "anomalyco/opencode"
88const 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
1224function 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
68102describe ( "upstream-only automation" , ( ) => {
0 commit comments