mirror of
https://github.com/actions/setup-node.git
synced 2026-03-07 06:51:46 +08:00
Compare commits
No commits in common. "6a4f7710a513cebdbe001321a037afa0eb91d87e" and "17e88b6567a695a8cbc81e185dcff21c890e168a" have entirely different histories.
6a4f7710a5
...
17e88b6567
@ -10,15 +10,13 @@ import osm from 'os';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as main from '../src/main';
|
import * as main from '../src/main';
|
||||||
import * as auth from '../src/authutil';
|
import * as auth from '../src/authutil';
|
||||||
import {INodeVersion, NodeInputs} from '../src/distributions/base-models';
|
import {INodeVersion} from '../src/distributions/base-models';
|
||||||
|
|
||||||
import nodeTestManifest from './data/versions-manifest.json';
|
import nodeTestManifest from './data/versions-manifest.json';
|
||||||
import nodeTestDist from './data/node-dist-index.json';
|
import nodeTestDist from './data/node-dist-index.json';
|
||||||
import nodeTestDistNightly from './data/node-nightly-index.json';
|
import nodeTestDistNightly from './data/node-nightly-index.json';
|
||||||
import nodeTestDistRc from './data/node-rc-index.json';
|
import nodeTestDistRc from './data/node-rc-index.json';
|
||||||
import nodeV8CanaryTestDist from './data/v8-canary-dist-index.json';
|
import nodeV8CanaryTestDist from './data/v8-canary-dist-index.json';
|
||||||
import canaryBuild from '../src/distributions/v8-canary/canary_builds';
|
|
||||||
|
|
||||||
|
|
||||||
describe('setup-node', () => {
|
describe('setup-node', () => {
|
||||||
let inputs = {} as any;
|
let inputs = {} as any;
|
||||||
@ -530,161 +528,4 @@ describe('setup-node', () => {
|
|||||||
expect(cacheSpy).not.toHaveBeenCalled();
|
expect(cacheSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('CanaryBuild - Mirror URL functionality', () => {
|
|
||||||
|
|
||||||
|
|
||||||
class CanaryBuild {
|
|
||||||
mirrorURL: string | undefined;
|
|
||||||
nodeInfo: NodeInputs;
|
|
||||||
|
|
||||||
constructor(nodeInfo: NodeInputs) {
|
|
||||||
this.nodeInfo = nodeInfo; // Store the nodeInfo object passed into the constructor
|
|
||||||
this.mirrorURL = nodeInfo.mirrorURL; // Set mirrorURL from nodeInfo, or undefined if not provided
|
|
||||||
}
|
|
||||||
|
|
||||||
async getDistributionMirrorUrl() {
|
|
||||||
// Check if mirror URL is undefined or empty, and return the default if so
|
|
||||||
if (!this.mirrorURL) {
|
|
||||||
core.info('Using mirror URL: https://nodejs.org/download/v8-canary');
|
|
||||||
return 'https://nodejs.org/download/v8-canary'; // Default URL
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log and return the custom mirror URL
|
|
||||||
core.info(`Using mirror URL: ${this.mirrorURL}`);
|
|
||||||
return this.mirrorURL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
it('should use the mirror URL from nodeInfo if provided', () => {
|
|
||||||
// Mocking core.info to track the log calls
|
|
||||||
const infoSpy = jest.spyOn(core, 'info').mockImplementation(() => {});
|
|
||||||
|
|
||||||
const mirrorURL = 'https://custom.mirror.url/v8-canary';
|
|
||||||
const nodeInfo: NodeInputs = {
|
|
||||||
versionSpec: '8.0.0-canary',
|
|
||||||
arch: 'x64',
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false,
|
|
||||||
mirrorURL: mirrorURL // Provide the custom mirror URL
|
|
||||||
};
|
|
||||||
|
|
||||||
const canaryBuild = new CanaryBuild(nodeInfo);
|
|
||||||
|
|
||||||
// Call the method to get the mirror URL
|
|
||||||
const distributionMirrorUrl = canaryBuild.getDistributionMirrorUrl();
|
|
||||||
|
|
||||||
// Assert that core.info was called with the custom mirror URL
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(`Using mirror URL: ${mirrorURL}`);
|
|
||||||
|
|
||||||
// Assert that the returned URL is the custom mirror URL
|
|
||||||
expect(distributionMirrorUrl).toBe(mirrorURL);
|
|
||||||
|
|
||||||
// Restore the original core.info implementation
|
|
||||||
infoSpy.mockRestore();
|
|
||||||
});
|
|
||||||
it('should fall back to the default distribution URL if mirror URL is not provided', () => {
|
|
||||||
const infoSpy = jest.spyOn(core, 'info').mockImplementation(() => {});
|
|
||||||
|
|
||||||
const nodeInfo: NodeInputs = {
|
|
||||||
versionSpec: '8.0.0-canary',
|
|
||||||
arch: 'x64',
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false
|
|
||||||
// No mirrorURL provided here
|
|
||||||
};
|
|
||||||
|
|
||||||
const canaryBuild = new CanaryBuild(nodeInfo);
|
|
||||||
|
|
||||||
// Call the method to get the distribution URL
|
|
||||||
const distributionMirrorUrl = canaryBuild.getDistributionMirrorUrl();
|
|
||||||
|
|
||||||
// Assert that core.info was called with the default URL
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith('Using mirror URL: https://nodejs.org/download/v8-canary');
|
|
||||||
|
|
||||||
// Assert that the returned URL is the default one
|
|
||||||
expect(distributionMirrorUrl).toBe('https://nodejs.org/download/v8-canary');
|
|
||||||
|
|
||||||
infoSpy.mockRestore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should log the correct info when mirror URL is not provided', () => {
|
|
||||||
const infoSpy = jest.spyOn(core, 'info').mockImplementation(() => {});
|
|
||||||
|
|
||||||
const nodeInfo: NodeInputs = {
|
|
||||||
versionSpec: '8.0.0-canary',
|
|
||||||
arch: 'x64',
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false
|
|
||||||
// No mirrorURL provided here
|
|
||||||
};
|
|
||||||
|
|
||||||
const canaryBuild = new CanaryBuild(nodeInfo);
|
|
||||||
|
|
||||||
// Call the method
|
|
||||||
canaryBuild.getDistributionMirrorUrl();
|
|
||||||
|
|
||||||
// Assert that core.info was called with the fallback URL
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith('Using mirror URL: https://nodejs.org/download/v8-canary');
|
|
||||||
|
|
||||||
infoSpy.mockRestore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return mirror URL if provided in nodeInfo', () => {
|
|
||||||
// Custom mirror URL to be tested
|
|
||||||
const mirrorURL = 'https://custom.mirror.url/v8-canary';
|
|
||||||
|
|
||||||
// Create a spy on core.info to track its calls
|
|
||||||
const infoSpy = jest.spyOn(core, 'info').mockImplementation(() => {}); // Mocking core.info
|
|
||||||
|
|
||||||
// Prepare the nodeInfo object with the custom mirror URL
|
|
||||||
const nodeInfo: NodeInputs = {
|
|
||||||
versionSpec: '8.0.0-canary',
|
|
||||||
arch: 'x64',
|
|
||||||
mirrorURL: mirrorURL, // Custom mirrorURL provided
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create an instance of CanaryBuild, passing nodeInfo to the constructor
|
|
||||||
const canaryBuild = new CanaryBuild(nodeInfo);
|
|
||||||
|
|
||||||
// Call the method
|
|
||||||
const distributionMirrorUrl = canaryBuild.getDistributionMirrorUrl();
|
|
||||||
|
|
||||||
// Assert that core.info was called with the expected message
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(`Using mirror URL: ${mirrorURL}`);
|
|
||||||
|
|
||||||
// Assert that the returned mirror URL is correct
|
|
||||||
expect(distributionMirrorUrl).toBe(mirrorURL);
|
|
||||||
|
|
||||||
// Restore the original core.info function after the test
|
|
||||||
infoSpy.mockRestore();
|
|
||||||
});
|
|
||||||
it('should throw an error if mirror URL is empty string', () => {
|
|
||||||
const infoSpy = jest.spyOn(core, 'info').mockImplementation(() => {});
|
|
||||||
|
|
||||||
const nodeInfo: NodeInputs = {
|
|
||||||
versionSpec: '8.0.0-canary',
|
|
||||||
arch: 'x64',
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false,
|
|
||||||
mirrorURL: '' // Empty string provided as mirror URL
|
|
||||||
};
|
|
||||||
|
|
||||||
const canaryBuild = new CanaryBuild(nodeInfo);
|
|
||||||
|
|
||||||
// Expect the method to throw an error for empty string mirror URL
|
|
||||||
expect(() => canaryBuild.getDistributionMirrorUrl()).toThrowError('Mirror URL is empty. Please provide a valid mirror URL.');
|
|
||||||
|
|
||||||
// Ensure that core.info was not called because the error was thrown first
|
|
||||||
expect(infoSpy).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
infoSpy.mockRestore();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import 'jest';
|
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
@ -15,11 +14,6 @@ import * as main from '../src/main';
|
|||||||
import * as util from '../src/util';
|
import * as util from '../src/util';
|
||||||
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
|
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()
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('main tests', () => {
|
describe('main tests', () => {
|
||||||
let inputs = {} as any;
|
let inputs = {} as any;
|
||||||
let os = {} as any;
|
let os = {} as any;
|
||||||
@ -286,91 +280,4 @@ describe('main tests', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Create a mock object that satisfies the BaseDistribution interface
|
|
||||||
const createMockNodejsDistribution = () => ({
|
|
||||||
setupNodeJs: jest.fn(),
|
|
||||||
httpClient: {}, // Mocking the httpClient (you can replace this with more detailed mocks if needed)
|
|
||||||
osPlat: 'darwin', // Mocking osPlat (the platform the action will run on, e.g., 'darwin', 'win32', 'linux')
|
|
||||||
nodeInfo: {
|
|
||||||
version: '14.x',
|
|
||||||
arch: 'x64',
|
|
||||||
platform: 'darwin',
|
|
||||||
},
|
|
||||||
getDistributionUrl: jest.fn().mockReturnValue('https://nodejs.org/dist/'), // Example URL
|
|
||||||
install: jest.fn(),
|
|
||||||
validate: jest.fn(),
|
|
||||||
// Add any other methods/properties required by your BaseDistribution type
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Mirror URL Tests', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should pass mirror URL correctly when provided', async () => {
|
|
||||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
|
||||||
if (name === 'mirror-url') return 'https://custom-mirror-url.com';
|
|
||||||
if (name === 'node-version') return '14.x';
|
|
||||||
return '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const mockNodejsDistribution = createMockNodejsDistribution();
|
|
||||||
(installerFactory.getNodejsDistribution as jest.Mock).mockReturnValue(mockNodejsDistribution);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
// Ensure setupNodeJs is called with the correct parameters, including the mirror URL
|
|
||||||
expect(mockNodejsDistribution.setupNodeJs).toHaveBeenCalledWith({
|
|
||||||
versionSpec: '14.x',
|
|
||||||
checkLatest: false,
|
|
||||||
auth: undefined,
|
|
||||||
stable: true,
|
|
||||||
arch: 'x64',
|
|
||||||
mirrorURL: 'https://custom-mirror-url.com', // Ensure this matches
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should use default mirror URL when no mirror URL is provided', async () => {
|
|
||||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
|
||||||
if (name === 'mirror-url') return ''; // Simulating no mirror URL provided
|
|
||||||
if (name === 'node-version') return '14.x';
|
|
||||||
return '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const mockNodejsDistribution = createMockNodejsDistribution();
|
|
||||||
(installerFactory.getNodejsDistribution as jest.Mock).mockReturnValue(mockNodejsDistribution);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
// Expect that setupNodeJs is called with an empty mirror URL (default behavior)
|
|
||||||
expect(mockNodejsDistribution.setupNodeJs).toHaveBeenCalledWith(expect.objectContaining({
|
|
||||||
mirrorURL: '', // Default URL is expected to be handled internally
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle mirror URL with spaces correctly', async () => {
|
|
||||||
const mirrorURL = 'https://custom-mirror-url.com ';
|
|
||||||
const expectedTrimmedURL = 'https://custom-mirror-url.com';
|
|
||||||
|
|
||||||
// Mock the setupNodeJs function
|
|
||||||
const mockNodejsDistribution = {
|
|
||||||
setupNodeJs: jest.fn(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Simulate calling the main function that will trigger setupNodeJs
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
// Assert that setupNodeJs was called with the correct trimmed mirrorURL
|
|
||||||
expect(mockNodejsDistribution.setupNodeJs).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
mirrorURL: expectedTrimmedURL, // Ensure the URL is trimmed properly
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,8 +10,8 @@ import osm from 'os';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as main from '../src/main';
|
import * as main from '../src/main';
|
||||||
import * as auth from '../src/authutil';
|
import * as auth from '../src/authutil';
|
||||||
import {INodeVersion, NodeInputs} from '../src/distributions/base-models';
|
import {INodeVersion} from '../src/distributions/base-models';
|
||||||
import NightlyNodejs from '../src/distributions/nightly/nightly_builds';
|
|
||||||
import nodeTestManifest from './data/versions-manifest.json';
|
import nodeTestManifest from './data/versions-manifest.json';
|
||||||
import nodeTestDist from './data/node-dist-index.json';
|
import nodeTestDist from './data/node-dist-index.json';
|
||||||
import nodeTestDistNightly from './data/node-nightly-index.json';
|
import nodeTestDistNightly from './data/node-nightly-index.json';
|
||||||
@ -606,127 +606,3 @@ describe('setup-node', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Mock core.info to track the log output
|
|
||||||
jest.mock('@actions/core', () => ({
|
|
||||||
info: jest.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Create a subclass to access the protected method for testing purposes
|
|
||||||
class TestNightlyNodejs extends NightlyNodejs {
|
|
||||||
nodeInputs: NodeInputs;
|
|
||||||
|
|
||||||
constructor(nodeInputs: NodeInputs) {
|
|
||||||
super(nodeInputs);
|
|
||||||
this.nodeInputs = nodeInputs;
|
|
||||||
}
|
|
||||||
|
|
||||||
getDistributionUrlPublic() {
|
|
||||||
// If a mirrorURL is provided, return it; otherwise, return the default URL
|
|
||||||
if (this.nodeInputs.mirrorURL && this.nodeInputs.mirrorURL.trim() !== '') {
|
|
||||||
core.info(`Using mirror URL: ${this.nodeInputs.mirrorURL}`);
|
|
||||||
return this.nodeInputs.mirrorURL;
|
|
||||||
} else {
|
|
||||||
core.info("Using default distribution URL for nightly Node.js.");
|
|
||||||
return 'https://nodejs.org/download/nightly';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
describe('NightlyNodejs', () => {
|
|
||||||
|
|
||||||
it('uses mirror URL when provided', async () => {
|
|
||||||
const mirrorURL = 'https://my.custom.mirror/nodejs/nightly';
|
|
||||||
const nodeInfo: NodeInputs = {
|
|
||||||
mirrorURL: mirrorURL, // Use the custom mirror URL here
|
|
||||||
versionSpec: '18.0.0-nightly',
|
|
||||||
arch: 'x64',
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false
|
|
||||||
};
|
|
||||||
|
|
||||||
const nightlyNode = new TestNightlyNodejs(nodeInfo);
|
|
||||||
|
|
||||||
const distributionUrl = nightlyNode.getDistributionUrlPublic();
|
|
||||||
|
|
||||||
// Check if the correct distribution URL is being used
|
|
||||||
expect(distributionUrl).toBe(mirrorURL);
|
|
||||||
|
|
||||||
// Verify if the core.info was called with the correct message
|
|
||||||
expect(core.info).toHaveBeenCalledWith(`Using mirror URL: ${mirrorURL}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('falls back to default distribution URL when no mirror URL is provided', async () => {
|
|
||||||
const nodeInfo: NodeInputs = {
|
|
||||||
versionSpec: '18.0.0-nightly', arch: 'x64',
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false
|
|
||||||
}; const nightlyNode = new TestNightlyNodejs(nodeInfo);
|
|
||||||
|
|
||||||
const distributionUrl = nightlyNode.getDistributionUrlPublic();
|
|
||||||
|
|
||||||
expect(distributionUrl).toBe('https://nodejs.org/download/nightly');
|
|
||||||
expect(core.info).toHaveBeenCalledWith('Using default distribution URL for nightly Node.js.');
|
|
||||||
});
|
|
||||||
|
|
||||||
const core = require('@actions/core'); // Mock core
|
|
||||||
jest.spyOn(core, 'info').mockImplementation(() => {}); // Mock core.info function
|
|
||||||
|
|
||||||
it('logs mirror URL when provided', async () => {
|
|
||||||
const mirrorURL = 'https://custom.mirror/nodejs/nightly';
|
|
||||||
|
|
||||||
const nodeInfo = {
|
|
||||||
mirrorURL: mirrorURL, // Set the mirror URL correctly
|
|
||||||
versionSpec: '18.0.0-nightly',
|
|
||||||
arch: 'x64',
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false
|
|
||||||
};
|
|
||||||
|
|
||||||
const nightlyNode = new TestNightlyNodejs(nodeInfo);
|
|
||||||
await nightlyNode.getDistributionUrlPublic(); // Ensure to await if the function is async
|
|
||||||
|
|
||||||
expect(core.info).toHaveBeenCalledWith(`Using mirror URL: ${mirrorURL}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('logs default URL when no mirror URL is provided', async () => {
|
|
||||||
const nodeInfo: NodeInputs = {
|
|
||||||
versionSpec: '18.0.0-nightly', arch: 'x64',
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false
|
|
||||||
}; const nightlyNode = new TestNightlyNodejs(nodeInfo);
|
|
||||||
|
|
||||||
nightlyNode.getDistributionUrlPublic();
|
|
||||||
|
|
||||||
expect(core.info).toHaveBeenCalledWith('Using default distribution URL for nightly Node.js.');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('falls back to default distribution URL if mirror URL is an empty string', async () => {
|
|
||||||
const nodeInfo: NodeInputs = {
|
|
||||||
mirrorURL: '', versionSpec: '18.0.0-nightly', arch: 'x64',
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false
|
|
||||||
};
|
|
||||||
const nightlyNode = new TestNightlyNodejs(nodeInfo);
|
|
||||||
|
|
||||||
const distributionUrl = nightlyNode.getDistributionUrlPublic();
|
|
||||||
|
|
||||||
expect(distributionUrl).toBe('https://nodejs.org/download/nightly');
|
|
||||||
expect(core.info).toHaveBeenCalledWith('Using default distribution URL for nightly Node.js.');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('falls back to default distribution URL if mirror URL is undefined', async () => {
|
|
||||||
const nodeInfo: NodeInputs = {
|
|
||||||
mirrorURL: '', versionSpec: '18.0.0-nightly', arch: 'x64',
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false
|
|
||||||
};
|
|
||||||
const nightlyNode = new TestNightlyNodejs(nodeInfo);
|
|
||||||
|
|
||||||
const distributionUrl = nightlyNode.getDistributionUrlPublic();
|
|
||||||
|
|
||||||
expect(distributionUrl).toBe('https://nodejs.org/download/nightly');
|
|
||||||
expect(core.info).toHaveBeenCalledWith('Using default distribution URL for nightly Node.js.');
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
@ -11,7 +11,7 @@ import path from 'path';
|
|||||||
import * as main from '../src/main';
|
import * as main from '../src/main';
|
||||||
import * as auth from '../src/authutil';
|
import * as auth from '../src/authutil';
|
||||||
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
|
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
|
||||||
import {INodeVersion, NodeInputs} from '../src/distributions/base-models';
|
import {INodeVersion} from '../src/distributions/base-models';
|
||||||
|
|
||||||
import nodeTestManifest from './data/versions-manifest.json';
|
import nodeTestManifest from './data/versions-manifest.json';
|
||||||
import nodeTestDist from './data/node-dist-index.json';
|
import nodeTestDist from './data/node-dist-index.json';
|
||||||
@ -828,122 +828,4 @@ describe('setup-node', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
import { OfficialBuilds } from './path-to-your-official-builds-file'; // Adjust path
|
|
||||||
import * as core from '@actions/core';
|
|
||||||
import * as tc from '@actions/tool-cache';
|
|
||||||
|
|
||||||
jest.mock('@actions/core');
|
|
||||||
jest.mock('@actions/tool-cache');
|
|
||||||
|
|
||||||
describe('OfficialBuilds - Mirror URL functionality', () => {
|
|
||||||
|
|
||||||
let officialBuilds: OfficialBuilds;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
const mockNodeInfo = {
|
|
||||||
versionSpec: '16.x',
|
|
||||||
mirrorURL: 'https://my.custom.mirror/nodejs',
|
|
||||||
arch: 'x64',
|
|
||||||
stable: true,
|
|
||||||
checkLatest: false,
|
|
||||||
osPlat: 'linux', // Mock OS platform to avoid "undefined" error
|
|
||||||
auth: 'someAuthToken',
|
|
||||||
};
|
|
||||||
officialBuilds = new OfficialBuilds(mockNodeInfo);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should download using the mirror URL when provided', async () => {
|
|
||||||
const mockDownloadPath = '/some/temp/path';
|
|
||||||
const mockDownloadTool = jest.spyOn(tc, 'downloadTool').mockResolvedValue(mockDownloadPath);
|
|
||||||
const mockAddPath = jest.spyOn(core, 'addPath').mockImplementation(() => {});
|
|
||||||
|
|
||||||
await officialBuilds.setupNodeJs();
|
|
||||||
|
|
||||||
// Check if the mirror URL was used
|
|
||||||
expect(core.info).toHaveBeenCalledWith('Attempting to download using mirror URL...');
|
|
||||||
expect(core.info).toHaveBeenCalledWith('downloadPath from downloadFromMirrorURL() /some/temp/path');
|
|
||||||
expect(core.addPath).toHaveBeenCalledWith(mockDownloadPath);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should log a message when mirror URL is used', async () => {
|
|
||||||
const mockInfo = jest.spyOn(core, 'info').mockImplementation(() => {});
|
|
||||||
|
|
||||||
await officialBuilds.setupNodeJs();
|
|
||||||
|
|
||||||
// Check if the appropriate message is logged for mirror URL
|
|
||||||
expect(core.info).toHaveBeenCalledWith(`Using mirror URL: https://my.custom.mirror/nodejs`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fall back to default URL if mirror URL is not provided', async () => {
|
|
||||||
// Mock a scenario where mirror URL is not provided
|
|
||||||
officialBuilds.nodeInfo.mirrorURL = undefined;
|
|
||||||
|
|
||||||
const mockInfo = jest.spyOn(core, 'info').mockImplementation(() => {});
|
|
||||||
|
|
||||||
await officialBuilds.setupNodeJs();
|
|
||||||
|
|
||||||
// Check if fallback logic was triggered
|
|
||||||
expect(core.info).toHaveBeenCalledWith('Falling back to download directly from Node');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should log an error and handle failure during mirror URL download', async () => {
|
|
||||||
const errorMessage = 'Network error';
|
|
||||||
const mockError = jest.spyOn(core, 'error').mockImplementation(() => {});
|
|
||||||
const mockDebug = jest.spyOn(core, 'debug').mockImplementation(() => {});
|
|
||||||
|
|
||||||
const mockDownloadTool = jest.spyOn(tc, 'downloadTool').mockRejectedValue(new Error(errorMessage));
|
|
||||||
|
|
||||||
try {
|
|
||||||
await officialBuilds.setupNodeJs();
|
|
||||||
} catch (error) {
|
|
||||||
// Expect core.error to be called with the error message
|
|
||||||
expect(core.error).toHaveBeenCalledWith(errorMessage);
|
|
||||||
expect(core.debug).toHaveBeenCalledWith(expect.stringContaining('empty stack'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should log a fallback message if downloading from the mirror URL fails', async () => {
|
|
||||||
const mockInfo = jest.spyOn(core, 'info').mockImplementation(() => {});
|
|
||||||
const mockDownloadTool = jest.spyOn(tc, 'downloadTool').mockRejectedValue(new Error('Download failed'));
|
|
||||||
|
|
||||||
await officialBuilds.setupNodeJs();
|
|
||||||
|
|
||||||
// Check if fallback log message was triggered
|
|
||||||
expect(core.info).toHaveBeenCalledWith('Failed to download from mirror URL. Falling back to default Node.js URL...');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if mirror URL is not provided and downloading from both mirror and default fails', async () => {
|
|
||||||
const errorMessage = `Unable to find Node version for platform linux and architecture x64.`;
|
|
||||||
|
|
||||||
const mockDownloadTool = jest.spyOn(tc, 'downloadTool').mockRejectedValue(new Error('Download failed'));
|
|
||||||
const mockGetNodeJsVersions = jest.spyOn(officialBuilds, 'getNodeJsVersions').mockResolvedValue([]);
|
|
||||||
|
|
||||||
// Simulating failure in getting versions and download
|
|
||||||
try {
|
|
||||||
await officialBuilds.setupNodeJs();
|
|
||||||
} catch (error) {
|
|
||||||
expect(error.message).toContain(errorMessage);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if mirror URL is undefined and not provided', async () => {
|
|
||||||
const errorMessage = `Unable to find Node version for platform linux and architecture x64.`;
|
|
||||||
officialBuilds.nodeInfo.mirrorURL = undefined; // Simulate missing mirror URL
|
|
||||||
|
|
||||||
const mockGetNodeJsVersions = jest.spyOn(officialBuilds, 'getNodeJsVersions').mockResolvedValue([]);
|
|
||||||
const mockDownloadTool = jest.spyOn(tc, 'downloadTool').mockRejectedValue(new Error('Download failed'));
|
|
||||||
|
|
||||||
try {
|
|
||||||
await officialBuilds.setupNodeJs();
|
|
||||||
} catch (error) {
|
|
||||||
expect(error.message).toContain(errorMessage);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,13 +10,12 @@ import osm from 'os';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as main from '../src/main';
|
import * as main from '../src/main';
|
||||||
import * as auth from '../src/authutil';
|
import * as auth from '../src/authutil';
|
||||||
import {INodeVersion, NodeInputs} from '../src/distributions/base-models';
|
import {INodeVersion} from '../src/distributions/base-models';
|
||||||
|
|
||||||
import nodeTestDist from './data/node-dist-index.json';
|
import nodeTestDist from './data/node-dist-index.json';
|
||||||
import nodeTestDistNightly from './data/node-nightly-index.json';
|
import nodeTestDistNightly from './data/node-nightly-index.json';
|
||||||
import nodeTestDistRc from './data/node-rc-index.json';
|
import nodeTestDistRc from './data/node-rc-index.json';
|
||||||
import nodeV8CanaryTestDist from './data/v8-canary-dist-index.json';
|
import nodeV8CanaryTestDist from './data/v8-canary-dist-index.json';
|
||||||
import RcBuild from '../src/distributions/rc/rc_builds';
|
|
||||||
|
|
||||||
describe('setup-node', () => {
|
describe('setup-node', () => {
|
||||||
let inputs = {} as any;
|
let inputs = {} as any;
|
||||||
@ -145,10 +144,6 @@ describe('setup-node', () => {
|
|||||||
|
|
||||||
const toolPath = path.normalize('/cache/node/12.0.0-rc.1/x64');
|
const toolPath = path.normalize('/cache/node/12.0.0-rc.1/x64');
|
||||||
findSpy.mockImplementation(() => toolPath);
|
findSpy.mockImplementation(() => toolPath);
|
||||||
// Ensure spies are set up before running the main logic
|
|
||||||
const logSpy = jest.spyOn(console, 'log'); // Ensure this is spying on console.log
|
|
||||||
const cnSpy = jest.spyOn(process.stdout, 'write'); // Ensure this spies on the correct add-path function
|
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||||
@ -161,10 +156,6 @@ describe('setup-node', () => {
|
|||||||
|
|
||||||
const toolPath = path.normalize('/cache/node/12.0.0-rc.1/x64');
|
const toolPath = path.normalize('/cache/node/12.0.0-rc.1/x64');
|
||||||
findSpy.mockImplementation(() => toolPath);
|
findSpy.mockImplementation(() => toolPath);
|
||||||
|
|
||||||
// Ensure spies are set up before running the main logic
|
|
||||||
const logSpy = jest.spyOn(console, 'log'); // Ensure this is spying on console.log
|
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||||
@ -177,10 +168,6 @@ describe('setup-node', () => {
|
|||||||
|
|
||||||
const toolPath = path.normalize('/cache/node/12.0.0-rc.1/x64');
|
const toolPath = path.normalize('/cache/node/12.0.0-rc.1/x64');
|
||||||
findSpy.mockImplementation(() => toolPath);
|
findSpy.mockImplementation(() => toolPath);
|
||||||
// Ensure spies are set up before running the main logic
|
|
||||||
const logSpy = jest.spyOn(console, 'log'); // Ensure this is spying on console.log
|
|
||||||
const cnSpy = jest.spyOn(process.stdout, 'write'); // Ensure this spies on the correct add-path function
|
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
const expPath = path.join(toolPath, 'bin');
|
const expPath = path.join(toolPath, 'bin');
|
||||||
@ -237,10 +224,6 @@ describe('setup-node', () => {
|
|||||||
inputs['node-version'] = versionSpec;
|
inputs['node-version'] = versionSpec;
|
||||||
|
|
||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
// Ensure spies are set up before running the main logic
|
|
||||||
const logSpy = jest.spyOn(console, 'log'); // Ensure this is spying on console.log
|
|
||||||
const cnSpy = jest.spyOn(process.stdout, 'write'); // Ensure this spies on the correct add-path function
|
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
expect(cnSpy).toHaveBeenCalledWith(
|
expect(cnSpy).toHaveBeenCalledWith(
|
||||||
@ -264,11 +247,6 @@ describe('setup-node', () => {
|
|||||||
dlSpy.mockImplementation(() => {
|
dlSpy.mockImplementation(() => {
|
||||||
throw new Error(errMsg);
|
throw new Error(errMsg);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Ensure spies are set up before running the main logic
|
|
||||||
const logSpy = jest.spyOn(console, 'log'); // Ensure this is spying on console.log
|
|
||||||
const cnSpy = jest.spyOn(process.stdout, 'write'); // Ensure this spies on the correct add-path function
|
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
|
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
|
||||||
@ -303,9 +281,6 @@ describe('setup-node', () => {
|
|||||||
const toolPath = path.normalize(`/cache/node/${version}/${arch}`);
|
const toolPath = path.normalize(`/cache/node/${version}/${arch}`);
|
||||||
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
// Ensure spies are set up before running the main logic
|
|
||||||
const logSpy = jest.spyOn(console, 'log'); // Ensure this is spying on console.log
|
|
||||||
const cnSpy = jest.spyOn(process.stdout, 'write'); // Ensure this spies on the correct add-path function
|
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
expect(dlSpy).toHaveBeenCalled();
|
expect(dlSpy).toHaveBeenCalled();
|
||||||
@ -356,11 +331,6 @@ describe('setup-node', () => {
|
|||||||
inputs['node-version'] = input;
|
inputs['node-version'] = input;
|
||||||
os['arch'] = 'x64';
|
os['arch'] = 'x64';
|
||||||
os['platform'] = 'linux';
|
os['platform'] = 'linux';
|
||||||
|
|
||||||
// Ensure spies are set up before running the main logic
|
|
||||||
const logSpy = jest.spyOn(console, 'log'); // Ensure this is spying on console.log
|
|
||||||
const cnSpy = jest.spyOn(process.stdout, 'write'); // Ensure this spies on the correct add-path function
|
|
||||||
|
|
||||||
// act
|
// act
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
@ -382,18 +352,14 @@ describe('setup-node', () => {
|
|||||||
'finds the %s version in the hostedToolcache',
|
'finds the %s version in the hostedToolcache',
|
||||||
async (input, expectedVersion) => {
|
async (input, expectedVersion) => {
|
||||||
const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`);
|
const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`);
|
||||||
|
findSpy.mockImplementation((_, version) =>
|
||||||
// Mocking the behavior of findSpy and findAllVersionsSpy
|
path.normalize(`/cache/node/${version}/x64`)
|
||||||
findSpy.mockImplementation((_, version) => {
|
);
|
||||||
console.log(`findSpy called for version: ${version}`); // Debugging line
|
|
||||||
return path.normalize(`/cache/node/${version}/x64`);
|
|
||||||
});
|
|
||||||
|
|
||||||
findAllVersionsSpy.mockReturnValue([
|
findAllVersionsSpy.mockReturnValue([
|
||||||
'2.2.2-rc.2',
|
'2.2.2-rc.2',
|
||||||
'1.1.1-rc.1',
|
'1.1.1-rc.1',
|
||||||
'99.1.1',
|
'99.1.1',
|
||||||
expectedVersion, // This should be the expected version
|
expectedVersion,
|
||||||
'88.1.1',
|
'88.1.1',
|
||||||
'3.3.3-rc.3'
|
'3.3.3-rc.3'
|
||||||
]);
|
]);
|
||||||
@ -402,33 +368,17 @@ describe('setup-node', () => {
|
|||||||
os['arch'] = 'x64';
|
os['arch'] = 'x64';
|
||||||
os['platform'] = 'linux';
|
os['platform'] = 'linux';
|
||||||
|
|
||||||
// Ensure spies are set up before running the main logic
|
// act
|
||||||
const logSpy = jest.spyOn(console, 'log'); // Ensure this is spying on console.log
|
|
||||||
const cnSpy = jest.spyOn(process.stdout, 'write'); // Ensure this spies on the correct add-path function
|
|
||||||
|
|
||||||
|
|
||||||
// Act: Run the main function (your application logic)
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
// Debugging output to check if logSpy was called
|
// assert
|
||||||
console.log('logSpy calls:', logSpy.mock.calls); // Debugging line
|
|
||||||
|
|
||||||
// Assert: Check that the logSpy was called with the correct message
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||||
|
|
||||||
// Assert: Check that cnSpy was called with the correct add-path action
|
|
||||||
expect(cnSpy).toHaveBeenCalledWith(
|
expect(cnSpy).toHaveBeenCalledWith(
|
||||||
`::add-path::${path.join(toolPath, 'bin')}${osm.EOL}`
|
`::add-path::${path.join(toolPath, 'bin')}${osm.EOL}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// Clean up spies
|
|
||||||
logSpy.mockRestore();
|
|
||||||
cnSpy.mockRestore();
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it('throws an error if version is not found', async () => {
|
it('throws an error if version is not found', async () => {
|
||||||
const versionSpec = '19.0.0-rc.3';
|
const versionSpec = '19.0.0-rc.3';
|
||||||
|
|
||||||
@ -440,10 +390,6 @@ describe('setup-node', () => {
|
|||||||
inputs['node-version'] = versionSpec;
|
inputs['node-version'] = versionSpec;
|
||||||
os['arch'] = 'x64';
|
os['arch'] = 'x64';
|
||||||
os['platform'] = 'linux';
|
os['platform'] = 'linux';
|
||||||
// Ensure spies are set up before running the main logic
|
|
||||||
const logSpy = jest.spyOn(console, 'log'); // Ensure this is spying on console.log
|
|
||||||
const cnSpy = jest.spyOn(process.stdout, 'write'); // Ensure this spies on the correct add-path function
|
|
||||||
|
|
||||||
// act
|
// act
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
@ -453,93 +399,4 @@ describe('setup-node', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('RcBuild - Mirror URL functionality', () => {
|
|
||||||
const nodeInfo: NodeInputs = {
|
|
||||||
versionSpec: '18.0.0-rc',
|
|
||||||
arch: 'x64',
|
|
||||||
mirrorURL: '',
|
|
||||||
checkLatest: false,
|
|
||||||
stable: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
it('should return the default distribution URL if no mirror URL is provided', () => {
|
|
||||||
const rcBuild = new RcBuild(nodeInfo);
|
|
||||||
|
|
||||||
const distributionUrl = rcBuild.getDistributionUrl();
|
|
||||||
|
|
||||||
// Default URL
|
|
||||||
expect(distributionUrl).toBe('https://nodejs.org/download/rc');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should use the mirror URL from nodeInfo if provided', () => {
|
|
||||||
const mirrorURL = 'https://my.custom.mirror/nodejs'; // Set the custom mirror URL
|
|
||||||
nodeInfo.mirrorURL = mirrorURL; // Set the mirrorURL in nodeInfo
|
|
||||||
|
|
||||||
const rcBuild = new RcBuild(nodeInfo);
|
|
||||||
|
|
||||||
// Mock core.info to track its calls
|
|
||||||
const infoSpy = jest.spyOn(core, 'info').mockImplementation(() => {});
|
|
||||||
|
|
||||||
// Call the method
|
|
||||||
const distributionMirrorUrl = rcBuild['getDistributionMirrorUrl'](); // Access the protected method
|
|
||||||
|
|
||||||
// Assert that core.info was called with the correct mirror URL message
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(`Using mirror URL: ${mirrorURL}`);
|
|
||||||
|
|
||||||
// Assert that the returned URL is the mirror URL
|
|
||||||
expect(distributionMirrorUrl).toBe(mirrorURL);
|
|
||||||
|
|
||||||
// Restore the original core.info function after the test
|
|
||||||
infoSpy.mockRestore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if mirror URL is empty', () => {
|
|
||||||
nodeInfo.mirrorURL = ''; // Empty mirror URL
|
|
||||||
|
|
||||||
const rcBuild = new RcBuild(nodeInfo);
|
|
||||||
|
|
||||||
// Mock core.info to track its calls
|
|
||||||
const infoSpy = jest.spyOn(core, 'info').mockImplementation(() => {});
|
|
||||||
|
|
||||||
// Expect the function to return the default URL because the mirror URL is empty
|
|
||||||
const distributionMirrorUrl = rcBuild['getDistributionMirrorUrl']();
|
|
||||||
|
|
||||||
expect(distributionMirrorUrl).toBe('https://nodejs.org/download/rc');
|
|
||||||
|
|
||||||
// Ensure that core.info was NOT called because it's not a custom mirror URL
|
|
||||||
expect(infoSpy).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
infoSpy.mockRestore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if mirror URL is undefined', () => {
|
|
||||||
nodeInfo.mirrorURL = undefined; // Undefined mirror URL
|
|
||||||
|
|
||||||
const rcBuild = new RcBuild(nodeInfo);
|
|
||||||
|
|
||||||
// Mock core.info to track its calls
|
|
||||||
const infoSpy = jest.spyOn(core, 'info').mockImplementation(() => {});
|
|
||||||
|
|
||||||
// Expect the function to return the default URL because the mirror URL is undefined
|
|
||||||
const distributionMirrorUrl = rcBuild['getDistributionMirrorUrl']();
|
|
||||||
|
|
||||||
expect(distributionMirrorUrl).toBe('https://nodejs.org/download/rc');
|
|
||||||
|
|
||||||
// Ensure that core.info was NOT called because it's not a custom mirror URL
|
|
||||||
expect(infoSpy).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
infoSpy.mockRestore();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
57
dist/setup/index.js
vendored
57
dist/setup/index.js
vendored
@ -100156,27 +100156,12 @@ class BaseDistribution {
|
|||||||
}
|
}
|
||||||
getMirrorUrlVersions() {
|
getMirrorUrlVersions() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const initialUrl = this.getDistributionUrl();
|
const initialUrl = this.getDistributionMirrorUrl();
|
||||||
|
core.info('initialUrl from getDistributionMirrorUrl ' + initialUrl);
|
||||||
const dataUrl = `${initialUrl}/index.json`;
|
const dataUrl = `${initialUrl}/index.json`;
|
||||||
try {
|
core.info('dataUrl from index ' + dataUrl);
|
||||||
const response = yield this.httpClient.getJson(dataUrl);
|
const response = yield this.httpClient.getJson(dataUrl);
|
||||||
return response.result || [];
|
return response.result || [];
|
||||||
}
|
|
||||||
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.`);
|
|
||||||
}
|
|
||||||
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.`);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
core.error(`Failed to fetch Node.js versions from ${dataUrl}.
|
|
||||||
Please check the URL and try again.}`);
|
|
||||||
}
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getNodejsDistInfo(version) {
|
getNodejsDistInfo(version) {
|
||||||
@ -100190,7 +100175,7 @@ class BaseDistribution {
|
|||||||
? `${fileName}.zip`
|
? `${fileName}.zip`
|
||||||
: `${fileName}.7z`
|
: `${fileName}.7z`
|
||||||
: `${fileName}.tar.gz`;
|
: `${fileName}.tar.gz`;
|
||||||
const initialUrl = this.getDistributionUrl();
|
const initialUrl = this.getDistributionMirrorUrl();
|
||||||
const url = `${initialUrl}/v${version}/${urlFileName}`;
|
const url = `${initialUrl}/v${version}/${urlFileName}`;
|
||||||
return {
|
return {
|
||||||
downloadUrl: url,
|
downloadUrl: url,
|
||||||
@ -100201,7 +100186,9 @@ class BaseDistribution {
|
|||||||
}
|
}
|
||||||
getNodejsMirrorURLInfo(version) {
|
getNodejsMirrorURLInfo(version) {
|
||||||
const mirrorURL = this.nodeInfo.mirrorURL;
|
const mirrorURL = this.nodeInfo.mirrorURL;
|
||||||
|
core.info('mirrorURL from getNodejsMirrorURLInfo ' + mirrorURL);
|
||||||
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
|
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
|
||||||
|
core.info('osArch from translateArchToDistUrl ' + osArch);
|
||||||
version = semver_1.default.clean(version) || '';
|
version = semver_1.default.clean(version) || '';
|
||||||
const fileName = this.osPlat == 'win32'
|
const fileName = this.osPlat == 'win32'
|
||||||
? `node-v${version}-win-${osArch}`
|
? `node-v${version}-win-${osArch}`
|
||||||
@ -100212,6 +100199,7 @@ class BaseDistribution {
|
|||||||
: `${fileName}.7z`
|
: `${fileName}.7z`
|
||||||
: `${fileName}.tar.gz`;
|
: `${fileName}.tar.gz`;
|
||||||
const url = `${mirrorURL}/v${version}/${urlFileName}`;
|
const url = `${mirrorURL}/v${version}/${urlFileName}`;
|
||||||
|
core.info('url from construct ' + url);
|
||||||
return {
|
return {
|
||||||
downloadUrl: url,
|
downloadUrl: url,
|
||||||
resolvedVersion: version,
|
resolvedVersion: version,
|
||||||
@ -100232,11 +100220,6 @@ class BaseDistribution {
|
|||||||
this.osPlat == 'win32') {
|
this.osPlat == 'win32') {
|
||||||
return yield this.acquireWindowsNodeFromFallbackLocation(info.resolvedVersion, info.arch, info.downloadUrl);
|
return yield this.acquireWindowsNodeFromFallbackLocation(info.resolvedVersion, info.arch, info.downloadUrl);
|
||||||
}
|
}
|
||||||
// Handle network-related issues (e.g., DNS resolution failures)
|
|
||||||
if (err instanceof Error && err.message.includes('getaddrinfo EAI_AGAIN')) {
|
|
||||||
core.error(`Network error: Failed to resolve the server at ${info.downloadUrl}.
|
|
||||||
This could be due to a DNS resolution issue. Please verify the URL or check your network connection.`);
|
|
||||||
}
|
|
||||||
core.error(`Download failed from ${info.downloadUrl}. Please check the URl and try again.`);
|
core.error(`Download failed from ${info.downloadUrl}. Please check the URl and try again.`);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@ -100479,7 +100462,7 @@ class NightlyNodejs extends base_distribution_prerelease_1.default {
|
|||||||
// Check if mirrorUrl exists in the nodeInfo and return it if available
|
// Check if mirrorUrl exists in the nodeInfo and return it if available
|
||||||
const mirrorUrl = this.nodeInfo.mirrorURL;
|
const mirrorUrl = this.nodeInfo.mirrorURL;
|
||||||
if (mirrorUrl) {
|
if (mirrorUrl) {
|
||||||
core.info(`Downloding Using mirror URL: ${mirrorUrl}`);
|
core.info(`Using mirror URL: ${mirrorUrl}`);
|
||||||
return mirrorUrl;
|
return mirrorUrl;
|
||||||
}
|
}
|
||||||
// Default to the official Node.js nightly distribution URL if no mirror URL is provided
|
// Default to the official Node.js nightly distribution URL if no mirror URL is provided
|
||||||
@ -100669,11 +100652,15 @@ class OfficialBuilds extends base_distribution_1.default {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
getDistributionUrl() {
|
getDistributionUrl() {
|
||||||
if (this.nodeInfo.mirrorURL) {
|
|
||||||
return this.nodeInfo.mirrorURL;
|
|
||||||
}
|
|
||||||
return `https://nodejs.org/dist`;
|
return `https://nodejs.org/dist`;
|
||||||
}
|
}
|
||||||
|
getDistributionMirrorUrl() {
|
||||||
|
const mirrorURL = this.nodeInfo.mirrorURL;
|
||||||
|
if (!mirrorURL) {
|
||||||
|
throw new Error('Mirror URL is undefined');
|
||||||
|
}
|
||||||
|
return mirrorURL;
|
||||||
|
}
|
||||||
getManifest() {
|
getManifest() {
|
||||||
core.debug('Getting manifest from actions/node-versions@main');
|
core.debug('Getting manifest from actions/node-versions@main');
|
||||||
return tc.getManifestFromRepo('actions', 'node-versions', this.nodeInfo.auth, 'main');
|
return tc.getManifestFromRepo('actions', 'node-versions', this.nodeInfo.auth, 'main');
|
||||||
@ -100742,14 +100729,19 @@ class OfficialBuilds extends base_distribution_1.default {
|
|||||||
downloadFromMirrorURL() {
|
downloadFromMirrorURL() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const nodeJsVersions = yield this.getMirrorUrlVersions();
|
const nodeJsVersions = yield this.getMirrorUrlVersions();
|
||||||
|
core.info('nodeJsVersions from getMirrorUrVersions ' + nodeJsVersions);
|
||||||
const versions = this.filterVersions(nodeJsVersions);
|
const versions = this.filterVersions(nodeJsVersions);
|
||||||
|
core.info('versions from filterVersions ' + versions);
|
||||||
const evaluatedVersion = this.evaluateVersions(versions);
|
const evaluatedVersion = this.evaluateVersions(versions);
|
||||||
|
core.info('evaluatedVersion from evaluatedVersions ' + evaluatedVersion);
|
||||||
if (!evaluatedVersion) {
|
if (!evaluatedVersion) {
|
||||||
throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} from the provided mirror-url ${this.nodeInfo.mirrorURL}. Please check the mirror-url`);
|
throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`);
|
||||||
}
|
}
|
||||||
const toolName = this.getNodejsMirrorURLInfo(evaluatedVersion);
|
const toolName = this.getNodejsMirrorURLInfo(evaluatedVersion);
|
||||||
|
core.info('toolName from getNodejsMirrorURLInfo ' + toolName);
|
||||||
try {
|
try {
|
||||||
const toolPath = yield this.downloadNodejs(toolName);
|
const toolPath = yield this.downloadNodejs(toolName);
|
||||||
|
core.info('toolPath from downloadNodejs ' + toolPath);
|
||||||
return toolPath;
|
return toolPath;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
@ -100864,9 +100856,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||||||
const base_distribution_prerelease_1 = __importDefault(__nccwpck_require__(957));
|
const base_distribution_prerelease_1 = __importDefault(__nccwpck_require__(957));
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
class CanaryBuild extends base_distribution_prerelease_1.default {
|
class CanaryBuild extends base_distribution_prerelease_1.default {
|
||||||
static getDistributionMirrorUrl() {
|
|
||||||
throw new Error('Method not implemented.');
|
|
||||||
}
|
|
||||||
constructor(nodeInfo) {
|
constructor(nodeInfo) {
|
||||||
super(nodeInfo);
|
super(nodeInfo);
|
||||||
this.distribution = 'v8-canary';
|
this.distribution = 'v8-canary';
|
||||||
|
|||||||
@ -25,6 +25,7 @@ export default abstract class BaseDistribution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract getDistributionUrl(): string;
|
protected abstract getDistributionUrl(): string;
|
||||||
|
protected abstract getDistributionMirrorUrl(): string;
|
||||||
|
|
||||||
public async setupNodeJs() {
|
public async setupNodeJs() {
|
||||||
let nodeJsVersions: INodeVersion[] | undefined;
|
let nodeJsVersions: INodeVersion[] | undefined;
|
||||||
@ -105,25 +106,14 @@ export default abstract class BaseDistribution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async getMirrorUrlVersions(): Promise<INodeVersion[]> {
|
protected async getMirrorUrlVersions(): Promise<INodeVersion[]> {
|
||||||
const initialUrl = this.getDistributionUrl();
|
const initialUrl = this.getDistributionMirrorUrl();
|
||||||
|
core.info('initialUrl from getDistributionMirrorUrl '+initialUrl);
|
||||||
|
|
||||||
const dataUrl = `${initialUrl}/index.json`;
|
const dataUrl = `${initialUrl}/index.json`;
|
||||||
try {
|
core.info('dataUrl from index '+dataUrl);
|
||||||
|
|
||||||
const response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
|
const response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
|
||||||
return response.result || [];
|
return response.result || [];
|
||||||
}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.`);
|
|
||||||
} 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.`);
|
|
||||||
} else {
|
|
||||||
core.error(`Failed to fetch Node.js versions from ${dataUrl}.
|
|
||||||
Please check the URL and try again.}`);
|
|
||||||
}
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getNodejsDistInfo(version: string) {
|
protected getNodejsDistInfo(version: string) {
|
||||||
@ -139,7 +129,7 @@ export default abstract class BaseDistribution {
|
|||||||
? `${fileName}.zip`
|
? `${fileName}.zip`
|
||||||
: `${fileName}.7z`
|
: `${fileName}.7z`
|
||||||
: `${fileName}.tar.gz`;
|
: `${fileName}.tar.gz`;
|
||||||
const initialUrl = this.getDistributionUrl();
|
const initialUrl = this.getDistributionMirrorUrl();
|
||||||
const url = `${initialUrl}/v${version}/${urlFileName}`;
|
const url = `${initialUrl}/v${version}/${urlFileName}`;
|
||||||
|
|
||||||
return <INodeVersionInfo>{
|
return <INodeVersionInfo>{
|
||||||
@ -152,8 +142,10 @@ export default abstract class BaseDistribution {
|
|||||||
|
|
||||||
protected getNodejsMirrorURLInfo(version: string) {
|
protected getNodejsMirrorURLInfo(version: string) {
|
||||||
const mirrorURL = this.nodeInfo.mirrorURL;
|
const mirrorURL = this.nodeInfo.mirrorURL;
|
||||||
|
core.info('mirrorURL from getNodejsMirrorURLInfo '+mirrorURL);
|
||||||
|
|
||||||
const osArch: string = this.translateArchToDistUrl(this.nodeInfo.arch);
|
const osArch: string = this.translateArchToDistUrl(this.nodeInfo.arch);
|
||||||
|
core.info('osArch from translateArchToDistUrl '+osArch);
|
||||||
|
|
||||||
version = semver.clean(version) || '';
|
version = semver.clean(version) || '';
|
||||||
const fileName: string =
|
const fileName: string =
|
||||||
@ -168,6 +160,7 @@ export default abstract class BaseDistribution {
|
|||||||
: `${fileName}.tar.gz`;
|
: `${fileName}.tar.gz`;
|
||||||
|
|
||||||
const url = `${mirrorURL}/v${version}/${urlFileName}`;
|
const url = `${mirrorURL}/v${version}/${urlFileName}`;
|
||||||
|
core.info('url from construct '+url);
|
||||||
|
|
||||||
return <INodeVersionInfo>{
|
return <INodeVersionInfo>{
|
||||||
downloadUrl: url,
|
downloadUrl: url,
|
||||||
@ -196,13 +189,6 @@ export default abstract class BaseDistribution {
|
|||||||
info.downloadUrl
|
info.downloadUrl
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Handle network-related issues (e.g., DNS resolution failures)
|
|
||||||
if (err instanceof Error && err.message.includes('getaddrinfo EAI_AGAIN')) {
|
|
||||||
core.error(
|
|
||||||
`Network error: Failed to resolve the server at ${info.downloadUrl}.
|
|
||||||
This could be due to a DNS resolution issue. Please verify the URL or check your network connection.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
core.error(
|
core.error(
|
||||||
`Download failed from ${info.downloadUrl}. Please check the URl and try again.`
|
`Download failed from ${info.downloadUrl}. Please check the URl and try again.`
|
||||||
);
|
);
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export default class NightlyNodejs extends BasePrereleaseNodejs {
|
|||||||
// Check if mirrorUrl exists in the nodeInfo and return it if available
|
// Check if mirrorUrl exists in the nodeInfo and return it if available
|
||||||
const mirrorUrl = this.nodeInfo.mirrorURL;
|
const mirrorUrl = this.nodeInfo.mirrorURL;
|
||||||
if (mirrorUrl) {
|
if (mirrorUrl) {
|
||||||
core.info(`Downloding Using mirror URL: ${mirrorUrl}`);
|
core.info(`Using mirror URL: ${mirrorUrl}`);
|
||||||
return mirrorUrl;
|
return mirrorUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -193,12 +193,16 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected getDistributionUrl(): string {
|
protected getDistributionUrl(): string {
|
||||||
if (this.nodeInfo.mirrorURL) {
|
|
||||||
return this.nodeInfo.mirrorURL;
|
|
||||||
}
|
|
||||||
return `https://nodejs.org/dist`;
|
return `https://nodejs.org/dist`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected getDistributionMirrorUrl(): string {
|
||||||
|
const mirrorURL = this.nodeInfo.mirrorURL;
|
||||||
|
if (!mirrorURL) {
|
||||||
|
throw new Error('Mirror URL is undefined');
|
||||||
|
}
|
||||||
|
return mirrorURL;
|
||||||
|
}
|
||||||
|
|
||||||
private getManifest(): Promise<tc.IToolRelease[]> {
|
private getManifest(): Promise<tc.IToolRelease[]> {
|
||||||
core.debug('Getting manifest from actions/node-versions@main');
|
core.debug('Getting manifest from actions/node-versions@main');
|
||||||
@ -314,25 +318,30 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||||||
|
|
||||||
protected async downloadFromMirrorURL() {
|
protected async downloadFromMirrorURL() {
|
||||||
const nodeJsVersions = await this.getMirrorUrlVersions();
|
const nodeJsVersions = await this.getMirrorUrlVersions();
|
||||||
|
core.info('nodeJsVersions from getMirrorUrVersions '+nodeJsVersions);
|
||||||
const versions = this.filterVersions(nodeJsVersions);
|
const versions = this.filterVersions(nodeJsVersions);
|
||||||
|
core.info('versions from filterVersions '+versions);
|
||||||
|
|
||||||
|
|
||||||
const evaluatedVersion = this.evaluateVersions(versions);
|
const evaluatedVersion = this.evaluateVersions(versions);
|
||||||
|
|
||||||
|
core.info('evaluatedVersion from evaluatedVersions '+evaluatedVersion);
|
||||||
|
|
||||||
|
|
||||||
if (!evaluatedVersion) {
|
if (!evaluatedVersion) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} from the provided mirror-url ${this.nodeInfo.mirrorURL}. Please check the mirror-url`
|
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const toolName = this.getNodejsMirrorURLInfo(evaluatedVersion);
|
const toolName = this.getNodejsMirrorURLInfo(evaluatedVersion);
|
||||||
|
|
||||||
|
core.info('toolName from getNodejsMirrorURLInfo '+toolName);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const toolPath = await this.downloadNodejs(toolName);
|
const toolPath = await this.downloadNodejs(toolName);
|
||||||
|
core.info('toolPath from downloadNodejs '+toolPath);
|
||||||
|
|
||||||
return toolPath;
|
return toolPath;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user