mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 01:46:46 +00:00
add changes for check-latest
This commit is contained in:
parent
804a60faf9
commit
8f3a7c87ff
9 changed files with 3363 additions and 9258 deletions
37
.github/workflows/e2e-versions.yml
vendored
37
.github/workflows/e2e-versions.yml
vendored
|
@ -70,6 +70,43 @@ jobs:
|
|||
run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
|
||||
shell: bash
|
||||
|
||||
setup-java-major-minor-versions-with-check-latest:
|
||||
name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
|
||||
needs: setup-java-major-versions
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||
distribution: ['adopt', 'zulu']
|
||||
version:
|
||||
- '11.0'
|
||||
- '8.0.282'
|
||||
- '11.0.2+7'
|
||||
include:
|
||||
- distribution: 'adopt'
|
||||
version: '12.0.2+10.1'
|
||||
os: macos-latest
|
||||
- distribution: 'adopt'
|
||||
version: '12.0.2+10.1'
|
||||
os: windows-latest
|
||||
- distribution: 'adopt'
|
||||
version: '12.0.2+10.1'
|
||||
os: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: setup-java
|
||||
uses: ./
|
||||
id: setup-java
|
||||
with:
|
||||
java-version: ${{ matrix.version }}
|
||||
distribution: ${{ matrix.distribution }}
|
||||
check-latest: true
|
||||
- name: Verify Java
|
||||
run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
|
||||
shell: bash
|
||||
|
||||
setup-java-ea-versions-zulu:
|
||||
name: zulu ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
|
||||
needs: setup-java-major-minor-versions
|
||||
|
|
|
@ -19,13 +19,13 @@ class EmptyJavaBase extends JavaBase {
|
|||
|
||||
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||
return {
|
||||
version: '11.0.8',
|
||||
path: `/toolcache/${this.toolcacheFolderName}/11.0.8/${this.architecture}`
|
||||
version: '11.0.9',
|
||||
path: `toolcache/${this.toolcacheFolderName}/11.0.9/${this.architecture}`
|
||||
};
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
|
||||
const availableVersion = '11.0.8';
|
||||
const availableVersion = '11.0.9';
|
||||
if (!semver.satisfies(availableVersion, range)) {
|
||||
throw new Error('Available version not found');
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class EmptyJavaBase extends JavaBase {
|
|||
}
|
||||
|
||||
describe('findInToolcache', () => {
|
||||
const actualJavaVersion = '11.1.10';
|
||||
const actualJavaVersion = '11.0.8';
|
||||
const javaPath = path.join('Java_Empty_jdk', actualJavaVersion, 'x64');
|
||||
|
||||
let mockJavaBase: EmptyJavaBase;
|
||||
|
@ -62,18 +62,30 @@ describe('findInToolcache', () => {
|
|||
{ version: actualJavaVersion, path: javaPath }
|
||||
],
|
||||
[
|
||||
{ version: '11.1', architecture: 'x64', packageType: 'jdk' },
|
||||
{ version: '11.0', architecture: 'x64', packageType: 'jdk' },
|
||||
{ version: actualJavaVersion, path: javaPath }
|
||||
],
|
||||
[
|
||||
{ version: '11.1.10', architecture: 'x64', packageType: 'jdk' },
|
||||
{ version: '11.0.8', architecture: 'x64', packageType: 'jdk' },
|
||||
{ version: actualJavaVersion, path: javaPath }
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: true },
|
||||
{ version: actualJavaVersion, path: javaPath }
|
||||
],
|
||||
[
|
||||
{ version: '11.0', architecture: 'x64', packageType: 'jdk', checkLatest: true },
|
||||
{ version: actualJavaVersion, path: javaPath }
|
||||
],
|
||||
[
|
||||
{ version: '11.0.8', architecture: 'x64', packageType: 'jdk', checkLatest: true },
|
||||
{ version: actualJavaVersion, path: javaPath }
|
||||
],
|
||||
[{ version: '11', architecture: 'x64', packageType: 'jre' }, null],
|
||||
[{ version: '8', architecture: 'x64', packageType: 'jdk' }, null],
|
||||
[{ version: '11', architecture: 'x86', packageType: 'jdk' }, null],
|
||||
[{ version: '11', architecture: 'x86', packageType: 'jre' }, null]
|
||||
])(`should find java for path %s -> %s`, (input, expected) => {
|
||||
])(`should find java for path %o -> %o`, (input, expected) => {
|
||||
spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
|
||||
spyGetToolcachePath.mockImplementation(
|
||||
(toolname: string, javaVersion: string, architecture: string) => {
|
||||
|
@ -122,8 +134,10 @@ describe('findInToolcache', () => {
|
|||
});
|
||||
|
||||
describe('setupJava', () => {
|
||||
const actualJavaVersion = '11.1.10';
|
||||
const actualJavaVersion = '11.0.8';
|
||||
const installedJavaVersion = '11.0.9';
|
||||
const javaPath = path.join('Java_Empty_jdk', actualJavaVersion, 'x86');
|
||||
const javaPathInstalled = path.join('toolcache', 'Java_Empty_jdk', installedJavaVersion, 'x86');
|
||||
|
||||
let mockJavaBase: EmptyJavaBase;
|
||||
|
||||
|
@ -181,31 +195,54 @@ describe('setupJava', () => {
|
|||
{ version: actualJavaVersion, path: javaPath }
|
||||
],
|
||||
[
|
||||
{ version: '11.1', architecture: 'x86', packageType: 'jdk' },
|
||||
{ version: '11.0', architecture: 'x86', packageType: 'jdk' },
|
||||
{ version: actualJavaVersion, path: javaPath }
|
||||
],
|
||||
[
|
||||
{ version: '11.1.10', architecture: 'x86', packageType: 'jdk' },
|
||||
{ version: '11.0.8', architecture: 'x86', packageType: 'jdk' },
|
||||
{ version: actualJavaVersion, path: javaPath }
|
||||
]
|
||||
])('should find java locally for %s', (input, expected) => {
|
||||
])('should find java locally for %o', (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||
{ version: installedJavaVersion, path: javaPathInstalled }
|
||||
],
|
||||
[
|
||||
{ version: '11.0', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||
{ version: installedJavaVersion, path: javaPathInstalled }
|
||||
],
|
||||
[
|
||||
{ version: '11.0.x', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||
{ version: installedJavaVersion, path: javaPathInstalled }
|
||||
]
|
||||
])('should check the latest java version for %o', async (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith(
|
||||
`Java ${input.version} was not found in tool-cache. Trying to download...`
|
||||
);
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith(`Java ${installedJavaVersion} was downloaded`);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
{ version: '11', architecture: 'x86', packageType: 'jre' },
|
||||
{ path: `/toolcache/Java_Empty_jre/11.0.8/x86`, version: '11.0.8' }
|
||||
{ path: `toolcache/Java_Empty_jre/11.0.9/x86`, version: '11.0.9' }
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: 'x64', packageType: 'jdk' },
|
||||
{ path: `/toolcache/Java_Empty_jdk/11.0.8/x64`, version: '11.0.8' }
|
||||
{ path: `toolcache/Java_Empty_jdk/11.0.9/x64`, version: '11.0.9' }
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: 'x64', packageType: 'jre' },
|
||||
{ path: `/toolcache/Java_Empty_jre/11.0.8/x64`, version: '11.0.8' }
|
||||
{ path: `toolcache/Java_Empty_jre/11.0.9/x64`, version: '11.0.9' }
|
||||
]
|
||||
])('download java with configuration %s', async (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
|
|
|
@ -20,6 +20,10 @@ inputs:
|
|||
jdkFile:
|
||||
description: 'Path to where the compressed JDK is located'
|
||||
required: false
|
||||
check-latest:
|
||||
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
|
||||
required: false
|
||||
default: false
|
||||
server-id:
|
||||
description: 'ID of the distributionManagement repository in the pom.xml
|
||||
file. Default is `github`'
|
||||
|
|
6199
dist/cleanup/index.js
vendored
6199
dist/cleanup/index.js
vendored
File diff suppressed because it is too large
Load diff
6298
dist/setup/index.js
vendored
6298
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -4,6 +4,7 @@ export const INPUT_ARCHITECTURE = 'architecture';
|
|||
export const INPUT_JAVA_PACKAGE = 'java-package';
|
||||
export const INPUT_DISTRIBUTION = 'distribution';
|
||||
export const INPUT_JDK_FILE = 'jdkFile';
|
||||
export const INPUT_CHECK_LATEST = 'check-latest';
|
||||
export const INPUT_SERVER_ID = 'server-id';
|
||||
export const INPUT_SERVER_USERNAME = 'server-username';
|
||||
export const INPUT_SERVER_PASSWORD = 'server-password';
|
||||
|
|
|
@ -12,6 +12,7 @@ export abstract class JavaBase {
|
|||
protected architecture: string;
|
||||
protected packageType: string;
|
||||
protected stable: boolean;
|
||||
protected checkLatest: boolean;
|
||||
|
||||
constructor(protected distribution: string, installerOptions: JavaInstallerOptions) {
|
||||
this.http = new httpm.HttpClient('actions/setup-java', undefined, {
|
||||
|
@ -24,6 +25,7 @@ export abstract class JavaBase {
|
|||
));
|
||||
this.architecture = installerOptions.architecture;
|
||||
this.packageType = installerOptions.packageType;
|
||||
this.checkLatest = !!installerOptions.checkLatest;
|
||||
}
|
||||
|
||||
protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults>;
|
||||
|
@ -31,13 +33,17 @@ export abstract class JavaBase {
|
|||
|
||||
public async setupJava(): Promise<JavaInstallerResults> {
|
||||
let foundJava = this.findInToolcache();
|
||||
if (foundJava) {
|
||||
if (foundJava && !this.checkLatest) {
|
||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||
} else {
|
||||
core.info(`Java ${this.version} was not found in tool-cache. Trying to download...`);
|
||||
const javaRelease = await this.findPackageForDownload(this.version);
|
||||
foundJava = await this.downloadTool(javaRelease);
|
||||
core.info(`Java ${foundJava.version} was downloaded`);
|
||||
if (foundJava?.version != javaRelease.version) {
|
||||
foundJava = await this.downloadTool(javaRelease);
|
||||
core.info(`Java ${foundJava.version} was downloaded`);
|
||||
}
|
||||
|
||||
core.info(`Java ${foundJava.version} was resolved`);
|
||||
}
|
||||
|
||||
core.info(`Setting Java ${foundJava.version} as the default`);
|
||||
|
|
|
@ -2,6 +2,7 @@ export interface JavaInstallerOptions {
|
|||
version: string;
|
||||
architecture: string;
|
||||
packageType: string;
|
||||
checkLatest?: boolean;
|
||||
}
|
||||
|
||||
export interface JavaInstallerResults {
|
||||
|
|
|
@ -13,11 +13,13 @@ async function run() {
|
|||
const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
|
||||
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
|
||||
const jdkFile = core.getInput(constants.INPUT_JDK_FILE);
|
||||
const checkLatest = core.getInput(constants.INPUT_CHECK_LATEST);
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
version
|
||||
version,
|
||||
checkLatest: checkLatest ? false : checkLatest.toLowerCase() === 'true'
|
||||
};
|
||||
|
||||
const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue