@@ -15,7 +15,9 @@ import { parseRepositoryNwo } from "./repository";
1515import {
1616 createFeatures ,
1717 createTestConfig ,
18+ DEFAULT_ACTIONS_VARS ,
1819 makeVersionInfo ,
20+ setupActionsVars ,
1921 setupTests ,
2022} from "./testing-utils" ;
2123import * as uploadLib from "./upload-lib" ;
@@ -28,8 +30,7 @@ setupTests(test);
2830
2931test ( "init-post action with debug mode off" , async ( t ) => {
3032 return await util . withTmpDir ( async ( tmpDir ) => {
31- process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
32- process . env [ "RUNNER_TEMP" ] = tmpDir ;
33+ setupActionsVars ( tmpDir , tmpDir ) ;
3334
3435 const gitHubVersion : util . GitHubVersion = {
3536 type : util . GitHubVariant . DOTCOM ,
@@ -62,8 +63,7 @@ test("init-post action with debug mode off", async (t) => {
6263
6364test ( "init-post action with debug mode on" , async ( t ) => {
6465 return await util . withTmpDir ( async ( tmpDir ) => {
65- process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
66- process . env [ "RUNNER_TEMP" ] = tmpDir ;
66+ setupActionsVars ( tmpDir , tmpDir ) ;
6767
6868 const uploadAllAvailableDebugArtifactsSpy = sinon . spy ( ) ;
6969 const printDebugLogsSpy = sinon . spy ( ) ;
@@ -315,11 +315,7 @@ test("not uploading failed SARIF when `code-scanning` is not an enabled analysis
315315
316316test ( "saves overlay status when overlay-base analysis did not complete successfully" , async ( t ) => {
317317 return await util . withTmpDir ( async ( tmpDir ) => {
318- process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
319- process . env [ "GITHUB_RUN_ID" ] = "12345" ;
320- process . env [ "GITHUB_RUN_ATTEMPT" ] = "1" ;
321- process . env [ "GITHUB_JOB" ] = "analyze" ;
322- process . env [ "RUNNER_TEMP" ] = tmpDir ;
318+ setupActionsVars ( tmpDir , tmpDir ) ;
323319 // Ensure analyze did not complete successfully.
324320 delete process . env [ EnvVar . ANALYZE_DID_COMPLETE_SUCCESSFULLY ] ;
325321
@@ -375,9 +371,9 @@ test("saves overlay status when overlay-base analysis did not complete successfu
375371 builtOverlayBaseDatabase : false ,
376372 job : {
377373 checkRunId : undefined ,
378- workflowRunId : 12345 ,
379- workflowRunAttempt : 1 ,
380- name : "analyze" ,
374+ workflowRunId : Number ( DEFAULT_ACTIONS_VARS . GITHUB_RUN_ID ) ,
375+ workflowRunAttempt : Number ( DEFAULT_ACTIONS_VARS . GITHUB_RUN_ATTEMPT ) ,
376+ name : DEFAULT_ACTIONS_VARS . GITHUB_JOB ,
381377 } ,
382378 } ,
383379 "fourth arg should be the overlay status recording an unsuccessful build attempt with job details" ,
@@ -387,8 +383,7 @@ test("saves overlay status when overlay-base analysis did not complete successfu
387383
388384test ( "does not save overlay status when OverlayAnalysisStatusSave feature flag is disabled" , async ( t ) => {
389385 return await util . withTmpDir ( async ( tmpDir ) => {
390- process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
391- process . env [ "RUNNER_TEMP" ] = tmpDir ;
386+ setupActionsVars ( tmpDir , tmpDir ) ;
392387 // Ensure analyze did not complete successfully.
393388 delete process . env [ EnvVar . ANALYZE_DID_COMPLETE_SUCCESSFULLY ] ;
394389
@@ -424,8 +419,7 @@ test("does not save overlay status when OverlayAnalysisStatusSave feature flag i
424419
425420test ( "does not save overlay status when build successful" , async ( t ) => {
426421 return await util . withTmpDir ( async ( tmpDir ) => {
427- process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
428- process . env [ "RUNNER_TEMP" ] = tmpDir ;
422+ setupActionsVars ( tmpDir , tmpDir ) ;
429423 // Mark analyze as having completed successfully.
430424 process . env [ EnvVar . ANALYZE_DID_COMPLETE_SUCCESSFULLY ] = "true" ;
431425
@@ -461,8 +455,7 @@ test("does not save overlay status when build successful", async (t) => {
461455
462456test ( "does not save overlay status when overlay not enabled" , async ( t ) => {
463457 return await util . withTmpDir ( async ( tmpDir ) => {
464- process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
465- process . env [ "RUNNER_TEMP" ] = tmpDir ;
458+ setupActionsVars ( tmpDir , tmpDir ) ;
466459 delete process . env [ EnvVar . ANALYZE_DID_COMPLETE_SUCCESSFULLY ] ;
467460
468461 sinon . stub ( util , "checkDiskUsage" ) . resolves ( {
@@ -547,9 +540,8 @@ async function testFailedSarifUpload(
547540 config . dbLocation = "path/to/database" ;
548541 }
549542 process . env [ "GITHUB_JOB" ] = "analyze" ;
550- process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
551- process . env [ "GITHUB_WORKSPACE" ] =
552- "/home/runner/work/codeql-action/codeql-action" ;
543+ process . env [ "GITHUB_REPOSITORY" ] = DEFAULT_ACTIONS_VARS . GITHUB_REPOSITORY ;
544+ process . env [ "GITHUB_WORKSPACE" ] = "/tmp" ;
553545 sinon
554546 . stub ( actionsUtil , "getRequiredInput" )
555547 . withArgs ( "matrix" )
0 commit comments