@@ -88,6 +88,34 @@ test("getRef() returns ref provided as an input and ignores current HEAD", async
8888 } ) ;
8989} ) ;
9090
91+ test ( "getRef() returns CODE_SCANNING_REF as a fallback for GITHUB_REF" , async ( t ) => {
92+ await withTmpDir ( async ( tmpDir : string ) => {
93+ setupActionsVars ( tmpDir , tmpDir ) ;
94+ const expectedRef = "refs/pull/1/HEAD" ;
95+ const currentSha = "a" . repeat ( 40 ) ;
96+ process . env [ "CODE_SCANNING_REF" ] = expectedRef ;
97+ process . env [ "GITHUB_REF" ] = "" ;
98+ process . env [ "GITHUB_SHA" ] = currentSha ;
99+
100+ const actualRef = await actionsutil . getRef ( ) ;
101+ t . deepEqual ( actualRef , expectedRef ) ;
102+ } ) ;
103+ } ) ;
104+
105+ test ( "getRef() returns GITHUB_REF over CODE_SCANNING_REF if both are provided" , async ( t ) => {
106+ await withTmpDir ( async ( tmpDir : string ) => {
107+ setupActionsVars ( tmpDir , tmpDir ) ;
108+ const expectedRef = "refs/pull/1/merge" ;
109+ const currentSha = "a" . repeat ( 40 ) ;
110+ process . env [ "CODE_SCANNING_REF" ] = "refs/pull/1/HEAD" ;
111+ process . env [ "GITHUB_REF" ] = expectedRef ;
112+ process . env [ "GITHUB_SHA" ] = currentSha ;
113+
114+ const actualRef = await actionsutil . getRef ( ) ;
115+ t . deepEqual ( actualRef , expectedRef ) ;
116+ } ) ;
117+ } ) ;
118+
91119test ( "getRef() throws an error if only `ref` is provided as an input" , async ( t ) => {
92120 await withTmpDir ( async ( tmpDir : string ) => {
93121 setupActionsVars ( tmpDir , tmpDir ) ;
0 commit comments