@@ -88,6 +88,33 @@ 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_SHA" ] = currentSha ;
98+
99+ const actualRef = await actionsutil . getRef ( ) ;
100+ t . deepEqual ( actualRef , expectedRef ) ;
101+ } ) ;
102+ } ) ;
103+
104+ test ( "getRef() returns GITHUB_REF over CODE_SCANNING_REF if both are provided" , async ( t ) => {
105+ await withTmpDir ( async ( tmpDir : string ) => {
106+ setupActionsVars ( tmpDir , tmpDir ) ;
107+ const expectedRef = "refs/pull/1/merge" ;
108+ const currentSha = "a" . repeat ( 40 ) ;
109+ process . env [ "CODE_SCANNING_REF" ] = "refs/pull/1/HEAD" ;
110+ process . env [ "GITHUB_REF" ] = expectedRef ;
111+ process . env [ "GITHUB_SHA" ] = currentSha ;
112+
113+ const actualRef = await actionsutil . getRef ( ) ;
114+ t . deepEqual ( actualRef , expectedRef ) ;
115+ } ) ;
116+ } ) ;
117+
91118test ( "getRef() throws an error if only `ref` is provided as an input" , async ( t ) => {
92119 await withTmpDir ( async ( tmpDir : string ) => {
93120 setupActionsVars ( tmpDir , tmpDir ) ;
0 commit comments