Compare commits

..

2 Commits

Author SHA1 Message Date
Marco Ippolito
018279a706
Merge b431a178ef into 802632921f 2025-03-07 12:58:01 +00:00
Marco Ippolito
b431a178ef
feat: support private mirrors 2025-03-07 13:57:53 +01:00
3 changed files with 35 additions and 12 deletions

View File

@ -449,7 +449,7 @@ describe('setup-node', () => {
} }
}, 100000); }, 100000);
it('acquires specified architecture of node', async () => { it('acquires specified architecture of node from mirror', async () => {
for (const {arch, version, osSpec} of [ for (const {arch, version, osSpec} of [
{ {
arch: 'x86', arch: 'x86',

View File

@ -106,7 +106,10 @@ export default abstract class BaseDistribution {
headers['Authorization'] = `Bearer ${this.nodeInfo.mirrorToken}`; headers['Authorization'] = `Bearer ${this.nodeInfo.mirrorToken}`;
} }
const response = await this.httpClient.getJson<INodeVersion[]>(dataUrl, headers); const response = await this.httpClient.getJson<INodeVersion[]>(
dataUrl,
headers
);
return response.result || []; return response.result || [];
} }
@ -140,7 +143,11 @@ export default abstract class BaseDistribution {
`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}` `Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`
); );
try { try {
downloadPath = await tc.downloadTool(info.downloadUrl, undefined, this.nodeInfo.mirrorToken); downloadPath = await tc.downloadTool(
info.downloadUrl,
undefined,
this.nodeInfo.mirrorToken
);
} catch (err) { } catch (err) {
if ( if (
err instanceof tc.HTTPError && err instanceof tc.HTTPError &&
@ -191,18 +198,34 @@ export default abstract class BaseDistribution {
core.info(`Downloading only node binary from ${exeUrl}`); core.info(`Downloading only node binary from ${exeUrl}`);
const exePath = await tc.downloadTool(exeUrl, undefined, this.nodeInfo.mirrorToken); const exePath = await tc.downloadTool(
exeUrl,
undefined,
this.nodeInfo.mirrorToken
);
await io.cp(exePath, path.join(tempDir, 'node.exe')); await io.cp(exePath, path.join(tempDir, 'node.exe'));
const libPath = await tc.downloadTool(libUrl, undefined, this.nodeInfo.mirrorToken); const libPath = await tc.downloadTool(
libUrl,
undefined,
this.nodeInfo.mirrorToken
);
await io.cp(libPath, path.join(tempDir, 'node.lib')); await io.cp(libPath, path.join(tempDir, 'node.lib'));
} catch (err) { } catch (err) {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) { if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
exeUrl = `${initialUrl}/v${version}/node.exe`; exeUrl = `${initialUrl}/v${version}/node.exe`;
libUrl = `${initialUrl}/v${version}/node.lib`; libUrl = `${initialUrl}/v${version}/node.lib`;
const exePath = await tc.downloadTool(exeUrl, undefined, this.nodeInfo.mirrorToken); const exePath = await tc.downloadTool(
exeUrl,
undefined,
this.nodeInfo.mirrorToken
);
await io.cp(exePath, path.join(tempDir, 'node.exe')); await io.cp(exePath, path.join(tempDir, 'node.exe'));
const libPath = await tc.downloadTool(libUrl, undefined, this.nodeInfo.mirrorToken); const libPath = await tc.downloadTool(
libUrl,
undefined,
this.nodeInfo.mirrorToken
);
await io.cp(libPath, path.join(tempDir, 'node.lib')); await io.cp(libPath, path.join(tempDir, 'node.lib'));
} else { } else {
throw err; throw err;