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 16 commits into
base: main
Choose a base branch
from
Open
3 changes: 1 addition & 2 deletions .github/workflows/versions.yml
Original file line number Diff line number Diff line change
@@ -82,8 +82,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
node-version:
[20.11.0-nightly202312211a0be537da, 21-nightly, 18.0.0-nightly]
node-version: [20-nightly, 21-nightly, 18.0.0-nightly]
steps:
- uses: actions/checkout@v4
- name: Setup Node
33 changes: 33 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import each from 'jest-each';
import * as main from '../src/main';
import * as util from '../src/util';
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
import {validateMirrorURL} from '../src/util';

describe('main tests', () => {
let inputs = {} as any;
@@ -280,4 +281,36 @@ describe('main tests', () => {
);
});
});
describe('mirror-url parameter', () => {
beforeEach(() => {
inputs['mirror-url'] = 'https://custom-mirror-url.com';
});

afterEach(() => {
delete inputs['mirror-url'];
});

it('Read mirror-url if mirror-url is provided', async () => {
// Arrange
inputs['mirror-url'] = 'https://custom-mirror-url.com';

// Act
await main.run();

// Assert
expect(inputs['mirror-url']).toBeDefined();
});

it('should throw an error if mirror-url is empty', async () => {
// Arrange
inputs['mirror-url'] = ' ';

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

// Act & Assert
expect(() => validateMirrorURL(inputs['mirror-url'])).toThrow(
'Mirror URL is empty. Please provide a valid mirror URL.'
);
});
});
});
33 changes: 33 additions & 0 deletions __tests__/official-installer.test.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ import osm from 'os';
import path from 'path';
import * as main from '../src/main';
import * as auth from '../src/authutil';
import isLtsAlias from '../src/distributions/official_builds/official_builds';

import OfficialBuilds from '../src/distributions/official_builds/official_builds';
import {INodeVersion} from '../src/distributions/base-models';

@@ -828,4 +830,35 @@ describe('setup-node', () => {
}
);
});
describe('mirror-url parameter', () => {
it('default if mirror url is not provided', async () => {
os.platform = 'linux';
os.arch = 'x64';

inputs['node-version'] = '11';
inputs['check-latest'] = 'true';
inputs['always-auth'] = false;
inputs['token'] = 'faketoken';

dlSpy.mockImplementation(async () => '/some/temp/path');
const toolPath = path.normalize('/cache/node/12.11.0/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);

const dlmirrorSpy = jest.fn();
dlmirrorSpy.mockImplementation(async () => 'mocked-download-path');
await main.run();

const expPath = path.join(toolPath, 'bin');

expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();

expect(logSpy).toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...'
);

expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
});
});
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@ inputs:
default: false
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'
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/).'
token:
11 changes: 10 additions & 1 deletion dist/cache-save/index.js
Original file line number Diff line number Diff line change
@@ -91098,7 +91098,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
exports.unique = exports.validateMirrorURL = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const io = __importStar(__nccwpck_require__(7436));
@@ -91186,6 +91186,15 @@ function getToolVersion(tool, options) {
}
});
}
function validateMirrorURL(mirrorURL) {
if (mirrorURL === ' ' || mirrorURL.trim() === 'undefined') {
throw new Error('Mirror URL is empty. Please provide a valid mirror URL.');
}
else {
return mirrorURL;
}
}
exports.validateMirrorURL = validateMirrorURL;
const unique = () => {
const encountered = new Set();
return (value) => {
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.