Skip to content

Commit d98fa11

Browse files
authored
bugfix: Don't attempt to use Windows fallbacks on non-Windows OSes (#718)
1 parent 9d255ef commit d98fa11

File tree

4 files changed

+1422
-1327
lines changed

4 files changed

+1422
-1327
lines changed

__tests__/nightly-installer.test.ts

+89
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('setup-node', () => {
3939
let whichSpy: jest.SpyInstance;
4040
let existsSpy: jest.SpyInstance;
4141
let mkdirpSpy: jest.SpyInstance;
42+
let cpSpy: jest.SpyInstance;
4243
let execSpy: jest.SpyInstance;
4344
let authSpy: jest.SpyInstance;
4445
let parseNodeVersionSpy: jest.SpyInstance;
@@ -51,6 +52,7 @@ describe('setup-node', () => {
5152
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
5253
process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
5354
process.env['GITHUB_OUTPUT'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
55+
process.env['RUNNER_TEMP'] = '/runner_temp';
5456
inputs = {};
5557
inSpy = jest.spyOn(core, 'getInput');
5658
inSpy.mockImplementation(name => inputs[name]);
@@ -78,6 +80,7 @@ describe('setup-node', () => {
7880
whichSpy = jest.spyOn(io, 'which');
7981
existsSpy = jest.spyOn(fs, 'existsSync');
8082
mkdirpSpy = jest.spyOn(io, 'mkdirP');
83+
cpSpy = jest.spyOn(io, 'cp');
8184

8285
// @actions/tool-cache
8386
isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable');
@@ -273,6 +276,92 @@ describe('setup-node', () => {
273276
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
274277
});
275278

279+
it('windows: falls back to exe version if not in manifest and not in node dist', async () => {
280+
os.platform = 'win32';
281+
os.arch = 'x64';
282+
283+
// a version which is not in the manifest but is in node dist
284+
const versionSpec = '13.13.1-nightly20200415947ddec091';
285+
286+
const workingUrls = [
287+
`https://nodejs.org/download/nightly/v${versionSpec}/win-x64/node.exe`,
288+
`https://nodejs.org/download/nightly/v${versionSpec}/win-x64/node.lib`
289+
];
290+
291+
inputs['node-version'] = versionSpec;
292+
inputs['always-auth'] = false;
293+
inputs['token'] = 'faketoken';
294+
295+
// ... but not in the local cache
296+
findSpy.mockImplementation(() => '');
297+
findAllVersionsSpy.mockImplementation(() => []);
298+
299+
dlSpy.mockImplementation(async url => {
300+
if (workingUrls.includes(url)) {
301+
return '/some/temp/path';
302+
}
303+
304+
throw new tc.HTTPError(404);
305+
});
306+
const toolPath = path.normalize(
307+
'/cache/node/13.13.1-nightly20200415947ddec091/x64'
308+
);
309+
cacheSpy.mockImplementation(async () => toolPath);
310+
mkdirpSpy.mockImplementation(async () => {});
311+
cpSpy.mockImplementation(async () => {});
312+
313+
await main.run();
314+
315+
workingUrls.forEach(url => {
316+
expect(dlSpy).toHaveBeenCalledWith(url);
317+
});
318+
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}${osm.EOL}`);
319+
});
320+
321+
it('linux: does not fall back to exe version if not in manifest and not in node dist', async () => {
322+
os.platform = 'linux';
323+
os.arch = 'x64';
324+
325+
// a version which is not in the manifest but is in node dist
326+
const versionSpec = '13.13.1-nightly20200415947ddec091';
327+
328+
const workingUrls = [
329+
`https://nodejs.org/download/nightly/v${versionSpec}/win-x64/node.exe`,
330+
`https://nodejs.org/download/nightly/v${versionSpec}/win-x64/node.lib`
331+
];
332+
333+
inputs['node-version'] = versionSpec;
334+
inputs['always-auth'] = false;
335+
inputs['token'] = 'faketoken';
336+
337+
// ... but not in the local cache
338+
findSpy.mockImplementation(() => '');
339+
findAllVersionsSpy.mockImplementation(() => []);
340+
341+
dlSpy.mockImplementation(async url => {
342+
if (workingUrls.includes(url)) {
343+
return '/some/temp/path';
344+
}
345+
346+
throw new tc.HTTPError(404);
347+
});
348+
const toolPath = path.normalize(
349+
'/cache/node/13.13.1-nightly20200415947ddec091/x64'
350+
);
351+
cacheSpy.mockImplementation(async () => toolPath);
352+
mkdirpSpy.mockImplementation(async () => {});
353+
cpSpy.mockImplementation(async () => {});
354+
355+
await main.run();
356+
357+
workingUrls.forEach(url => {
358+
expect(dlSpy).not.toHaveBeenCalledWith(url);
359+
});
360+
expect(cnSpy).toHaveBeenCalledWith(
361+
`::error::Unexpected HTTP response: 404${osm.EOL}`
362+
);
363+
});
364+
276365
it('does not find a version that does not exist', async () => {
277366
os.platform = 'linux';
278367
os.arch = 'x64';

0 commit comments

Comments
 (0)