Compare commits

..

No commits in common. "87063ef0add0e22b68aefd914b1349a2ab0a94b1" and "092c6400ca064b42326d0c102bb683fb41eab38c" have entirely different histories.

7 changed files with 87 additions and 59 deletions

View File

@ -82,7 +82,8 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
node-version: [20-nightly, 21-nightly, 18.0.0-nightly]
node-version:
[20.11.0-nightly202312211a0be537da, 21-nightly, 18.0.0-nightly]
steps:
- uses: actions/checkout@v4
- name: Setup Node

View File

@ -13,6 +13,11 @@ 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 * as installerFactory from '../src/distributions/installer-factory';
jest.mock('../src/distributions/installer-factory', () => ({
getNodejsDistribution: jest.fn()
}));
import {validateMirrorURL} from '../src/util';
describe('main tests', () => {
@ -39,6 +44,8 @@ describe('main tests', () => {
let setupNodeJsSpy: jest.SpyInstance;
let validateMirrorUrlSpy: jest.SpyInstance;
beforeEach(() => {
inputs = {};
@ -166,6 +173,8 @@ describe('main tests', () => {
});
});
describe('node-version-file flag', () => {
beforeEach(() => {
delete inputs['node-version'];
@ -281,37 +290,6 @@ 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'] = ' ';
// Mock log and setFailed
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.'
);
});
});
});

View File

@ -831,7 +831,52 @@ describe('setup-node', () => {
);
});
describe('mirror-url parameter', () => {
it('default if mirror url is not provided', async () => {
it('Download mirror url if mirror-url is provided', async () => {
// Set up test inputs and environment
os.platform = 'linux';
os.arch = 'x64';
inputs['check-latest'] = 'true';
const mirrorURL = (inputs['mirror-url'] =
'https://custom-mirror-url.com');
inputs['token'] = 'faketoken';
// Mock that the version is not in cache (simulate a fresh download)
findSpy.mockImplementation(() => '');
// Mock implementations for other dependencies
const toolPath = path.normalize('/cache/node/11.11.0/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
const dlmirrorSpy = jest.fn(); // Create a spy to track the download logic
const mockDownloadNodejs = jest
.spyOn(OfficialBuilds.prototype as any, 'downloadFromMirrorURL')
.mockImplementation(async () => {
dlmirrorSpy();
});
// Run the main method or your logic that invokes `downloadFromMirrorURL`
await main.run(); // This should internally call `downloadFromMirrorURL`
// Prepare the expected path after download
const expPath = path.join(toolPath, 'bin');
// Assert that the spy was called, meaning the download logic was triggered
expect(dlmirrorSpy).toHaveBeenCalled(); // This verifies that the download occurred
// Other assertions to verify the flow
expect(exSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download from ${mirrorURL}...`
);
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
// Clean up mocks after the test
mockDownloadNodejs.mockRestore(); // Ensure to restore the original method after the test
});
it('fallback to default if mirror url is not provided', async () => {
os.platform = 'linux';
os.arch = 'x64';

20
dist/setup/index.js vendored
View File

@ -100165,13 +100165,16 @@ class BaseDistribution {
catch (err) {
if (err instanceof Error &&
err.message.includes('getaddrinfo EAI_AGAIN')) {
core.setFailed(`Network error: Failed to resolve the server at ${dataUrl}.Please check your DNS settings or verify that the URL is correct.`);
core.error(`Network error: Failed to resolve the server at ${dataUrl}.
Please check your DNS settings or verify that the URL is correct.`);
}
else if (err instanceof hc.HttpClientError && err.statusCode === 404) {
core.setFailed(`404 Error: Unable to find versions at ${dataUrl}.Please verify that the mirror URL is valid.`);
core.error(`404 Error: Unable to find versions at ${dataUrl}.
Please verify that the mirror URL is valid.`);
}
else {
core.setFailed(`Failed to fetch Node.js versions from ${dataUrl}.Please check the URL and try again.}`);
core.error(`Failed to fetch Node.js versions from ${dataUrl}.
Please check the URL and try again.}`);
}
throw err;
}
@ -100522,8 +100525,8 @@ class OfficialBuilds extends base_distribution_1.default {
}
}
catch (err) {
core.setFailed(err.message);
core.setFailed('Download failed');
core.info(err.message);
core.info('Download failed');
core.debug((_a = err.stack) !== null && _a !== void 0 ? _a : 'empty stack');
}
}
@ -100723,13 +100726,13 @@ 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. ` +
core.error(`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/. ' +
'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`);
core.error(`An unexpected error occurred like url might not correct`);
}
throw error;
}
@ -100867,7 +100870,8 @@ function run() {
if (!arch) {
arch = os_1.default.arch();
}
const mirrorURL = core.getInput('mirror-url');
const mirrorurl = core.getInput('mirror-url');
const mirrorURL = (0, util_1.validateMirrorURL)(mirrorurl);
if (version) {
const token = core.getInput('token');
const auth = !token ? undefined : `token ${token}`;

View File

@ -116,17 +116,14 @@ export default abstract class BaseDistribution {
err instanceof Error &&
err.message.includes('getaddrinfo EAI_AGAIN')
) {
core.setFailed(
`Network error: Failed to resolve the server at ${dataUrl}.Please check your DNS settings or verify that the URL is correct.`
);
core.error(`Network error: Failed to resolve the server at ${dataUrl}.
Please check your DNS settings or verify that the URL is correct.`);
} else if (err instanceof hc.HttpClientError && err.statusCode === 404) {
core.setFailed(
`404 Error: Unable to find versions at ${dataUrl}.Please verify that the mirror URL is valid.`
);
core.error(`404 Error: Unable to find versions at ${dataUrl}.
Please verify that the mirror URL is valid.`);
} else {
core.setFailed(
`Failed to fetch Node.js versions from ${dataUrl}.Please check the URL and try again.}`
);
core.error(`Failed to fetch Node.js versions from ${dataUrl}.
Please check the URL and try again.}`);
}
throw err;
}

View File

@ -26,8 +26,8 @@ export default class OfficialBuilds extends BaseDistribution {
const toolPath = downloadPath;
}
} catch (err) {
core.setFailed((err as Error).message);
core.setFailed('Download failed');
core.info((err as Error).message);
core.info('Download failed');
core.debug((err as Error).stack ?? 'empty stack');
}
} else {
@ -334,16 +334,14 @@ export default class OfficialBuilds extends BaseDistribution {
return toolPath;
} catch (error) {
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
core.setFailed(
core.error(
`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/. ' +
'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`
);
core.error(`An unexpected error occurred like url might not correct`);
}
throw error;

View File

@ -7,7 +7,11 @@ import * as path from 'path';
import {restoreCache} from './cache-restore';
import {isCacheFeatureAvailable} from './cache-utils';
import {getNodejsDistribution} from './distributions/installer-factory';
import {getNodeVersionFromFile, printEnvDetailsAndSetOutput} from './util';
import {
getNodeVersionFromFile,
printEnvDetailsAndSetOutput,
validateMirrorURL
} from './util';
import {State} from './constants';
export async function run() {
@ -33,7 +37,8 @@ export async function run() {
arch = os.arch();
}
const mirrorURL = core.getInput('mirror-url');
const mirrorurl = core.getInput('mirror-url');
const mirrorURL = validateMirrorURL(mirrorurl);
if (version) {
const token = core.getInput('token');