mirror of
https://github.com/actions/setup-node
synced 2024-11-09 15:12:40 +00:00
bugfix: Don't attempt to use Windows fallbacks on non-Windows OSes (#718)
This commit is contained in:
parent
9d255ef245
commit
d98fa11138
4 changed files with 1419 additions and 1324 deletions
|
@ -39,6 +39,7 @@ describe('setup-node', () => {
|
|||
let whichSpy: jest.SpyInstance;
|
||||
let existsSpy: jest.SpyInstance;
|
||||
let mkdirpSpy: jest.SpyInstance;
|
||||
let cpSpy: jest.SpyInstance;
|
||||
let execSpy: jest.SpyInstance;
|
||||
let authSpy: jest.SpyInstance;
|
||||
let parseNodeVersionSpy: jest.SpyInstance;
|
||||
|
@ -51,6 +52,7 @@ describe('setup-node', () => {
|
|||
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
|
||||
process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
|
||||
process.env['GITHUB_OUTPUT'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
|
||||
process.env['RUNNER_TEMP'] = '/runner_temp';
|
||||
inputs = {};
|
||||
inSpy = jest.spyOn(core, 'getInput');
|
||||
inSpy.mockImplementation(name => inputs[name]);
|
||||
|
@ -78,6 +80,7 @@ describe('setup-node', () => {
|
|||
whichSpy = jest.spyOn(io, 'which');
|
||||
existsSpy = jest.spyOn(fs, 'existsSync');
|
||||
mkdirpSpy = jest.spyOn(io, 'mkdirP');
|
||||
cpSpy = jest.spyOn(io, 'cp');
|
||||
|
||||
// @actions/tool-cache
|
||||
isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable');
|
||||
|
@ -273,6 +276,92 @@ describe('setup-node', () => {
|
|||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||
});
|
||||
|
||||
it('windows: falls back to exe version if not in manifest and not in node dist', async () => {
|
||||
os.platform = 'win32';
|
||||
os.arch = 'x64';
|
||||
|
||||
// a version which is not in the manifest but is in node dist
|
||||
const versionSpec = '13.13.1-nightly20200415947ddec091';
|
||||
|
||||
const workingUrls = [
|
||||
`https://nodejs.org/download/nightly/v${versionSpec}/win-x64/node.exe`,
|
||||
`https://nodejs.org/download/nightly/v${versionSpec}/win-x64/node.lib`
|
||||
];
|
||||
|
||||
inputs['node-version'] = versionSpec;
|
||||
inputs['always-auth'] = false;
|
||||
inputs['token'] = 'faketoken';
|
||||
|
||||
// ... but not in the local cache
|
||||
findSpy.mockImplementation(() => '');
|
||||
findAllVersionsSpy.mockImplementation(() => []);
|
||||
|
||||
dlSpy.mockImplementation(async url => {
|
||||
if (workingUrls.includes(url)) {
|
||||
return '/some/temp/path';
|
||||
}
|
||||
|
||||
throw new tc.HTTPError(404);
|
||||
});
|
||||
const toolPath = path.normalize(
|
||||
'/cache/node/13.13.1-nightly20200415947ddec091/x64'
|
||||
);
|
||||
cacheSpy.mockImplementation(async () => toolPath);
|
||||
mkdirpSpy.mockImplementation(async () => {});
|
||||
cpSpy.mockImplementation(async () => {});
|
||||
|
||||
await main.run();
|
||||
|
||||
workingUrls.forEach(url => {
|
||||
expect(dlSpy).toHaveBeenCalledWith(url);
|
||||
});
|
||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}${osm.EOL}`);
|
||||
});
|
||||
|
||||
it('linux: does not fall back to exe version if not in manifest and not in node dist', async () => {
|
||||
os.platform = 'linux';
|
||||
os.arch = 'x64';
|
||||
|
||||
// a version which is not in the manifest but is in node dist
|
||||
const versionSpec = '13.13.1-nightly20200415947ddec091';
|
||||
|
||||
const workingUrls = [
|
||||
`https://nodejs.org/download/nightly/v${versionSpec}/win-x64/node.exe`,
|
||||
`https://nodejs.org/download/nightly/v${versionSpec}/win-x64/node.lib`
|
||||
];
|
||||
|
||||
inputs['node-version'] = versionSpec;
|
||||
inputs['always-auth'] = false;
|
||||
inputs['token'] = 'faketoken';
|
||||
|
||||
// ... but not in the local cache
|
||||
findSpy.mockImplementation(() => '');
|
||||
findAllVersionsSpy.mockImplementation(() => []);
|
||||
|
||||
dlSpy.mockImplementation(async url => {
|
||||
if (workingUrls.includes(url)) {
|
||||
return '/some/temp/path';
|
||||
}
|
||||
|
||||
throw new tc.HTTPError(404);
|
||||
});
|
||||
const toolPath = path.normalize(
|
||||
'/cache/node/13.13.1-nightly20200415947ddec091/x64'
|
||||
);
|
||||
cacheSpy.mockImplementation(async () => toolPath);
|
||||
mkdirpSpy.mockImplementation(async () => {});
|
||||
cpSpy.mockImplementation(async () => {});
|
||||
|
||||
await main.run();
|
||||
|
||||
workingUrls.forEach(url => {
|
||||
expect(dlSpy).not.toHaveBeenCalledWith(url);
|
||||
});
|
||||
expect(cnSpy).toHaveBeenCalledWith(
|
||||
`::error::Unexpected HTTP response: 404${osm.EOL}`
|
||||
);
|
||||
});
|
||||
|
||||
it('does not find a version that does not exist', async () => {
|
||||
os.platform = 'linux';
|
||||
os.arch = 'x64';
|
||||
|
|
8
dist/setup/index.js
vendored
8
dist/setup/index.js
vendored
|
@ -73441,8 +73441,10 @@ class BaseDistribution {
|
|||
downloadPath = yield tc.downloadTool(info.downloadUrl);
|
||||
}
|
||||
catch (err) {
|
||||
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
|
||||
return yield this.acquireNodeFromFallbackLocation(info.resolvedVersion, info.arch);
|
||||
if (err instanceof tc.HTTPError &&
|
||||
err.httpStatusCode == 404 &&
|
||||
this.osPlat == 'win32') {
|
||||
return yield this.acquireWindowsNodeFromFallbackLocation(info.resolvedVersion, info.arch);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
@ -73458,7 +73460,7 @@ class BaseDistribution {
|
|||
const valid = (_a = semver_1.default.valid(c)) !== null && _a !== void 0 ? _a : versionSpec;
|
||||
return { range: valid, options };
|
||||
}
|
||||
acquireNodeFromFallbackLocation(version, arch = os_1.default.arch()) {
|
||||
acquireWindowsNodeFromFallbackLocation(version, arch = os_1.default.arch()) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const initialUrl = this.getDistributionUrl();
|
||||
const osArch = this.translateArchToDistUrl(arch);
|
||||
|
|
|
@ -127,8 +127,12 @@ export default abstract class BaseDistribution {
|
|||
try {
|
||||
downloadPath = await tc.downloadTool(info.downloadUrl);
|
||||
} catch (err) {
|
||||
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
|
||||
return await this.acquireNodeFromFallbackLocation(
|
||||
if (
|
||||
err instanceof tc.HTTPError &&
|
||||
err.httpStatusCode == 404 &&
|
||||
this.osPlat == 'win32'
|
||||
) {
|
||||
return await this.acquireWindowsNodeFromFallbackLocation(
|
||||
info.resolvedVersion,
|
||||
info.arch
|
||||
);
|
||||
|
@ -151,7 +155,7 @@ export default abstract class BaseDistribution {
|
|||
return {range: valid, options};
|
||||
}
|
||||
|
||||
protected async acquireNodeFromFallbackLocation(
|
||||
protected async acquireWindowsNodeFromFallbackLocation(
|
||||
version: string,
|
||||
arch: string = os.arch()
|
||||
): Promise<string> {
|
||||
|
|
Loading…
Reference in a new issue