@@ -40,8 +40,21 @@ axiosRetry(axios, {
4040
4141async function downloadNodeBinary ( platform , arch , maxRetries = 3 ) {
4242 try {
43+ console . log ( "fetching release details...." ) ;
44+
4345 const url = 'https://api.github.com/repos/phcode-dev/phnode/releases/latest' ;
44- const releaseResponse = await axios . get ( url ) ;
46+ const GH_TOKEN = process . env . GH_TOKEN ; // Access the environment variable
47+ // Only add the Authorization header if GH_TOKEN is set
48+ let headers = { } ;
49+ if ( GH_TOKEN ) {
50+ console . log ( "Using GH_TOKEN passed in from github actions." ) ;
51+ headers = {
52+ 'Authorization' : `Bearer ${ GH_TOKEN } `
53+ } ;
54+ } else {
55+ console . warn ( "GH_TOKEN not passed in from github actions, using unauthorized fetch for ." , url ) ;
56+ }
57+ const releaseResponse = await axios . get ( url , { headers } ) ;
4558 const extension = platform === 'win' ? 'zip' : 'tar.gz' ;
4659 const regex = new RegExp ( `node-v[\\d.]+-${ platform } -${ arch } \\.${ extension } ` ) ;
4760 const asset = releaseResponse . data . assets . find ( a => regex . test ( a . name ) ) ;
@@ -50,14 +63,15 @@ async function downloadNodeBinary(platform, arch, maxRetries = 3) {
5063 throw new Error ( `No asset found for platform: ${ platform } , arch: ${ arch } ` ) ;
5164 }
5265
66+ console . log ( "fetching asset " , asset ) ;
67+
5368 const outputPath = path . resolve ( __dirname , asset . name ) ;
5469 if ( fs . existsSync ( outputPath ) ) {
5570 console . log ( `File already downloaded: ${ asset . name } ` ) ;
5671 return asset . name ;
5772 }
5873
5974 const writer = fs . createWriteStream ( outputPath ) ;
60- const GH_TOKEN = process . env . GH_TOKEN ; // Access the environment variable
6175 const config = {
6276 url : asset . browser_download_url ,
6377 method : 'GET' ,
@@ -71,7 +85,7 @@ async function downloadNodeBinary(platform, arch, maxRetries = 3) {
7185 'Authorization' : `Bearer ${ GH_TOKEN } `
7286 } ;
7387 } else {
74- console . warn ( "GH_TOKEN not passed in from github actions, using unauthorized fetch." ) ;
88+ console . warn ( "GH_TOKEN not passed in from github actions, using unauthorized fetch for" , config . url ) ;
7589 }
7690
7791 const { data } = await axios ( config ) ;
0 commit comments