mirror of
https://github.com/actions/setup-java.git
synced 2025-04-21 02:16:45 +00:00
pull latest main
This commit is contained in:
parent
793a1df84f
commit
e9a0f2c685
8 changed files with 172 additions and 92 deletions
|
@ -528,6 +528,47 @@
|
|||
"semver": "12.0.2+10.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"binaries": [
|
||||
{
|
||||
"architecture": "x64",
|
||||
"download_count": 24493,
|
||||
"heap_size": "normal",
|
||||
"image_type": "jdk",
|
||||
"jvm_impl": "hotspot",
|
||||
"os": "mac",
|
||||
"package": {
|
||||
"checksum": "9919eee037554d40c7d2f219bbd654f2bf119e16a2f4d284d8dedaf525ee59e6",
|
||||
"checksum_link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.2%2B10/OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz.sha256.txt",
|
||||
"download_count": 22907,
|
||||
"link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.2%2B10/OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz",
|
||||
"metadata_link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.2%2B10/OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz.json",
|
||||
"name": "OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz",
|
||||
"size": 198392994
|
||||
},
|
||||
"project": "jdk",
|
||||
"scm_ref": "jdk-12.0.2+9_adopt",
|
||||
"updated_at": "2019-07-18T20:27:24Z"
|
||||
}
|
||||
],
|
||||
"download_count": 396318,
|
||||
"id": "MDc6UmVsZWFzZTE4NzE2Mzk5.S/VUFSgnrVIv8A==",
|
||||
"release_link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/tag/jdk-12.0.2%2B10",
|
||||
"release_name": "jdk-12.0.2+9",
|
||||
"release_type": "ga",
|
||||
"timestamp": "2019-07-18T20:26:29Z",
|
||||
"updated_at": "2019-07-18T20:26:29Z",
|
||||
"vendor": "adoptopenjdk",
|
||||
"version_data": {
|
||||
"adopt_build_number": 1,
|
||||
"build": 10,
|
||||
"major": 12,
|
||||
"minor": 0,
|
||||
"openjdk_version": "12.0.2+9",
|
||||
"security": 2,
|
||||
"semver": "12.0.2+9.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"binaries": [
|
||||
{
|
||||
|
|
|
@ -96,7 +96,10 @@ describe('findPackageForDownload', () => {
|
|||
['15.0.1', '15.0.1+9.1'],
|
||||
['11.x', '11.0.10+9'],
|
||||
['x', '15.0.2+7'],
|
||||
['12', '12.0.2+10.3'] // make sure that '12.0.2+10.1', '12.0.2+10.3', '12.0.2+10.2' are sorted correctly
|
||||
['12', '12.0.2+10.3'], // make sure that '12.0.2+10.1', '12.0.2+10.3', '12.0.2+10.2' are sorted correctly
|
||||
['12.0.2+10.1', '12.0.2+10.1'],
|
||||
['15.0.1+9', '15.0.1+9'],
|
||||
['15.0.1+9.1', '15.0.1+9.1']
|
||||
])('version is resolved correctly %s -> %s', async (input, expected) => {
|
||||
const distribution = new AdoptiumDistribution({
|
||||
version: '11',
|
||||
|
@ -104,7 +107,7 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk'
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
const resolvedVersion = await distribution['findPackageForDownload'](new semver.Range(input));
|
||||
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
||||
expect(resolvedVersion.version).toBe(expected);
|
||||
});
|
||||
|
||||
|
@ -115,9 +118,9 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk'
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
await expect(
|
||||
distribution['findPackageForDownload'](new semver.Range('9.0.8'))
|
||||
).rejects.toThrowError(/Could not find satisfied version for SemVer */);
|
||||
await expect(distribution['findPackageForDownload']('9.0.8')).rejects.toThrowError(
|
||||
/Could not find satisfied version for SemVer */
|
||||
);
|
||||
});
|
||||
|
||||
it('version is not found', async () => {
|
||||
|
@ -127,9 +130,9 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk'
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
await expect(
|
||||
distribution['findPackageForDownload'](new semver.Range('7.x'))
|
||||
).rejects.toThrowError(/Could not find satisfied version for SemVer */);
|
||||
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrowError(
|
||||
/Could not find satisfied version for SemVer */
|
||||
);
|
||||
});
|
||||
|
||||
it('version list is empty', async () => {
|
||||
|
@ -139,8 +142,8 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk'
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => [];
|
||||
await expect(
|
||||
distribution['findPackageForDownload'](new semver.Range('11'))
|
||||
).rejects.toThrowError(/Could not find satisfied version for SemVer */);
|
||||
await expect(distribution['findPackageForDownload']('11')).rejects.toThrowError(
|
||||
/Could not find satisfied version for SemVer */
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as tc from '@actions/tool-cache';
|
||||
import * as core from '@actions/core';
|
||||
import * as util from '../../src/util';
|
||||
|
||||
import path from 'path';
|
||||
import * as semver from 'semver';
|
||||
|
@ -23,7 +24,7 @@ class EmptyJavaBase extends JavaBase {
|
|||
};
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(range: semver.Range): Promise<JavaDownloadRelease> {
|
||||
protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
|
||||
const availableVersion = '11.0.8';
|
||||
if (!semver.satisfies(availableVersion, range)) {
|
||||
throw new Error('Available version not found');
|
||||
|
@ -41,11 +42,11 @@ describe('findInToolcache', () => {
|
|||
const javaPath = path.join('Java_Empty_jdk', actualJavaVersion, 'x64');
|
||||
|
||||
let mockJavaBase: EmptyJavaBase;
|
||||
let spyTcFind: jest.SpyInstance;
|
||||
let spyGetToolcachePath: jest.SpyInstance;
|
||||
let spyTcFindAllVersions: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyTcFind = jest.spyOn(tc, 'find');
|
||||
spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath');
|
||||
spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions');
|
||||
});
|
||||
|
||||
|
@ -74,15 +75,17 @@ describe('findInToolcache', () => {
|
|||
[{ version: '11', arch: 'x86', packageType: 'jre' }, null]
|
||||
])(`should find java for path %s -> %s`, (input, expected) => {
|
||||
spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
|
||||
spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
spyGetToolcachePath.mockImplementation(
|
||||
(toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
|
||||
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
|
||||
return '';
|
||||
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
|
||||
}
|
||||
|
||||
return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
|
||||
});
|
||||
);
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
expect(mockJavaBase['findInToolcache']()).toEqual(expected);
|
||||
});
|
||||
|
@ -108,7 +111,7 @@ describe('findInToolcache', () => {
|
|||
'11.3.2-ea',
|
||||
'11.0.1'
|
||||
]);
|
||||
spyTcFind.mockImplementation(
|
||||
spyGetToolcachePath.mockImplementation(
|
||||
(toolname: string, javaVersion: string, architecture: string) =>
|
||||
`/hostedtoolcache/${toolname}/${javaVersion}/${architecture}`
|
||||
);
|
||||
|
@ -124,7 +127,7 @@ describe('setupJava', () => {
|
|||
|
||||
let mockJavaBase: EmptyJavaBase;
|
||||
|
||||
let spyTcFind: jest.SpyInstance;
|
||||
let spyGetToolcachePath: jest.SpyInstance;
|
||||
let spyTcFindAllVersions: jest.SpyInstance;
|
||||
let spyCoreDebug: jest.SpyInstance;
|
||||
let spyCoreInfo: jest.SpyInstance;
|
||||
|
@ -133,16 +136,18 @@ describe('setupJava', () => {
|
|||
let spyCoreSetOutput: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyTcFind = jest.spyOn(tc, 'find');
|
||||
spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath');
|
||||
spyGetToolcachePath.mockImplementation(
|
||||
(toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
|
||||
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
|
||||
return '';
|
||||
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
|
||||
}
|
||||
|
||||
return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
|
||||
});
|
||||
);
|
||||
|
||||
spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions');
|
||||
spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
|
||||
|
@ -186,7 +191,7 @@ describe('setupJava', () => {
|
|||
])('should find java locally for %s', (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||
expect(spyTcFind).toHaveBeenCalled();
|
||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
@ -205,7 +210,7 @@ describe('setupJava', () => {
|
|||
])('download java with configuration %s', async (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||
expect(spyTcFind).toHaveBeenCalled();
|
||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
expect(spyCoreAddPath).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalled();
|
||||
expect(spyCoreSetOutput).toHaveBeenCalled();
|
||||
|
@ -228,11 +233,11 @@ describe('normalizeVersion', () => {
|
|||
const DummyJavaBase = JavaBase as any;
|
||||
|
||||
it.each([
|
||||
['11', { version: new semver.Range('11'), stable: true }],
|
||||
['11.0', { version: new semver.Range('11.0'), stable: true }],
|
||||
['11.0.10', { version: new semver.Range('11.0.10'), stable: true }],
|
||||
['11-ea', { version: new semver.Range('11'), stable: false }],
|
||||
['11.0.2-ea', { version: new semver.Range('11.0.2'), stable: false }]
|
||||
['11', { version: '11', stable: true }],
|
||||
['11.0', { version: '11.0', stable: true }],
|
||||
['11.0.10', { version: '11.0.10', stable: true }],
|
||||
['11-ea', { version: '11', stable: false }],
|
||||
['11.0.2-ea', { version: '11.0.2', stable: false }]
|
||||
])('normalizeVersion from %s to %s', (input, expected) => {
|
||||
expect(DummyJavaBase.prototype.normalizeVersion.call(null, input)).toEqual(expected);
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@ import * as core from '@actions/core';
|
|||
|
||||
import path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import * as utils from '../../src/util';
|
||||
import * as util from '../../src/util';
|
||||
|
||||
import { LocalDistribution } from '../../src/distributions/local/installer';
|
||||
|
||||
|
@ -15,7 +15,7 @@ describe('setupJava', () => {
|
|||
|
||||
let mockJavaBase: LocalDistribution;
|
||||
|
||||
let spyTcFind: jest.SpyInstance;
|
||||
let spyGetToolcachePath: jest.SpyInstance;
|
||||
let spyTcCacheDir: jest.SpyInstance;
|
||||
let spyTcFindAllVersions: jest.SpyInstance;
|
||||
let spyCoreDebug: jest.SpyInstance;
|
||||
|
@ -30,16 +30,18 @@ describe('setupJava', () => {
|
|||
let expectedJdkFile = 'JavaLocalJdkFile';
|
||||
|
||||
beforeEach(() => {
|
||||
spyTcFind = jest.spyOn(tc, 'find');
|
||||
spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath');
|
||||
spyGetToolcachePath.mockImplementation(
|
||||
(toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
|
||||
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
|
||||
return '';
|
||||
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
|
||||
}
|
||||
|
||||
return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
|
||||
});
|
||||
);
|
||||
|
||||
spyTcCacheDir = jest.spyOn(tc, 'cacheDir');
|
||||
spyTcCacheDir.mockImplementation(
|
||||
|
@ -76,7 +78,7 @@ describe('setupJava', () => {
|
|||
});
|
||||
|
||||
// Spy on util methods
|
||||
spyUtilsExtractJdkFile = jest.spyOn(utils, 'extractJdkFile');
|
||||
spyUtilsExtractJdkFile = jest.spyOn(util, 'extractJdkFile');
|
||||
spyUtilsExtractJdkFile.mockImplementation(() => 'some/random/path/');
|
||||
|
||||
// Spy on path methods
|
||||
|
@ -100,7 +102,7 @@ describe('setupJava', () => {
|
|||
|
||||
mockJavaBase = new LocalDistribution(inputs, jdkFile);
|
||||
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||
expect(spyTcFind).toHaveBeenCalled();
|
||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${actualJavaVersion} from tool-cache`);
|
||||
expect(spyCoreInfo).not.toHaveBeenCalledWith(
|
||||
`Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
|
||||
|
@ -117,7 +119,7 @@ describe('setupJava', () => {
|
|||
|
||||
mockJavaBase = new LocalDistribution(inputs, jdkFile);
|
||||
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||
expect(spyTcFind).toHaveBeenCalled();
|
||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${actualJavaVersion} from tool-cache`);
|
||||
expect(spyCoreInfo).not.toHaveBeenCalledWith(
|
||||
`Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
|
||||
|
|
|
@ -96,7 +96,10 @@ describe('findPackageForDownload', () => {
|
|||
['15', '15.0.2+7'],
|
||||
['9.0.0', '9.0.0+0'],
|
||||
['9.0', '9.0.1+0'],
|
||||
['8.0.262', '8.0.262+19'] // validate correct choise between [8.0.262.17, 8.0.262.19, 8.0.262.18]
|
||||
['8.0.262', '8.0.262+19'], // validate correct choise between [8.0.262.17, 8.0.262.19, 8.0.262.18]
|
||||
['8.0.262+17', '8.0.262+17'],
|
||||
['15.0.1+8', '15.0.1+8'],
|
||||
['15.0.1+9', '15.0.1+9']
|
||||
])('version is %s -> %s', async (input, expected) => {
|
||||
const distribution = new ZuluDistribution({
|
||||
version: input,
|
||||
|
@ -111,7 +114,7 @@ describe('findPackageForDownload', () => {
|
|||
it('select correct bundle if there are multiple items with the same jdk version but different zulu versions', async () => {
|
||||
const distribution = new ZuluDistribution({ version: '', arch: 'x86', packageType: 'jdk' });
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
const result = await distribution['findPackageForDownload'](new semver.Range('11.0.5'));
|
||||
const result = await distribution['findPackageForDownload']('11.0.5');
|
||||
expect(result.url).toBe(
|
||||
'https://cdn.azul.com/zulu/bin/zulu11.35.15-ca-jdk11.0.5-macosx_x64.tar.gz'
|
||||
);
|
||||
|
|
22
__tests__/util.test.ts
Normal file
22
__tests__/util.test.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { isVersionSatisfies } from '../src/util';
|
||||
|
||||
describe('isVersionSatisfies', () => {
|
||||
it.each([
|
||||
['x', '11.0.0', true],
|
||||
['3', '3.7.1', true],
|
||||
['3', '3.7.2', true],
|
||||
['3', '3.7.2+4', true],
|
||||
['2.5', '2.5.0', true],
|
||||
['2.5', '2.5.0+1', true],
|
||||
['2.5', '2.6.1', false],
|
||||
['2.5.1', '2.5.0', false],
|
||||
['2.5.1+3', '2.5.0', false],
|
||||
['2.5.1+3', '2.5.1+3', true],
|
||||
['2.5.1+3', '2.5.1+2', false],
|
||||
['15.0.0+14', '15.0.0+14.1.202003190635', false],
|
||||
['15.0.0+14.1.202003190635', '15.0.0+14.1.202003190635', true]
|
||||
])('%s, %s -> %s', (inputRange: string, inputVersion: string, expected: boolean) => {
|
||||
const actual = isVersionSatisfies(inputRange, inputVersion);
|
||||
expect(actual).toBe(expected);
|
||||
});
|
||||
});
|
|
@ -10,12 +10,16 @@ if [ -z "$2" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
EXPECTED_JAVA_VERSION=${1/-ea/}
|
||||
EXPECTED_JAVA_VERSION=$1
|
||||
EXPECTED_PATH=$2
|
||||
|
||||
EXPECTED_JAVA_VERSION=$(echo $EXPECTED_JAVA_VERSION | cut -d'+' -f1)
|
||||
if [[ $EXPECTED_JAVA_VERSION == 8 ]] || [[ $EXPECTED_JAVA_VERSION == 8.* ]]; then
|
||||
EXPECTED_JAVA_VERSION="1.${EXPECTED_JAVA_VERSION}"
|
||||
fi
|
||||
if [[ $EXPECTED_JAVA_VERSION == *-ea* ]]; then
|
||||
EXPECTED_JAVA_VERSION=$(echo $EXPECTED_JAVA_VERSION | cut -d'-' -f1 | cut -d'.' -f1)
|
||||
fi
|
||||
|
||||
ACTUAL_JAVA_VERSION="$(java -version 2>&1)"
|
||||
echo "Found java version: $ACTUAL_JAVA_VERSION"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue