()
| 211 | } |
| 212 | |
| 213 | public async executeAsync(): Promise<void> { |
| 214 | try { |
| 215 | this.ctx.logger.info( |
| 216 | { marker: BuildStepLogMarker.START_STEP }, |
| 217 | `Executing build step "${this.displayName}"` |
| 218 | ); |
| 219 | this.status = BuildStepStatus.IN_PROGRESS; |
| 220 | |
| 221 | await fs.mkdir(this.outputsDir, { recursive: true }); |
| 222 | this.ctx.logger.debug(`Created temporary directory for step outputs: ${this.outputsDir}`); |
| 223 | |
| 224 | await fs.mkdir(this.envsDir, { recursive: true }); |
| 225 | this.ctx.logger.debug( |
| 226 | `Created temporary directory for step environment variables: ${this.envsDir}` |
| 227 | ); |
| 228 | |
| 229 | if (this.timeoutMs !== undefined) { |
| 230 | const abortController = new AbortController(); |
| 231 | |
| 232 | let timeoutId: NodeJS.Timeout | undefined; |
| 233 | const timeoutPromise = new Promise<void>((_, reject) => { |
| 234 | timeoutId = setTimeout(() => { |
| 235 | // Reject with timeout error FIRST, before killing the process |
| 236 | // This ensures the timeout error wins the race |
| 237 | reject( |
| 238 | new BuildStepRuntimeError( |
| 239 | `Build step "${this.displayName}" timed out after ${this.timeoutMs}ms` |
| 240 | ) |
| 241 | ); |
| 242 | |
| 243 | abortController.abort(); |
| 244 | }, this.timeoutMs); |
| 245 | }); |
| 246 | |
| 247 | try { |
| 248 | await Promise.race([ |
| 249 | this.command !== undefined |
| 250 | ? this.executeCommandAsync({ signal: abortController.signal }) |
| 251 | : this.executeFnAsync({ signal: abortController.signal }), |
| 252 | timeoutPromise, |
| 253 | ]); |
| 254 | } finally { |
| 255 | if (timeoutId) { |
| 256 | clearTimeout(timeoutId); |
| 257 | } |
| 258 | } |
| 259 | } else { |
| 260 | const executionPromise = |
| 261 | this.command !== undefined |
| 262 | ? this.executeCommandAsync({ signal: null }) |
| 263 | : this.executeFnAsync({ signal: null }); |
| 264 | await executionPromise; |
| 265 | } |
| 266 | |
| 267 | this.ctx.logger.info( |
| 268 | { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS }, |
| 269 | `Finished build step "${this.displayName}" successfully` |
| 270 | ); |
no test coverage detected