Skip to content

Commit c8889b2

Browse files
author
Gordey Doronin
committed
Support lts/* alias
1 parent 88d5bfd commit c8889b2

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

__tests__/installer.test.ts

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ describe('setup-node', () => {
552552
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
553553
expect(warningSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true')
554554
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'erbium' for Node version 'lts/erbium'`)
555-
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release 'erbium' for Node version 'lts/erbium'`)
555+
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '12.16.2' for Node version 'lts/erbium'`)
556556
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
557557
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
558558
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}/bin${osm.EOL}`);
@@ -580,13 +580,68 @@ describe('setup-node', () => {
580580
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
581581
expect(warningSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true')
582582
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'erbium' for Node version 'lts/erbium'`)
583-
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release 'erbium' for Node version 'lts/erbium'`)
583+
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '12.16.2' for Node version 'lts/erbium'`)
584584
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
585585
expect(logSpy).toHaveBeenCalledWith("Attempting to download 12.16.2...");
586586
expect(logSpy).toHaveBeenCalledWith(`Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}`);
587587
expect(logSpy).toHaveBeenCalledWith('Extracting ...');
588588
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
589589
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}/bin${osm.EOL}`);
590590
})
591+
592+
it('find latest LTS version and resolve it from local cache (lts/*)', async () => {
593+
// arrange
594+
os.platform = 'linux';
595+
os.arch = 'x64';
596+
597+
inputs['node-version'] = 'lts/*';
598+
inputs.stable = 'true';
599+
600+
const toolPath = path.normalize('/cache/node/14.0.0/x64');
601+
findSpy.mockReturnValue(toolPath);
602+
603+
// act
604+
await main.run();
605+
606+
// assert
607+
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
608+
expect(warningSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true')
609+
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias '*' for Node version 'lts/*'`)
610+
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '14.0.0' for Node version 'lts/*'`)
611+
expect(logSpy).toHaveBeenCalledWith("Resolved as '14.0.0'");
612+
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
613+
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}/bin${osm.EOL}`);
614+
});
615+
616+
it('find latest LTS version and install it from manifest (lts/*)', async () => {
617+
// arrange
618+
os.platform = 'linux';
619+
os.arch = 'x64';
620+
621+
inputs['node-version'] = 'lts/*';
622+
inputs.stable = 'true';
623+
624+
const toolPath = path.normalize('/cache/node/14.0.0/x64');
625+
findSpy.mockImplementation(() => '');
626+
dlSpy.mockImplementation(async () => '/some/temp/path');
627+
exSpy.mockImplementation(async () => '/some/other/temp/path');
628+
cacheSpy.mockImplementation(async () => toolPath);
629+
const expectedUrl = 'https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-linux-x64.tar.gz';
630+
631+
// act
632+
await main.run();
633+
634+
// assert
635+
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...');
636+
expect(warningSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true')
637+
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias '*' for Node version 'lts/*'`)
638+
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '14.0.0' for Node version 'lts/*'`)
639+
expect(logSpy).toHaveBeenCalledWith("Resolved as '14.0.0'");
640+
expect(logSpy).toHaveBeenCalledWith("Attempting to download 14.0.0...");
641+
expect(logSpy).toHaveBeenCalledWith(`Acquiring 14.0.0 - ${os.arch} from ${expectedUrl}`);
642+
expect(logSpy).toHaveBeenCalledWith('Extracting ...');
643+
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
644+
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}/bin${osm.EOL}`);
645+
})
591646
})
592647
});

src/installer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,15 @@ function findLtsVersionFromManifest(
192192

193193
core.debug(`LTS alias '${alias}' for Node version '${versionSpec}'`);
194194

195-
const release = candidates.find(x => x.lts?.toLowerCase() === alias && x.stable === stable);
195+
const release = alias === '*'
196+
? candidates.find(x => !!x.lts && x.stable === stable)
197+
: candidates.find(x => x.lts?.toLowerCase() === alias && x.stable === stable);
196198

197199
if (!release) {
198200
throw new Error(`Unable to find LTS release '${alias}' for Node version '${versionSpec}'.`);
199201
}
200202

201-
core.debug(`Found LTS release '${alias}' for Node version '${versionSpec}'`);
203+
core.debug(`Found LTS release '${release.version}' for Node version '${versionSpec}'`);
202204

203205
return release.version.split('.')[0];
204206
}

0 commit comments

Comments
 (0)