mirror of
https://github.com/actions/setup-node.git
synced 2026-03-07 06:51:46 +08:00
Compare commits
8 Commits
ffa588c6cf
...
ef2587e452
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef2587e452 | ||
|
|
87063ef0ad | ||
|
|
5d5d8e9b58 | ||
|
|
30c33f0409 | ||
|
|
a4f5538cea | ||
|
|
dd2fa9d9f8 | ||
|
|
d61dc50c40 | ||
|
|
b903bc8693 |
3
.github/workflows/versions.yml
vendored
3
.github/workflows/versions.yml
vendored
@ -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
|
||||
|
||||
@ -13,11 +13,6 @@ 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', () => {
|
||||
@ -44,8 +39,6 @@ describe('main tests', () => {
|
||||
|
||||
let setupNodeJsSpy: jest.SpyInstance;
|
||||
|
||||
let validateMirrorUrlSpy: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
inputs = {};
|
||||
|
||||
@ -173,8 +166,6 @@ describe('main tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('node-version-file flag', () => {
|
||||
beforeEach(() => {
|
||||
delete inputs['node-version'];
|
||||
@ -290,6 +281,37 @@ 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.'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -831,52 +831,7 @@ describe('setup-node', () => {
|
||||
);
|
||||
});
|
||||
describe('mirror-url parameter', () => {
|
||||
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 () => {
|
||||
it('default if mirror url is not provided', async () => {
|
||||
os.platform = 'linux';
|
||||
os.arch = 'x64';
|
||||
|
||||
|
||||
20
dist/setup/index.js
vendored
20
dist/setup/index.js
vendored
@ -100165,16 +100165,13 @@ class BaseDistribution {
|
||||
catch (err) {
|
||||
if (err instanceof Error &&
|
||||
err.message.includes('getaddrinfo EAI_AGAIN')) {
|
||||
core.error(`Network error: Failed to resolve the server at ${dataUrl}.
|
||||
Please check your DNS settings or verify that the URL is correct.`);
|
||||
core.setFailed(`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.error(`404 Error: Unable to find versions at ${dataUrl}.
|
||||
Please verify that the mirror URL is valid.`);
|
||||
core.setFailed(`404 Error: Unable to find versions at ${dataUrl}.Please verify that the mirror URL is valid.`);
|
||||
}
|
||||
else {
|
||||
core.error(`Failed to fetch Node.js versions from ${dataUrl}.
|
||||
Please check the URL and try again.}`);
|
||||
core.setFailed(`Failed to fetch Node.js versions from ${dataUrl}.Please check the URL and try again.}`);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
@ -100525,8 +100522,8 @@ class OfficialBuilds extends base_distribution_1.default {
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
core.info(err.message);
|
||||
core.info('Download failed');
|
||||
core.setFailed(err.message);
|
||||
core.setFailed('Download failed');
|
||||
core.debug((_a = err.stack) !== null && _a !== void 0 ? _a : 'empty stack');
|
||||
}
|
||||
}
|
||||
@ -100726,13 +100723,13 @@ class OfficialBuilds extends base_distribution_1.default {
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
|
||||
core.error(`Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` +
|
||||
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/. ' +
|
||||
'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.error(`An unexpected error occurred like url might not correct`);
|
||||
core.setFailed(`An unexpected error occurred like url might not correct`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
@ -100870,8 +100867,7 @@ function run() {
|
||||
if (!arch) {
|
||||
arch = os_1.default.arch();
|
||||
}
|
||||
const mirrorurl = core.getInput('mirror-url');
|
||||
const mirrorURL = (0, util_1.validateMirrorURL)(mirrorurl);
|
||||
const mirrorURL = core.getInput('mirror-url');
|
||||
if (version) {
|
||||
const token = core.getInput('token');
|
||||
const auth = !token ? undefined : `token ${token}`;
|
||||
|
||||
@ -116,14 +116,17 @@ export default abstract class BaseDistribution {
|
||||
err instanceof Error &&
|
||||
err.message.includes('getaddrinfo EAI_AGAIN')
|
||||
) {
|
||||
core.error(`Network error: Failed to resolve the server at ${dataUrl}.
|
||||
Please check your DNS settings or verify that the URL is correct.`);
|
||||
core.setFailed(
|
||||
`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.error(`404 Error: Unable to find versions at ${dataUrl}.
|
||||
Please verify that the mirror URL is valid.`);
|
||||
core.setFailed(
|
||||
`404 Error: Unable to find versions at ${dataUrl}.Please verify that the mirror URL is valid.`
|
||||
);
|
||||
} else {
|
||||
core.error(`Failed to fetch Node.js versions from ${dataUrl}.
|
||||
Please check the URL and try again.}`);
|
||||
core.setFailed(
|
||||
`Failed to fetch Node.js versions from ${dataUrl}.Please check the URL and try again.}`
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
@ -26,8 +26,8 @@ export default class OfficialBuilds extends BaseDistribution {
|
||||
const toolPath = downloadPath;
|
||||
}
|
||||
} catch (err) {
|
||||
core.info((err as Error).message);
|
||||
core.info('Download failed');
|
||||
core.setFailed((err as Error).message);
|
||||
core.setFailed('Download failed');
|
||||
core.debug((err as Error).stack ?? 'empty stack');
|
||||
}
|
||||
} else {
|
||||
@ -334,14 +334,16 @@ export default class OfficialBuilds extends BaseDistribution {
|
||||
return toolPath;
|
||||
} catch (error) {
|
||||
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
|
||||
core.error(
|
||||
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/. ' +
|
||||
'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.error(`An unexpected error occurred like url might not correct`);
|
||||
core.setFailed(
|
||||
`An unexpected error occurred like url might not correct`
|
||||
);
|
||||
}
|
||||
|
||||
throw error;
|
||||
|
||||
@ -7,11 +7,7 @@ import * as path from 'path';
|
||||
import {restoreCache} from './cache-restore';
|
||||
import {isCacheFeatureAvailable} from './cache-utils';
|
||||
import {getNodejsDistribution} from './distributions/installer-factory';
|
||||
import {
|
||||
getNodeVersionFromFile,
|
||||
printEnvDetailsAndSetOutput,
|
||||
validateMirrorURL
|
||||
} from './util';
|
||||
import {getNodeVersionFromFile, printEnvDetailsAndSetOutput} from './util';
|
||||
import {State} from './constants';
|
||||
|
||||
export async function run() {
|
||||
@ -37,8 +33,7 @@ export async function run() {
|
||||
arch = os.arch();
|
||||
}
|
||||
|
||||
const mirrorurl = core.getInput('mirror-url');
|
||||
const mirrorURL = validateMirrorURL(mirrorurl);
|
||||
const mirrorURL = core.getInput('mirror-url');
|
||||
|
||||
if (version) {
|
||||
const token = core.getInput('token');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user