@@ -28,20 +28,7 @@ const requiredEnv = (name) => {
2828 return value ;
2929} ;
3030
31- /**
32- * @param {string } name
33- * @returns {string }
34- */
35- const envValueOrUnset = ( name ) => {
36- return process . env [ name ] ?. trim ( ) || "<unset>" ;
37- } ;
3831
39- const logActionSourceEnv = ( ) => {
40- core . info (
41- `GITHUB_ACTION_REPOSITORY=${ envValueOrUnset ( "GITHUB_ACTION_REPOSITORY" ) } ` ,
42- ) ;
43- core . info ( `GITHUB_ACTION_REF=${ envValueOrUnset ( "GITHUB_ACTION_REF" ) } ` ) ;
44- } ;
4532
4633/**
4734 * @returns {string }
@@ -152,32 +139,36 @@ const releaseTag = async (actionRepository, actionRef, githubToken) => {
152139 * @returns {Promise<{ url: string, headers: Record<string, string> }> }
153140 */
154141const releaseAssetRequest = async ( assetName , githubToken ) => {
155- // const actionRepository = requiredEnv("GITHUB_ACTION_REPOSITORY");
156- // const actionRef = requiredEnv("GITHUB_ACTION_REF");
157- const actionRepository = "sub60/cache-action" ;
158- const actionRef = "v0.0.2" ;
159- const tag = await releaseTag ( actionRepository , actionRef , githubToken ) ;
142+ const actionRepository =
143+ process . env . GITHUB_ACTION_REPOSITORY ?. trim ( ) || "sub60/cache-action" ;
144+
145+ // TODO: remove the fallback once the repo is public and local checkouts are
146+ // no longer needed.
147+ const actionRef = process . env . GITHUB_ACTION_REF ?. trim ( ) ;
160148
161149 if ( ! githubToken ) {
162- return {
163- url : `https://github.com/${ actionRepository } /releases/download/${ tag } /${ assetName } ` ,
164- headers : { } ,
165- } ;
150+ const base = `https://github.com/${ actionRepository } /releases` ;
151+ const url = actionRef
152+ ? `${ base } /download/${ await releaseTag ( actionRepository , actionRef , githubToken ) } /${ assetName } `
153+ : `${ base } /latest/download/${ assetName } ` ;
154+
155+ return { url, headers : { } } ;
166156 }
167157
168158 const apiUrl = requiredEnv ( "GITHUB_API_URL" ) ;
169159
170- const response = await fetch (
171- `${ apiUrl } /repos/${ actionRepository } /releases/tags/${ encodeURIComponent ( tag ) } ` ,
172- {
173- headers : githubApiHeaders ( githubToken ) ,
174- redirect : "follow" ,
175- } ,
176- ) ;
160+ const releaseUrl = actionRef
161+ ? `${ apiUrl } /repos/${ actionRepository } /releases/tags/${ encodeURIComponent ( await releaseTag ( actionRepository , actionRef , githubToken ) ) } `
162+ : `${ apiUrl } /repos/${ actionRepository } /releases/latest` ;
163+
164+ const response = await fetch ( releaseUrl , {
165+ headers : githubApiHeaders ( githubToken ) ,
166+ redirect : "follow" ,
167+ } ) ;
177168
178169 if ( ! response . ok ) {
179170 throw new Error (
180- `Failed to resolve release ' ${ tag } ' in '${ actionRepository } ': ${ response . status } ${ response . statusText } ` ,
171+ `Failed to resolve release in '${ actionRepository } ': ${ response . status } ${ response . statusText } ` ,
181172 ) ;
182173 }
183174
@@ -186,7 +177,7 @@ const releaseAssetRequest = async (assetName, githubToken) => {
186177
187178 if ( ! asset ) {
188179 throw new Error (
189- `Release '${ tag } ' in '${ actionRepository } ' does not contain asset '${ assetName } '` ,
180+ `Release '${ release . tag_name } ' in '${ actionRepository } ' does not contain asset '${ assetName } '` ,
190181 ) ;
191182 }
192183
@@ -332,8 +323,6 @@ const main = async () => {
332323 const configPath = path . join ( daemonDir , "nix.conf" ) ;
333324 const assetName = `${ binaryName } -${ target } ` ;
334325
335- logActionSourceEnv ( ) ;
336-
337326 const { url, headers } = await releaseAssetRequest ( assetName , githubToken ) ;
338327
339328 core . info ( `Downloading daemon '${ assetName } ' from '${ url } '` ) ;
0 commit comments