Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mirror-url parameter to allow downloading Node.js from a custom URL #1232

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
improvements
  • Loading branch information
aparnajyothi-y committed Mar 4, 2025
commit f3381893337bb7cd0d7fef631f22adbced87fce4
1 change: 0 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -305,7 +305,6 @@ describe('main tests', () => {
// Arrange
inputs['mirror-url'] = ' ';

// Mock log and setFailed
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); // Mock the log function

// Act & Assert
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ inputs:
registry-url:
description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN.'
mirror-url:
description: 'Custom mirror URL to download Node.js from (optional)'
description: 'Custom mirror URL to download Node.js'
required: false
scope:
description: 'Optional scope for authenticating against scoped registries. Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/).'
12 changes: 4 additions & 8 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
@@ -100510,17 +100510,14 @@ class OfficialBuilds extends base_distribution_1.default {
}
setupNodeJs() {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
var _a;
if (this.nodeInfo.mirrorURL) {
let downloadPath = '';
try {
core.info(`Attempting to download using mirror URL...`);
downloadPath = yield this.downloadFromMirrorURL(); // Attempt to download from the mirror
yield this.downloadFromMirrorURL(); // Attempt to download from the mirror
}
catch (err) {
core.setFailed(err.message);
core.setFailed('Download failed');
core.debug((_a = err.stack) !== null && _a !== void 0 ? _a : 'empty stack');
}
}
else {
@@ -100581,7 +100578,7 @@ class OfficialBuilds extends base_distribution_1.default {
else {
core.info(err.message);
}
core.debug((_b = err.stack) !== null && _b !== void 0 ? _b : 'empty stack');
core.debug((_a = err.stack) !== null && _a !== void 0 ? _a : 'empty stack');
core.info('Falling back to download directly from Node');
}
if (!toolPath) {
@@ -100719,11 +100716,10 @@ class OfficialBuilds extends base_distribution_1.default {
catch (error) {
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
core.setFailed(`Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` +
'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
'This usually happens when downloadable binaries are not fully updated in the provided mirror-url' +
'To resolve this issue you may either fall back to the older version or try again later.');
}
else {
// For any other error type, you can log the error message.
core.setFailed(`An unexpected error occurred like url might not correct`);
}
throw error;
9 changes: 2 additions & 7 deletions src/distributions/official_builds/official_builds.ts
Original file line number Diff line number Diff line change
@@ -16,15 +16,11 @@ export default class OfficialBuilds extends BaseDistribution {

public async setupNodeJs() {
if (this.nodeInfo.mirrorURL) {
let downloadPath = '';

try {
core.info(`Attempting to download using mirror URL...`);
downloadPath = await this.downloadFromMirrorURL(); // Attempt to download from the mirror
await this.downloadFromMirrorURL(); // Attempt to download from the mirror
} catch (err) {
core.setFailed((err as Error).message);
core.setFailed('Download failed');
core.debug((err as Error).stack ?? 'empty stack');
}
} else {
core.info('Setup Node.js');
@@ -331,11 +327,10 @@ export default class OfficialBuilds extends BaseDistribution {
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
core.setFailed(
`Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` +
'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
'This usually happens when downloadable binaries are not fully updated in the provided mirror-url' +
'To resolve this issue you may either fall back to the older version or try again later.'
);
} else {
// For any other error type, you can log the error message.
core.setFailed(
`An unexpected error occurred like url might not correct`
);
Loading
Oops, something went wrong.