@@ -9,7 +9,12 @@ import { mkdtempForTestSync } from '@agent-device/test-kit';
99const repo = path . resolve ( import . meta. dirname , '../..' ) ;
1010const workflows = [ 'release-ios-runner.yml' , 'release-android-snapshot-helper.yml' ] ;
1111
12- type Step = { name : string ; run ?: string ; env ?: Record < string , string > } ;
12+ type Step = {
13+ name : string ;
14+ run ?: string ;
15+ env ?: Record < string , string > ;
16+ with ?: Record < string , string > ;
17+ } ;
1318
1419function fixture ( ) {
1520 const root = fs . realpathSync ( mkdtempForTestSync ( 'release-assets-' ) ) ;
@@ -93,13 +98,17 @@ function run(root: string, env: Record<string, string>, script: string, args: st
9398 return spawnSync ( '/bin/sh' , [ script , ...args ] , { cwd : root , env, encoding : 'utf8' } ) ;
9499}
95100
96- function metadataStep ( workflow : string ) : Step {
101+ function workflowSteps ( workflow : string ) : Step [ ] {
97102 const doc = parse ( fs . readFileSync ( path . join ( repo , '.github/workflows' , workflow ) , 'utf8' ) ) as {
98103 jobs : Record < string , { steps : Step [ ] } > ;
99104 } ;
100- const step = Object . values ( doc . jobs )
101- . flatMap ( ( job ) => job . steps )
102- . find ( ( candidate ) => candidate . name === 'Resolve release metadata' ) ;
105+ return Object . values ( doc . jobs ) . flatMap ( ( job ) => job . steps ) ;
106+ }
107+
108+ function metadataStep ( workflow : string ) : Step {
109+ const step = workflowSteps ( workflow ) . find (
110+ ( candidate ) => candidate . name === 'Resolve release metadata' ,
111+ ) ;
103112 assert . ok ( step ?. run ) ;
104113 return step ;
105114}
@@ -117,6 +126,25 @@ for (const workflow of workflows) {
117126 ] as const ) {
118127 test ( `${ workflow } handles ${ label } as data` , ( ) => {
119128 const f = fixture ( ) ;
129+ const historical = path . join ( f . root , 'historical.mjs' ) ;
130+ fs . writeFileSync ( historical , "console.error('unknown command'); process.exit(1);\n" ) ;
131+ const refs : Record < string , string > = {
132+ '${{ inputs.checkout_ref || github.ref }}' : historical ,
133+ '${{ github.workflow_sha }}' : path . join ( repo , 'scripts/release-version.mjs' ) ,
134+ } ;
135+ for ( const checkout of workflowSteps ( workflow ) . filter ( ( step ) =>
136+ step . name . startsWith ( 'Checkout' ) ,
137+ ) ) {
138+ const source = refs [ checkout . with ?. ref ?? '' ] ;
139+ assert . ok ( source , `unexpected checkout ref: ${ checkout . with ?. ref } ` ) ;
140+ const destination = path . join (
141+ f . root ,
142+ checkout . with ?. path ?? '' ,
143+ 'scripts/release-version.mjs' ,
144+ ) ;
145+ fs . mkdirSync ( path . dirname ( destination ) , { recursive : true } ) ;
146+ fs . copyFileSync ( source , destination ) ;
147+ }
120148 const tag = makeTag ( f . marker ) ;
121149 const step = metadataStep ( workflow ) ;
122150 const inputExpression = '${{ inputs.release_tag }}' ;
0 commit comments