feat: add allow-alpha input for Node.js alpha releases (#1674)
This commit is contained in:
1 parent
66f83c8206
commit
387287a7d3
9 files changed
+330
-16
No files matched your search
@@ -792,6 +792,160 @@ describe('setup-node', () => {
|
||||
}, 10000);
|
||||
});
|
||||
|
||||
describe('allow-alpha', () => {
|
||||
const olderAlpha = '27.0.0-alpha.0.0.9';
|
||||
const newestAlpha = '27.0.0-alpha.0.0.10';
|
||||
const files = ['linux-x64'];
|
||||
let releases: INodeVersion[];
|
||||
|
||||
function expectInstalled(version: string) {
|
||||
const toolPath = path.normalize(`/cache/node/${version}/${os.arch}`);
|
||||
cacheSpy.mockImplementation(async () => toolPath);
|
||||
getExecOutputSpy.mockImplementation(async () => ({
|
||||
stdout: `v${version}`,
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
}));
|
||||
return toolPath;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
os.platform = 'linux';
|
||||
os.arch = 'x64';
|
||||
inputs['allow-alpha'] = 'true';
|
||||
inputs['node-version'] = '27';
|
||||
releases = [
|
||||
{version: `v${olderAlpha}`, files},
|
||||
{version: `v${newestAlpha}`, files},
|
||||
{version: 'v28.0.0-alpha.0.0.0', files},
|
||||
{version: 'v26.1.0', files}
|
||||
];
|
||||
getJsonSpy.mockImplementation(async () => ({result: releases}));
|
||||
findSpy.mockReturnValue('');
|
||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||
exSpy.mockImplementation(async () => '/some/extracted/path');
|
||||
});
|
||||
|
||||
it.each([
|
||||
'27',
|
||||
'27.x',
|
||||
'27.0',
|
||||
'27.0.0',
|
||||
'^27.0.0',
|
||||
'~27.0.0',
|
||||
'>=27.0.0 <28.0.0'
|
||||
])('selects the newest matching alpha for %s', async versionSpec => {
|
||||
inputs['node-version'] = versionSpec;
|
||||
expectInstalled(newestAlpha);
|
||||
|
||||
await main.run();
|
||||
|
||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||
expect(dlSpy).toHaveBeenCalledWith(
|
||||
`https://nodejs.org/dist/v${newestAlpha}/node-v${newestAlpha}-linux-x64.tar.gz`,
|
||||
undefined,
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
it.each(['27', '27.0.0'])(
|
||||
'prefers a stable release for %s over a newer alpha',
|
||||
async versionSpec => {
|
||||
inputs['node-version'] = versionSpec;
|
||||
releases.push({version: 'v27.0.0', files});
|
||||
expectInstalled('27.0.0');
|
||||
|
||||
await main.run();
|
||||
|
||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||
expect(cacheSpy).toHaveBeenCalledWith(
|
||||
'/some/extracted/path',
|
||||
'node',
|
||||
'27.0.0',
|
||||
'x64'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([undefined, 'false'])(
|
||||
'does not select an alpha and suggests the input when allow-alpha is %s',
|
||||
async allowAlpha => {
|
||||
inputs['allow-alpha'] = allowAlpha;
|
||||
await main.run();
|
||||
expect(setFailedSpy).toHaveBeenCalledWith(
|
||||
"Unable to find Node version '27' for platform linux and architecture x64. A matching alpha release is available; set 'allow-alpha: true' to use it."
|
||||
);
|
||||
expect(dlSpy).not.toHaveBeenCalled();
|
||||
}
|
||||
);
|
||||
|
||||
it.each(['latest', 'current', 'node'])(
|
||||
'installs the newest stable release for %s',
|
||||
async versionSpec => {
|
||||
inputs['node-version'] = versionSpec;
|
||||
expectInstalled('26.1.0');
|
||||
|
||||
await main.run();
|
||||
|
||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||
expect(cacheSpy).toHaveBeenCalledWith(
|
||||
'/some/extracted/path',
|
||||
'node',
|
||||
'26.1.0',
|
||||
'x64'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
it('does not suggest allow-alpha when no alpha matches', async () => {
|
||||
inputs['allow-alpha'] = 'false';
|
||||
inputs['node-version'] = '29';
|
||||
await main.run();
|
||||
expect(setFailedSpy).toHaveBeenCalledWith(
|
||||
"Unable to find Node version '29' for platform linux and architecture x64."
|
||||
);
|
||||
});
|
||||
|
||||
it('respects an explicit prerelease lower bound', async () => {
|
||||
inputs['node-version'] = '>=27.0.0-alpha.0.0.99';
|
||||
await main.run();
|
||||
expect(setFailedSpy).toHaveBeenCalledWith(
|
||||
"Unable to find Node version '>=27.0.0-alpha.0.0.99' for platform linux and architecture x64."
|
||||
);
|
||||
expect(dlSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('reuses a cached alpha instead of downloading it again', async () => {
|
||||
const toolPath = expectInstalled(newestAlpha);
|
||||
findSpy.mockImplementation((_tool, version) =>
|
||||
version === `v${newestAlpha}` ? toolPath : ''
|
||||
);
|
||||
|
||||
await main.run();
|
||||
|
||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||
expect(dlSpy).not.toHaveBeenCalled();
|
||||
expect(addPathSpy).toHaveBeenCalledWith(path.join(toolPath, 'bin'));
|
||||
});
|
||||
|
||||
it('downloads a newer alpha when only an older alpha is cached', async () => {
|
||||
findSpy.mockImplementation((_tool, version) =>
|
||||
version === `v${olderAlpha}` ? `/cache/node/${olderAlpha}/x64` : ''
|
||||
);
|
||||
expectInstalled(newestAlpha);
|
||||
|
||||
await main.run();
|
||||
|
||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||
expect(cacheSpy).toHaveBeenCalledWith(
|
||||
'/some/extracted/path',
|
||||
'node',
|
||||
newestAlpha,
|
||||
'x64'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('LTS version', () => {
|
||||
useRetryTimers();
|
||||
|
||||
|
||||
Reference in new issue
Block a user