Skip to content

Commit 0bad5f1

Browse files
committed
fix: github token not passed in for fetch release details API
1 parent 29be46e commit 0bad5f1

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src-build/downloadNodeBinary.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,21 @@ axiosRetry(axios, {
4040

4141
async 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

Comments
 (0)