mirror of
https://github.com/actions/setup-java.git
synced 2025-06-30 21:04:16 +00:00
Merge branch 'main' into ibm-semeru
# Conflicts: # .github/workflows/e2e-versions.yml # README.md # dist/cleanup/index.js # dist/setup/index.js # src/distributions/distribution-factory.ts
This commit is contained in:
commit
f854a50c5a
54 changed files with 137052 additions and 123702 deletions
|
@ -98,7 +98,7 @@ describe('dependency cache', () => {
|
|||
await expect(restore('gradle')).rejects.toThrowError(
|
||||
`No file in ${projectRoot(
|
||||
workspace
|
||||
)} matched to [**/*.gradle*,**/gradle-wrapper.properties], make sure you have checked out the target repository`
|
||||
)} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt], make sure you have checked out the target repository`
|
||||
);
|
||||
});
|
||||
it('downloads cache based on build.gradle', async () => {
|
||||
|
@ -118,6 +118,32 @@ describe('dependency cache', () => {
|
|||
expect(spyInfo).toBeCalledWith('gradle cache is not found');
|
||||
});
|
||||
});
|
||||
it('downloads cache based on buildSrc/Versions.kt', async () => {
|
||||
createDirectory(join(workspace, 'buildSrc'));
|
||||
createFile(join(workspace, 'buildSrc', 'Versions.kt'));
|
||||
|
||||
await restore('gradle');
|
||||
expect(spyCacheRestore).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith('gradle cache is not found');
|
||||
});
|
||||
describe('for sbt', () => {
|
||||
it('throws error if no build.sbt found', async () => {
|
||||
await expect(restore('sbt')).rejects.toThrowError(
|
||||
`No file in ${projectRoot(
|
||||
workspace
|
||||
)} matched to [**/*.sbt,**/project/build.properties,**/project/**.{scala,sbt}], make sure you have checked out the target repository`
|
||||
);
|
||||
});
|
||||
it('downloads cache', async () => {
|
||||
createFile(join(workspace, 'build.sbt'));
|
||||
|
||||
await restore('sbt');
|
||||
expect(spyCacheRestore).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith('sbt cache is not found');
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('save', () => {
|
||||
let spyCacheSave: jest.SpyInstance<
|
||||
|
@ -136,6 +162,27 @@ describe('dependency cache', () => {
|
|||
return expect(save('ant')).rejects.toThrowError('unknown package manager specified: ant');
|
||||
});
|
||||
|
||||
it('save with -1 cacheId , should not fail workflow', async () => {
|
||||
spyCacheSave.mockImplementation(() => Promise.resolve(-1));
|
||||
createStateForMissingBuildFile();
|
||||
|
||||
await save('maven');
|
||||
expect(spyCacheSave).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
|
||||
});
|
||||
|
||||
it('saves with error from toolkit, should fail workflow', async () => {
|
||||
spyCacheSave.mockImplementation(() =>
|
||||
Promise.reject(new cache.ValidationError('Validation failed'))
|
||||
);
|
||||
createStateForMissingBuildFile();
|
||||
|
||||
expect.assertions(1);
|
||||
await expect(save('maven')).rejects.toEqual(new cache.ValidationError('Validation failed'));
|
||||
});
|
||||
|
||||
describe('for maven', () => {
|
||||
it('uploads cache even if no pom.xml found', async () => {
|
||||
createStateForMissingBuildFile();
|
||||
|
@ -193,6 +240,40 @@ describe('dependency cache', () => {
|
|||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
|
||||
});
|
||||
it('uploads cache based on buildSrc/Versions.kt', async () => {
|
||||
createDirectory(join(workspace, 'buildSrc'));
|
||||
createFile(join(workspace, 'buildSrc', 'Versions.kt'));
|
||||
createStateForSuccessfulRestore();
|
||||
|
||||
await save('gradle');
|
||||
expect(spyCacheSave).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
|
||||
});
|
||||
});
|
||||
describe('for sbt', () => {
|
||||
it('uploads cache even if no build.sbt found', async () => {
|
||||
createStateForMissingBuildFile();
|
||||
await save('sbt');
|
||||
expect(spyCacheSave).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
});
|
||||
it('does not upload cache if no restore run before', async () => {
|
||||
createFile(join(workspace, 'build.sbt'));
|
||||
|
||||
await save('sbt');
|
||||
expect(spyCacheSave).not.toBeCalled();
|
||||
expect(spyWarning).toBeCalledWith('Error retrieving key from state.');
|
||||
});
|
||||
it('uploads cache', async () => {
|
||||
createFile(join(workspace, 'build.sbt'));
|
||||
createStateForSuccessfulRestore();
|
||||
|
||||
await save('sbt');
|
||||
expect(spyCacheSave).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -236,6 +317,11 @@ function createFile(path: string) {
|
|||
fs.writeFileSync(path, '');
|
||||
}
|
||||
|
||||
function createDirectory(path: string) {
|
||||
core.info(`created a directory at ${path}`);
|
||||
fs.mkdirSync(path);
|
||||
}
|
||||
|
||||
function projectRoot(workspace: string): string {
|
||||
if (os.platform() === 'darwin') {
|
||||
return `/private${workspace}`;
|
||||
|
|
1
__tests__/cache/sbt/.gitignore
vendored
Normal file
1
__tests__/cache/sbt/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
target/
|
3
__tests__/cache/sbt/build.sbt
vendored
Normal file
3
__tests__/cache/sbt/build.sbt
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
ThisBuild / scalaVersion := "2.12.15"
|
||||
|
||||
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2"
|
1
__tests__/cache/sbt/project/build.properties
vendored
Normal file
1
__tests__/cache/sbt/project/build.properties
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
sbt.version=1.6.2
|
|
@ -26,7 +26,7 @@ describe('cleanup', () => {
|
|||
resetState();
|
||||
});
|
||||
|
||||
it('does not fail nor warn even when the save provess throws a ReserveCacheError', async () => {
|
||||
it('does not fail nor warn even when the save process throws a ReserveCacheError', async () => {
|
||||
spyCacheSave.mockImplementation((paths: string[], key: string) =>
|
||||
Promise.reject(
|
||||
new cache.ReserveCacheError(
|
||||
|
|
1183
__tests__/data/corretto.json
Normal file
1183
__tests__/data/corretto.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -244,6 +244,10 @@ describe('setupJava', () => {
|
|||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
expect(spyCoreAddPath).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||
`JAVA_HOME_${input.version}_${input.architecture.toLocaleUpperCase()}`,
|
||||
expected.path
|
||||
);
|
||||
expect(spyCoreSetOutput).toHaveBeenCalled();
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote');
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${expected.version}`);
|
||||
|
|
152
__tests__/distributors/corretto-installer.test.ts
Normal file
152
__tests__/distributors/corretto-installer.test.ts
Normal file
|
@ -0,0 +1,152 @@
|
|||
import { HttpClient } from '@actions/http-client';
|
||||
import { JavaInstallerOptions } from '../../src/distributions/base-models';
|
||||
|
||||
import { CorrettoDistribution } from '../../src/distributions/corretto/installer';
|
||||
import * as util from '../../src/util';
|
||||
|
||||
const manifestData = require('../data/corretto.json') as [];
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyGetDownloadArchiveExtension: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
spyHttpClient.mockReturnValue({
|
||||
statusCode: 200,
|
||||
headers: {},
|
||||
result: manifestData
|
||||
});
|
||||
spyGetDownloadArchiveExtension = jest.spyOn(util, 'getDownloadArchiveExtension');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
it('load available versions', async () => {
|
||||
const distribution = new CorrettoDistribution({
|
||||
version: '11',
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
mockPlatform(distribution, 'linux');
|
||||
|
||||
const availableVersions = await distribution['getAvailableVersions']();
|
||||
expect(availableVersions).not.toBeNull();
|
||||
expect(availableVersions.length).toBe(6);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[{ version: '16', architecture: 'x64', packageType: 'jdk', checkLatest: false }, 'macos', 6],
|
||||
[{ version: '16', architecture: 'x86', packageType: 'jdk', checkLatest: false }, 'macos', 0],
|
||||
[{ version: '16', architecture: 'x64', packageType: 'jre', checkLatest: false }, 'macos', 0],
|
||||
[{ version: '16', architecture: 'x64', packageType: 'jdk', checkLatest: false }, 'linux', 6],
|
||||
[
|
||||
{ version: '18', architecture: 'x64', packageType: 'jdk', checkLatest: false },
|
||||
'windows',
|
||||
6
|
||||
],
|
||||
[{ version: '18', architecture: 'x64', packageType: 'jre', checkLatest: false }, 'windows', 1]
|
||||
])(
|
||||
'fetch expected amount of available versions for %s',
|
||||
async (
|
||||
installerOptions: JavaInstallerOptions,
|
||||
platform: string,
|
||||
expectedAmountOfAvailableVersions
|
||||
) => {
|
||||
const distribution = new CorrettoDistribution(installerOptions);
|
||||
mockPlatform(distribution, platform);
|
||||
|
||||
const availableVersions = await distribution['getAvailableVersions']();
|
||||
expect(availableVersions).not.toBeNull();
|
||||
expect(availableVersions.length).toBe(expectedAmountOfAvailableVersions);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('findPackageForDownload', () => {
|
||||
it.each([
|
||||
[
|
||||
'macos',
|
||||
'https://corretto.aws/downloads/resources/18.0.0.37.1/amazon-corretto-18.0.0.37.1-macosx-x64.tar.gz'
|
||||
],
|
||||
[
|
||||
'windows',
|
||||
'https://corretto.aws/downloads/resources/18.0.0.37.1/amazon-corretto-18.0.0.37.1-windows-x64-jdk.zip'
|
||||
],
|
||||
[
|
||||
'linux',
|
||||
'https://corretto.aws/downloads/resources/18.0.0.37.1/amazon-corretto-18.0.0.37.1-linux-x64.tar.gz'
|
||||
]
|
||||
])('for os: %s', async (platform: string, expectedLink: string) => {
|
||||
const version = '18';
|
||||
const distribution = new CorrettoDistribution({
|
||||
version,
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
mockPlatform(distribution, platform);
|
||||
|
||||
const availableVersion = await distribution['findPackageForDownload'](version);
|
||||
expect(availableVersion).not.toBeNull();
|
||||
expect(availableVersion.url).toBe(expectedLink);
|
||||
});
|
||||
|
||||
it('with unstable version expect to throw not supported error', async () => {
|
||||
const version = '18.0.1-ea';
|
||||
const distribution = new CorrettoDistribution({
|
||||
version,
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
mockPlatform(distribution, 'linux');
|
||||
|
||||
await expect(distribution['findPackageForDownload'](version)).rejects.toThrowError(
|
||||
'Early access versions are not supported'
|
||||
);
|
||||
});
|
||||
|
||||
it('with non major version expect to throw not supported error', async () => {
|
||||
const version = '18.0.1';
|
||||
const distribution = new CorrettoDistribution({
|
||||
version,
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
mockPlatform(distribution, 'linux');
|
||||
|
||||
await expect(distribution['findPackageForDownload'](version)).rejects.toThrowError(
|
||||
'Only major versions are supported'
|
||||
);
|
||||
});
|
||||
|
||||
it('with unfound version throw could not find error', async () => {
|
||||
const version = '4';
|
||||
const distribution = new CorrettoDistribution({
|
||||
version,
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
mockPlatform(distribution, 'linux');
|
||||
|
||||
await expect(distribution['findPackageForDownload'](version)).rejects.toThrowError(
|
||||
"Could not find satisfied version for SemVer '4'"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
const mockPlatform = (distribution: CorrettoDistribution, platform: string) => {
|
||||
distribution['getPlatformOption'] = () => platform;
|
||||
const mockedExtension = platform === 'windows' ? 'zip' : 'tar.gz';
|
||||
spyGetDownloadArchiveExtension.mockReturnValue(mockedExtension);
|
||||
};
|
||||
});
|
|
@ -14,10 +14,15 @@ describe('findPackageForDownload', () => {
|
|||
|
||||
it.each([
|
||||
[
|
||||
'17.x',
|
||||
'17.0.1',
|
||||
'17.0.1',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
'17.x',
|
||||
'17.0.3',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-17.0.3-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
'16.0.x',
|
||||
'16.0.2',
|
||||
|
@ -27,6 +32,11 @@ describe('findPackageForDownload', () => {
|
|||
'11.0.13',
|
||||
'11.0.13',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
'11.0.15',
|
||||
'11.0.15',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-11.0.15-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
]
|
||||
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
|
||||
const result = await distribution['findPackageForDownload'](input);
|
||||
|
|
|
@ -52,6 +52,14 @@ describe('getAvailableVersions', () => {
|
|||
[
|
||||
{ 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'
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: 'arm64', packageType: 'jdk', checkLatest: false },
|
||||
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=arm&hw_bitness=64&release_status=ga'
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: 'arm', packageType: 'jdk', checkLatest: false },
|
||||
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=arm&hw_bitness=&release_status=ga'
|
||||
]
|
||||
])('build correct url for %s -> %s', async (input, parsedUrl) => {
|
||||
const distribution = new ZuluDistribution(input);
|
||||
|
@ -102,7 +110,7 @@ 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 choice 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']
|
||||
|
@ -139,6 +147,7 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
await expect(
|
||||
distribution['findPackageForDownload'](distribution['version'])
|
||||
).rejects.toThrowError(/Could not find satisfied version for semver */);
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import { isVersionSatisfies } from '../src/util';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
import { isVersionSatisfies, isCacheFeatureAvailable } from '../src/util';
|
||||
|
||||
jest.mock('@actions/cache');
|
||||
jest.mock('@actions/core');
|
||||
|
||||
describe('isVersionSatisfies', () => {
|
||||
it.each([
|
||||
|
@ -20,3 +25,38 @@ describe('isVersionSatisfies', () => {
|
|||
expect(actual).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isCacheFeatureAvailable', () => {
|
||||
it('isCacheFeatureAvailable disabled on GHES', () => {
|
||||
jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => false);
|
||||
try {
|
||||
process.env['GITHUB_SERVER_URL'] = 'http://example.com';
|
||||
isCacheFeatureAvailable();
|
||||
} catch (error) {
|
||||
expect(error).toHaveProperty(
|
||||
'message',
|
||||
'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.'
|
||||
);
|
||||
} finally {
|
||||
delete process.env['GITHUB_SERVER_URL'];
|
||||
}
|
||||
});
|
||||
|
||||
it('isCacheFeatureAvailable disabled on dotcom', () => {
|
||||
jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => false);
|
||||
const infoMock = jest.spyOn(core, 'warning');
|
||||
const message = 'The runner was not able to contact the cache service. Caching will be skipped';
|
||||
try {
|
||||
process.env['GITHUB_SERVER_URL'] = 'http://github.com';
|
||||
expect(isCacheFeatureAvailable()).toBe(false);
|
||||
expect(infoMock).toHaveBeenCalledWith(message);
|
||||
} finally {
|
||||
delete process.env['GITHUB_SERVER_URL'];
|
||||
}
|
||||
});
|
||||
|
||||
it('isCacheFeatureAvailable is enabled', () => {
|
||||
jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => true);
|
||||
expect(isCacheFeatureAvailable()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue