resolve comment for check-latest

This commit is contained in:
Dmitry Shibanov 2021-03-22 12:14:18 +03:00
parent 61c3e48d26
commit 6e6487b787
7 changed files with 105 additions and 52 deletions

View file

@ -27,19 +27,19 @@ describe('getAvailableVersions', () => {
it.each([ it.each([
[ [
{ version: '11', architecture: 'x64', packageType: 'jdk' }, { version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
'os=mac&architecture=x64&image_type=jdk&release_type=ga&page_size=20&page=0' 'os=mac&architecture=x64&image_type=jdk&release_type=ga&page_size=20&page=0'
], ],
[ [
{ version: '11', architecture: 'x86', packageType: 'jdk' }, { version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false },
'os=mac&architecture=x86&image_type=jdk&release_type=ga&page_size=20&page=0' 'os=mac&architecture=x86&image_type=jdk&release_type=ga&page_size=20&page=0'
], ],
[ [
{ version: '11', architecture: 'x64', packageType: 'jre' }, { version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false },
'os=mac&architecture=x64&image_type=jre&release_type=ga&page_size=20&page=0' 'os=mac&architecture=x64&image_type=jre&release_type=ga&page_size=20&page=0'
], ],
[ [
{ version: '11-ea', architecture: 'x64', packageType: 'jdk' }, { version: '11-ea', architecture: 'x64', packageType: 'jdk', checkLatest: false },
'os=mac&architecture=x64&image_type=jdk&release_type=ea&page_size=20&page=0' 'os=mac&architecture=x64&image_type=jdk&release_type=ea&page_size=20&page=0'
] ]
])( ])(
@ -79,7 +79,8 @@ describe('getAvailableVersions', () => {
const distribution = new AdoptDistribution({ const distribution = new AdoptDistribution({
version: '11', version: '11',
architecture: 'x64', architecture: 'x64',
packageType: 'jdk' packageType: 'jdk',
checkLatest: false
}); });
const availableVersions = await distribution['getAvailableVersions'](); const availableVersions = await distribution['getAvailableVersions']();
expect(availableVersions).not.toBeNull(); expect(availableVersions).not.toBeNull();
@ -104,7 +105,8 @@ describe('findPackageForDownload', () => {
const distribution = new AdoptDistribution({ const distribution = new AdoptDistribution({
version: '11', version: '11',
architecture: 'x64', architecture: 'x64',
packageType: 'jdk' packageType: 'jdk',
checkLatest: false
}); });
distribution['getAvailableVersions'] = async () => manifestData; distribution['getAvailableVersions'] = async () => manifestData;
const resolvedVersion = await distribution['findPackageForDownload'](input); const resolvedVersion = await distribution['findPackageForDownload'](input);
@ -115,7 +117,8 @@ describe('findPackageForDownload', () => {
const distribution = new AdoptDistribution({ const distribution = new AdoptDistribution({
version: '11', version: '11',
architecture: 'x64', architecture: 'x64',
packageType: 'jdk' packageType: 'jdk',
checkLatest: false
}); });
distribution['getAvailableVersions'] = async () => manifestData; distribution['getAvailableVersions'] = async () => manifestData;
await expect(distribution['findPackageForDownload']('9.0.8')).rejects.toThrowError( await expect(distribution['findPackageForDownload']('9.0.8')).rejects.toThrowError(
@ -127,7 +130,8 @@ describe('findPackageForDownload', () => {
const distribution = new AdoptDistribution({ const distribution = new AdoptDistribution({
version: '11', version: '11',
architecture: 'x64', architecture: 'x64',
packageType: 'jdk' packageType: 'jdk',
checkLatest: false
}); });
distribution['getAvailableVersions'] = async () => manifestData; distribution['getAvailableVersions'] = async () => manifestData;
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrowError( await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrowError(
@ -139,7 +143,8 @@ describe('findPackageForDownload', () => {
const distribution = new AdoptDistribution({ const distribution = new AdoptDistribution({
version: '11', version: '11',
architecture: 'x64', architecture: 'x64',
packageType: 'jdk' packageType: 'jdk',
checkLatest: false
}); });
distribution['getAvailableVersions'] = async () => []; distribution['getAvailableVersions'] = async () => [];
await expect(distribution['findPackageForDownload']('11')).rejects.toThrowError( await expect(distribution['findPackageForDownload']('11')).rejects.toThrowError(

View file

@ -58,15 +58,15 @@ describe('findInToolcache', () => {
it.each([ it.each([
[ [
{ version: '11', architecture: 'x64', packageType: 'jdk' }, { version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{ version: actualJavaVersion, path: javaPath } { version: actualJavaVersion, path: javaPath }
], ],
[ [
{ version: '11.0', architecture: 'x64', packageType: 'jdk' }, { version: '11.0', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{ version: actualJavaVersion, path: javaPath } { version: actualJavaVersion, path: javaPath }
], ],
[ [
{ version: '11.0.8', architecture: 'x64', packageType: 'jdk' }, { version: '11.0.8', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{ version: actualJavaVersion, path: javaPath } { version: actualJavaVersion, path: javaPath }
], ],
[ [
@ -81,10 +81,10 @@ describe('findInToolcache', () => {
{ version: '11.0.8', architecture: 'x64', packageType: 'jdk', checkLatest: true }, { version: '11.0.8', architecture: 'x64', packageType: 'jdk', checkLatest: true },
{ version: actualJavaVersion, path: javaPath } { version: actualJavaVersion, path: javaPath }
], ],
[{ version: '11', architecture: 'x64', packageType: 'jre' }, null], [{ version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false }, null],
[{ version: '8', architecture: 'x64', packageType: 'jdk' }, null], [{ version: '8', architecture: 'x64', packageType: 'jdk', checkLatest: false }, null],
[{ version: '11', architecture: 'x86', packageType: 'jdk' }, null], [{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false }, null],
[{ version: '11', architecture: 'x86', packageType: 'jre' }, null] [{ version: '11', architecture: 'x86', packageType: 'jre', checkLatest: false }, null]
])(`should find java for path %s -> %s`, (input, expected) => { ])(`should find java for path %s -> %s`, (input, expected) => {
spyTcFindAllVersions.mockReturnValue([actualJavaVersion]); spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
spyGetToolcachePath.mockImplementation( spyGetToolcachePath.mockImplementation(
@ -127,7 +127,12 @@ describe('findInToolcache', () => {
(toolname: string, javaVersion: string, architecture: string) => (toolname: string, javaVersion: string, architecture: string) =>
`/hostedtoolcache/${toolname}/${javaVersion}/${architecture}` `/hostedtoolcache/${toolname}/${javaVersion}/${architecture}`
); );
mockJavaBase = new EmptyJavaBase({ version: input, architecture: 'x64', packageType: 'jdk' }); mockJavaBase = new EmptyJavaBase({
version: input,
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
const foundVersion = mockJavaBase['findInToolcache'](); const foundVersion = mockJavaBase['findInToolcache']();
expect(foundVersion?.version).toEqual(expected); expect(foundVersion?.version).toEqual(expected);
}); });
@ -191,15 +196,15 @@ describe('setupJava', () => {
it.each([ it.each([
[ [
{ version: '11', architecture: 'x86', packageType: 'jdk' }, { version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{ version: installedJavaVersion, path: javaPath } { version: installedJavaVersion, path: javaPath }
], ],
[ [
{ version: '11.0', architecture: 'x86', packageType: 'jdk' }, { version: '11.0', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{ version: installedJavaVersion, path: javaPath } { version: installedJavaVersion, path: javaPath }
], ],
[ [
{ version: '11.0.8', architecture: 'x86', packageType: 'jdk' }, { version: '11.0.8', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{ version: installedJavaVersion, path: javaPath } { version: installedJavaVersion, path: javaPath }
] ]
])('should find java locally for %s', (input, expected) => { ])('should find java locally for %s', (input, expected) => {
@ -216,15 +221,15 @@ describe('setupJava', () => {
it.each([ it.each([
[ [
{ version: '11', architecture: 'x86', packageType: 'jre' }, { version: '11', architecture: 'x86', packageType: 'jre', checkLatest: false },
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'), version: '11.0.9' } { path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'), version: '11.0.9' }
], ],
[ [
{ version: '11', architecture: 'x64', packageType: 'jdk' }, { version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{ path: path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64'), version: '11.0.9' } { path: path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64'), version: '11.0.9' }
], ],
[ [
{ version: '11', architecture: 'x64', packageType: 'jre' }, { version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false },
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x64'), version: '11.0.9' } { path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x64'), version: '11.0.9' }
] ]
])('download java with configuration %s', async (input, expected) => { ])('download java with configuration %s', async (input, expected) => {
@ -281,8 +286,8 @@ describe('setupJava', () => {
}); });
it.each([ it.each([
[{ version: '15', architecture: 'x86', packageType: 'jre' }], [{ version: '15', architecture: 'x86', packageType: 'jre', checkLatest: false }],
[{ version: '11.0.7', architecture: 'x64', packageType: 'jre' }] [{ version: '11.0.7', architecture: 'x64', packageType: 'jre', checkLatest: false }]
])('should throw an error for Available version not found for %s', async input => { ])('should throw an error for Available version not found for %s', async input => {
mockJavaBase = new EmptyJavaBase(input); mockJavaBase = new EmptyJavaBase(input);
await expect(mockJavaBase.setupJava()).rejects.toThrowError('Available version not found'); await expect(mockJavaBase.setupJava()).rejects.toThrowError('Available version not found');

View file

@ -93,7 +93,12 @@ describe('setupJava', () => {
}); });
it('java is resolved from toolcache, jdkfile is untouched', async () => { it('java is resolved from toolcache, jdkfile is untouched', async () => {
const inputs = { version: actualJavaVersion, architecture: 'x86', packageType: 'jdk' }; const inputs = {
version: actualJavaVersion,
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
};
const jdkFile = 'not_existing_one'; const jdkFile = 'not_existing_one';
const expected = { const expected = {
version: actualJavaVersion, version: actualJavaVersion,
@ -110,7 +115,12 @@ describe('setupJava', () => {
}); });
it("java is resolved from toolcache, jdkfile doesn't exist", async () => { it("java is resolved from toolcache, jdkfile doesn't exist", async () => {
const inputs = { version: actualJavaVersion, architecture: 'x86', packageType: 'jdk' }; const inputs = {
version: actualJavaVersion,
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
};
const jdkFile = undefined; const jdkFile = undefined;
const expected = { const expected = {
version: actualJavaVersion, version: actualJavaVersion,
@ -127,7 +137,12 @@ describe('setupJava', () => {
}); });
it('java is unpacked from jdkfile', async () => { it('java is unpacked from jdkfile', async () => {
const inputs = { version: '11.0.289', architecture: 'x86', packageType: 'jdk' }; const inputs = {
version: '11.0.289',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
};
const jdkFile = expectedJdkFile; const jdkFile = expectedJdkFile;
const expected = { const expected = {
version: '11.0.289', version: '11.0.289',
@ -147,7 +162,12 @@ describe('setupJava', () => {
}); });
it('jdk file is not found', async () => { it('jdk file is not found', async () => {
const inputs = { version: '11.0.289', architecture: 'x86', packageType: 'jdk' }; const inputs = {
version: '11.0.289',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
};
const jdkFile = 'not_existing_one'; const jdkFile = 'not_existing_one';
const expected = { const expected = {
javaVersion: '11.0.289', javaVersion: '11.0.289',
@ -170,10 +190,22 @@ describe('setupJava', () => {
}); });
it.each([ it.each([
[{ version: '8.0.289', architecture: 'x64', packageType: 'jdk' }, 'otherJdkFile'], [
[{ version: '11.0.289', architecture: 'x64', packageType: 'jdk' }, 'otherJdkFile'], { version: '8.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false },
[{ version: '12.0.289', architecture: 'x64', packageType: 'jdk' }, 'otherJdkFile'], 'otherJdkFile'
[{ version: '11.1.11', architecture: 'x64', packageType: 'jdk' }, 'not_existing_one'] ],
[
{ version: '11.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false },
'otherJdkFile'
],
[
{ version: '12.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false },
'otherJdkFile'
],
[
{ version: '11.1.11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
'not_existing_one'
]
])( ])(
`Throw an error if jdkfile has wrong path, inputs %s, jdkfile %s, real name ${expectedJdkFile}`, `Throw an error if jdkfile has wrong path, inputs %s, jdkfile %s, real name ${expectedJdkFile}`,
async (inputs, jdkFile) => { async (inputs, jdkFile) => {
@ -186,9 +218,15 @@ describe('setupJava', () => {
); );
it.each([ it.each([
[{ version: '8.0.289', architecture: 'x64', packageType: 'jdk' }, ''], [{ version: '8.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false }, ''],
[{ version: '7.0.289', architecture: 'x64', packageType: 'jdk' }, undefined], [
[{ version: '11.0.289', architecture: 'x64', packageType: 'jdk' }, undefined] { version: '7.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false },
undefined
],
[
{ version: '11.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false },
undefined
]
])('Throw an error if jdkfile is not specified, inputs %s', async (inputs, jdkFile) => { ])('Throw an error if jdkfile is not specified, inputs %s', async (inputs, jdkFile) => {
mockJavaBase = new LocalDistribution(inputs, jdkFile); mockJavaBase = new LocalDistribution(inputs, jdkFile);
await expect(mockJavaBase.setupJava()).rejects.toThrowError("'jdkFile' is not specified"); await expect(mockJavaBase.setupJava()).rejects.toThrowError("'jdkFile' is not specified");

View file

@ -30,27 +30,27 @@ describe('getAvailableVersions', () => {
it.each([ it.each([
[ [
{ version: '11', architecture: 'x86', packageType: 'jdk' }, { version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=32&release_status=ga' '?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=32&release_status=ga'
], ],
[ [
{ version: '11-ea', architecture: 'x86', packageType: 'jdk' }, { version: '11-ea', architecture: 'x86', packageType: 'jdk', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=32&release_status=ea' '?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=32&release_status=ea'
], ],
[ [
{ version: '8', architecture: 'x64', packageType: 'jdk' }, { version: '8', architecture: 'x64', packageType: 'jdk', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=64&release_status=ga' '?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=64&release_status=ga'
], ],
[ [
{ version: '8', architecture: 'x64', packageType: 'jre' }, { version: '8', architecture: 'x64', packageType: 'jre', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jre&javafx=false&arch=x86&hw_bitness=64&release_status=ga' '?os=macos&ext=tar.gz&bundle_type=jre&javafx=false&arch=x86&hw_bitness=64&release_status=ga'
], ],
[ [
{ version: '8', architecture: 'x64', packageType: 'jdk+fx' }, { version: '8', architecture: 'x64', packageType: 'jdk+fx', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=true&arch=x86&hw_bitness=64&release_status=ga&features=fx' '?os=macos&ext=tar.gz&bundle_type=jdk&javafx=true&arch=x86&hw_bitness=64&release_status=ga&features=fx'
], ],
[ [
{ version: '8', architecture: 'x64', packageType: 'jre+fx' }, { version: '8', architecture: 'x64', packageType: 'jre+fx', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jre&javafx=true&arch=x86&hw_bitness=64&release_status=ga&features=fx' '?os=macos&ext=tar.gz&bundle_type=jre&javafx=true&arch=x86&hw_bitness=64&release_status=ga&features=fx'
] ]
])('build correct url for %s -> %s', async (input, parsedUrl) => { ])('build correct url for %s -> %s', async (input, parsedUrl) => {
@ -68,7 +68,8 @@ describe('getAvailableVersions', () => {
const distribution = new ZuluDistribution({ const distribution = new ZuluDistribution({
version: '11', version: '11',
architecture: 'x86', architecture: 'x86',
packageType: 'jdk' packageType: 'jdk',
checkLatest: false
}); });
const availableVersions = await distribution['getAvailableVersions'](); const availableVersions = await distribution['getAvailableVersions']();
expect(availableVersions).toHaveLength(manifestData.length); expect(availableVersions).toHaveLength(manifestData.length);
@ -85,7 +86,8 @@ describe('getArchitectureOptions', () => {
const distribution = new ZuluDistribution({ const distribution = new ZuluDistribution({
version: '11', version: '11',
architecture: input.architecture, architecture: input.architecture,
packageType: 'jdk' packageType: 'jdk',
checkLatest: false
}); });
expect(distribution['getArchitectureOptions']()).toEqual(expected); expect(distribution['getArchitectureOptions']()).toEqual(expected);
}); });
@ -108,7 +110,8 @@ describe('findPackageForDownload', () => {
const distribution = new ZuluDistribution({ const distribution = new ZuluDistribution({
version: input, version: input,
architecture: 'x86', architecture: 'x86',
packageType: 'jdk' packageType: 'jdk',
checkLatest: false
}); });
distribution['getAvailableVersions'] = async () => manifestData; distribution['getAvailableVersions'] = async () => manifestData;
const result = await distribution['findPackageForDownload'](distribution['version']); const result = await distribution['findPackageForDownload'](distribution['version']);
@ -119,7 +122,8 @@ describe('findPackageForDownload', () => {
const distribution = new ZuluDistribution({ const distribution = new ZuluDistribution({
version: '', version: '',
architecture: 'x86', architecture: 'x86',
packageType: 'jdk' packageType: 'jdk',
checkLatest: false
}); });
distribution['getAvailableVersions'] = async () => manifestData; distribution['getAvailableVersions'] = async () => manifestData;
const result = await distribution['findPackageForDownload']('11.0.5'); const result = await distribution['findPackageForDownload']('11.0.5');
@ -132,7 +136,8 @@ describe('findPackageForDownload', () => {
const distribution = new ZuluDistribution({ const distribution = new ZuluDistribution({
version: '18', version: '18',
architecture: 'x86', architecture: 'x86',
packageType: 'jdk' packageType: 'jdk',
checkLatest: false
}); });
await expect( await expect(
distribution['findPackageForDownload'](distribution['version']) distribution['findPackageForDownload'](distribution['version'])
@ -151,7 +156,8 @@ describe('convertVersionToSemver', () => {
const distribution = new ZuluDistribution({ const distribution = new ZuluDistribution({
version: '18', version: '18',
architecture: 'x86', architecture: 'x86',
packageType: 'jdk' packageType: 'jdk',
checkLatest: false
}); });
const actual = distribution['convertVersionToSemver'](input); const actual = distribution['convertVersionToSemver'](input);
expect(actual).toBe(expected); expect(actual).toBe(expected);

3
dist/setup/index.js vendored
View file

@ -3959,7 +3959,6 @@ const util_1 = __webpack_require__(322);
const constants_1 = __webpack_require__(211); const constants_1 = __webpack_require__(211);
class JavaBase { class JavaBase {
constructor(distribution, installerOptions) { constructor(distribution, installerOptions) {
var _a;
this.distribution = distribution; this.distribution = distribution;
this.http = new httpm.HttpClient('actions/setup-java', undefined, { this.http = new httpm.HttpClient('actions/setup-java', undefined, {
allowRetries: true, allowRetries: true,
@ -3968,7 +3967,7 @@ class JavaBase {
({ version: this.version, stable: this.stable } = this.normalizeVersion(installerOptions.version)); ({ version: this.version, stable: this.stable } = this.normalizeVersion(installerOptions.version));
this.architecture = installerOptions.architecture; this.architecture = installerOptions.architecture;
this.packageType = installerOptions.packageType; this.packageType = installerOptions.packageType;
this.checkLatest = (_a = installerOptions.checkLatest) !== null && _a !== void 0 ? _a : false; this.checkLatest = installerOptions.checkLatest;
} }
setupJava() { setupJava() {
var _a, _b; var _a, _b;

View file

@ -27,7 +27,7 @@ export abstract class JavaBase {
)); ));
this.architecture = installerOptions.architecture; this.architecture = installerOptions.architecture;
this.packageType = installerOptions.packageType; this.packageType = installerOptions.packageType;
this.checkLatest = installerOptions.checkLatest ?? false; this.checkLatest = installerOptions.checkLatest;
} }
protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults>; protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults>;

View file

@ -2,7 +2,7 @@ export interface JavaInstallerOptions {
version: string; version: string;
architecture: string; architecture: string;
packageType: string; packageType: string;
checkLatest?: boolean; checkLatest: boolean;
} }
export interface JavaInstallerResults { export interface JavaInstallerResults {