@@ -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
@@ -374,9 +370,9 @@ test("saves overlay status when overlay-base analysis did not complete successfu
374370 attemptedToBuildOverlayBaseDatabase : true ,
375371 builtOverlayBaseDatabase : false ,
376372 job : {
377- workflowRunId : 12345 ,
378- workflowRunAttempt : 1 ,
379- name : "analyze" ,
373+ workflowRunId : Number ( DEFAULT_ACTIONS_VARS . GITHUB_RUN_ID ) ,
374+ workflowRunAttempt : Number ( DEFAULT_ACTIONS_VARS . GITHUB_RUN_ATTEMPT ) ,
375+ name : DEFAULT_ACTIONS_VARS . GITHUB_JOB ,
380376 } ,
381377 } ,
382378 "fourth arg should be the overlay status recording an unsuccessful build attempt with job details" ,
@@ -386,8 +382,7 @@ test("saves overlay status when overlay-base analysis did not complete successfu
386382
387383test ( "does not save overlay status when OverlayAnalysisStatusSave feature flag is disabled" , async ( t ) => {
388384 return await util . withTmpDir ( async ( tmpDir ) => {
389- process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
390- process . env [ "RUNNER_TEMP" ] = tmpDir ;
385+ setupActionsVars ( tmpDir , tmpDir ) ;
391386 // Ensure analyze did not complete successfully.
392387 delete process . env [ EnvVar . ANALYZE_DID_COMPLETE_SUCCESSFULLY ] ;
393388
@@ -423,8 +418,7 @@ test("does not save overlay status when OverlayAnalysisStatusSave feature flag i
423418
424419test ( "does not save overlay status when build successful" , async ( t ) => {
425420 return await util . withTmpDir ( async ( tmpDir ) => {
426- process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
427- process . env [ "RUNNER_TEMP" ] = tmpDir ;
421+ setupActionsVars ( tmpDir , tmpDir ) ;
428422 // Mark analyze as having completed successfully.
429423 process . env [ EnvVar . ANALYZE_DID_COMPLETE_SUCCESSFULLY ] = "true" ;
430424
@@ -460,8 +454,7 @@ test("does not save overlay status when build successful", async (t) => {
460454
461455test ( "does not save overlay status when overlay not enabled" , async ( t ) => {
462456 return await util . withTmpDir ( async ( tmpDir ) => {
463- process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
464- process . env [ "RUNNER_TEMP" ] = tmpDir ;
457+ setupActionsVars ( tmpDir , tmpDir ) ;
465458 delete process . env [ EnvVar . ANALYZE_DID_COMPLETE_SUCCESSFULLY ] ;
466459
467460 sinon . stub ( util , "checkDiskUsage" ) . resolves ( {
@@ -546,9 +539,8 @@ async function testFailedSarifUpload(
546539 config . dbLocation = "path/to/database" ;
547540 }
548541 process . env [ "GITHUB_JOB" ] = "analyze" ;
549- process . env [ "GITHUB_REPOSITORY" ] = "github/codeql-action-fake-repository" ;
550- process . env [ "GITHUB_WORKSPACE" ] =
551- "/home/runner/work/codeql-action/codeql-action" ;
542+ process . env [ "GITHUB_REPOSITORY" ] = DEFAULT_ACTIONS_VARS . GITHUB_REPOSITORY ;
543+ process . env [ "GITHUB_WORKSPACE" ] = "/tmp" ;
552544 sinon
553545 . stub ( actionsUtil , "getRequiredInput" )
554546 . withArgs ( "matrix" )
0 commit comments