@@ -35,6 +35,7 @@ interface BuilderDetailsResponse extends BuilderInstance {}
3535
3636interface CleanupState {
3737 builderName : string ;
38+ idempotencyKey : string ;
3839 builderInstances : BuilderInstance [ ] ;
3940 certDirs : string [ ] ;
4041}
@@ -47,6 +48,7 @@ export class WarpBuildRemoteBuilders {
4748 private readonly apiDomain : string ;
4849 private scriptStartTime : number ;
4950 private builderName : string ;
51+ private idempotencyKey : string ;
5052 private builderInstances : BuilderInstance [ ] = [ ] ;
5153 private certDirs : string [ ] = [ ] ;
5254 private assignmentPromise : Promise < void > | null = null ;
@@ -58,7 +60,9 @@ export class WarpBuildRemoteBuilders {
5860 this . scriptStartTime = Date . now ( ) ;
5961 this . apiDomain = process . env . WARPBUILD_API_DOMAIN || 'https://api.warpbuild.com' ;
6062 this . isWarpBuildRunner = this . determineRunnerType ( ) ;
61- this . builderName = `builder-${ uuidv4 ( ) } ` ;
63+ // Example output: lq1cr8p2n5x7d3fy
64+ this . idempotencyKey = uuidv4 ( ) . replace ( / - / g, '' ) . substring ( 0 , 16 ) ;
65+ this . builderName = `builder-${ this . idempotencyKey } ` ;
6266
6367 core . debug ( `API domain: ${ this . apiDomain } ` ) ;
6468 core . debug ( `Is WarpBuild runner: ${ this . isWarpBuildRunner } ` ) ;
@@ -87,6 +91,7 @@ export class WarpBuildRemoteBuilders {
8791 public saveState ( ) : void {
8892 const state : CleanupState = {
8993 builderName : this . builderName ,
94+ idempotencyKey : this . idempotencyKey ,
9095 builderInstances : this . builderInstances ,
9196 certDirs : this . certDirs
9297 } ;
@@ -100,6 +105,7 @@ export class WarpBuildRemoteBuilders {
100105 if ( stateStr ) {
101106 const state = JSON . parse ( stateStr ) as CleanupState ;
102107 this . builderName = state . builderName ;
108+ this . idempotencyKey = state . idempotencyKey ;
103109 this . builderInstances = state . builderInstances ;
104110 this . certDirs = state . certDirs ;
105111 core . debug ( `Loaded cleanup state: ${ JSON . stringify ( state ) } ` ) ;
@@ -108,6 +114,21 @@ export class WarpBuildRemoteBuilders {
108114 }
109115 }
110116
117+ /**
118+ * Get request context from github action job environment variables
119+ *
120+ * @returns {Object }
121+ */
122+ public getRequestContext ( ) {
123+ return {
124+ runner_name : process . env . RUNNER_NAME ,
125+ github_job_id : process . env . GITHUB_JOB ,
126+ run_id : process . env . GITHUB_RUN_ID ,
127+ run_attempt : process . env . GITHUB_RUN_ATTEMPT ,
128+ repo : process . env . GITHUB_REPOSITORY ,
129+ } ;
130+ }
131+
111132 /**
112133 * Check if required tools are available
113134 */
@@ -164,7 +185,7 @@ export class WarpBuildRemoteBuilders {
164185 'Content-Type' : 'application/json' ,
165186 Authorization : authHeader
166187 } ,
167- body : JSON . stringify ( { profile_name : profileName . trim ( ) } )
188+ body : JSON . stringify ( { profile_name : profileName . trim ( ) , request_metadata : this . getRequestContext ( ) , external_unique_id : this . idempotencyKey } )
168189 } ) ;
169190
170191 if ( ! response . ok ) {
@@ -493,7 +514,7 @@ export class WarpBuildRemoteBuilders {
493514 const response = await fetch ( removeBuilderEndpoint , {
494515 method : 'POST' ,
495516 headers : { Authorization : authHeader } ,
496- body : JSON . stringify ( { request_id : builderInstance . request_id } )
517+ body : JSON . stringify ( { request_id : builderInstance . request_id , external_unique_id : this . idempotencyKey } )
497518 } ,
498519 ) ;
499520
0 commit comments