mirror of
https://github.com/actions/setup-node.git
synced 2025-04-02 01:30:20 +08:00
checks update
This commit is contained in:
parent
d61dc50c40
commit
dd2fa9d9f8
3
.github/workflows/versions.yml
vendored
3
.github/workflows/versions.yml
vendored
@ -82,8 +82,7 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version:
|
node-version: [20.12.0-nightly, 21-nightly, 18.0.0-nightly]
|
||||||
[20.11.0-nightly202312211a0be537da, 21-nightly, 18.0.0-nightly]
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
|
@ -14,12 +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()
|
|
||||||
}));
|
|
||||||
import {validateMirrorURL} from '../src/util';
|
|
||||||
|
|
||||||
describe('main tests', () => {
|
describe('main tests', () => {
|
||||||
let inputs = {} as any;
|
let inputs = {} as any;
|
||||||
let os = {} as any;
|
let os = {} as any;
|
||||||
@ -44,8 +38,6 @@ describe('main tests', () => {
|
|||||||
|
|
||||||
let setupNodeJsSpy: jest.SpyInstance;
|
let setupNodeJsSpy: jest.SpyInstance;
|
||||||
|
|
||||||
let validateMirrorUrlSpy: jest.SpyInstance;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
inputs = {};
|
inputs = {};
|
||||||
|
|
||||||
@ -173,45 +165,6 @@ describe('main tests', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getNodeVersionFromFile', () => {
|
|
||||||
each`
|
|
||||||
contents | expected
|
|
||||||
${'12'} | ${'12'}
|
|
||||||
${'12.3'} | ${'12.3'}
|
|
||||||
${'12.3.4'} | ${'12.3.4'}
|
|
||||||
${'v12.3.4'} | ${'12.3.4'}
|
|
||||||
${'lts/erbium'} | ${'lts/erbium'}
|
|
||||||
${'lts/*'} | ${'lts/*'}
|
|
||||||
${'nodejs 12.3.4'} | ${'12.3.4'}
|
|
||||||
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
|
|
||||||
${''} | ${''}
|
|
||||||
${'unknown format'} | ${'unknown format'}
|
|
||||||
${' 14.1.0 '} | ${'14.1.0'}
|
|
||||||
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
|
|
||||||
${'{"volta": {"extends": "./package.json"}}'}| ${'18.0.0'}
|
|
||||||
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
|
|
||||||
${'{}'} | ${null}
|
|
||||||
`.it('parses "$contents"', ({contents, expected}) => {
|
|
||||||
const existsSpy = jest.spyOn(fs, 'existsSync');
|
|
||||||
existsSpy.mockImplementation(() => true);
|
|
||||||
|
|
||||||
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
|
||||||
readFileSpy.mockImplementation(filePath => {
|
|
||||||
if (
|
|
||||||
typeof filePath === 'string' &&
|
|
||||||
path.basename(filePath) === 'package.json'
|
|
||||||
) {
|
|
||||||
// Special case for volta.extends
|
|
||||||
return '{"volta": {"node": "18.0.0"}}';
|
|
||||||
}
|
|
||||||
|
|
||||||
return contents;
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(util.getNodeVersionFromFile('file')).toBe(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('node-version-file flag', () => {
|
describe('node-version-file flag', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
delete inputs['node-version'];
|
delete inputs['node-version'];
|
||||||
@ -327,41 +280,4 @@ describe('main tests', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('mirror-url parameter', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
inputs['mirror-url'] = 'https://custom-mirror-url.com';
|
|
||||||
|
|
||||||
validateMirrorUrlSpy = jest.spyOn(main, 'run');
|
|
||||||
validateMirrorUrlSpy.mockImplementation(() => {});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
validateMirrorUrlSpy.mockRestore();
|
|
||||||
});
|
|
||||||
|
|
||||||
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', () => {
|
describe('mirror-url parameter', () => {
|
||||||
it('Download mirror url if mirror-url is provided', async () => {
|
it('default if mirror url is not 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.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
|
3
dist/setup/index.js
vendored
3
dist/setup/index.js
vendored
@ -100870,8 +100870,7 @@ function run() {
|
|||||||
if (!arch) {
|
if (!arch) {
|
||||||
arch = os_1.default.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) {
|
if (version) {
|
||||||
const token = core.getInput('token');
|
const token = core.getInput('token');
|
||||||
const auth = !token ? undefined : `token ${token}`;
|
const auth = !token ? undefined : `token ${token}`;
|
||||||
|
@ -7,11 +7,7 @@ import * as path from 'path';
|
|||||||
import {restoreCache} from './cache-restore';
|
import {restoreCache} from './cache-restore';
|
||||||
import {isCacheFeatureAvailable} from './cache-utils';
|
import {isCacheFeatureAvailable} from './cache-utils';
|
||||||
import {getNodejsDistribution} from './distributions/installer-factory';
|
import {getNodejsDistribution} from './distributions/installer-factory';
|
||||||
import {
|
import {getNodeVersionFromFile, printEnvDetailsAndSetOutput} from './util';
|
||||||
getNodeVersionFromFile,
|
|
||||||
printEnvDetailsAndSetOutput,
|
|
||||||
validateMirrorURL
|
|
||||||
} from './util';
|
|
||||||
import {State} from './constants';
|
import {State} from './constants';
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
@ -37,8 +33,7 @@ export async function run() {
|
|||||||
arch = os.arch();
|
arch = os.arch();
|
||||||
}
|
}
|
||||||
|
|
||||||
const mirrorurl = core.getInput('mirror-url');
|
const mirrorURL = core.getInput('mirror-url');
|
||||||
const mirrorURL = validateMirrorURL(mirrorurl);
|
|
||||||
|
|
||||||
if (version) {
|
if (version) {
|
||||||
const token = core.getInput('token');
|
const token = core.getInput('token');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user