mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 09:56:46 +00:00
Add check-latest flag (#141)
* add changes for check-latest * run prerelease script * resolving comments * fixing tests * fix spelling * improve core.info messages * run format * run prerelease * change version to fix test * resolve comment for check-latest * Update README.md * added hosted tool cache section * Apply suggestions from code review Co-authored-by: Maxim Lobanov <v-malob@microsoft.com> Co-authored-by: Konrad Pabjan <konradpabjan@github.com>
This commit is contained in:
parent
502a6650cd
commit
022e86d5c9
14 changed files with 279 additions and 77 deletions
|
@ -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';
|
||||
|
|
|
@ -14,6 +14,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, {
|
||||
|
@ -26,6 +27,7 @@ export abstract class JavaBase {
|
|||
));
|
||||
this.architecture = installerOptions.architecture;
|
||||
this.packageType = installerOptions.packageType;
|
||||
this.checkLatest = installerOptions.checkLatest;
|
||||
}
|
||||
|
||||
protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults>;
|
||||
|
@ -33,13 +35,21 @@ 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...`);
|
||||
core.info('Trying to resolve the latest version from remote');
|
||||
const javaRelease = await this.findPackageForDownload(this.version);
|
||||
foundJava = await this.downloadTool(javaRelease);
|
||||
core.info(`Java ${foundJava.version} was downloaded`);
|
||||
core.info(`Resolved latest version as ${javaRelease.version}`);
|
||||
core.info(foundJava?.version ?? '');
|
||||
core.info(javaRelease.version ?? '');
|
||||
if (foundJava?.version === javaRelease.version) {
|
||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||
} else {
|
||||
core.info('Trying to download...');
|
||||
foundJava = await this.downloadTool(javaRelease);
|
||||
core.info(`Java ${foundJava.version} was downloaded`);
|
||||
}
|
||||
}
|
||||
|
||||
// JDK folder may contain postfix "Contents/Home" on macOS
|
||||
|
|
|
@ -2,6 +2,7 @@ export interface JavaInstallerOptions {
|
|||
version: string;
|
||||
architecture: string;
|
||||
packageType: string;
|
||||
checkLatest: boolean;
|
||||
}
|
||||
|
||||
export interface JavaInstallerResults {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as auth from './auth';
|
||||
|
||||
import { getBooleanInput } from './util';
|
||||
import * as constants from './constants';
|
||||
import * as path from 'path';
|
||||
import { getJavaDistribution } from './distributions/distribution-factory';
|
||||
|
@ -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 = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
version
|
||||
version,
|
||||
checkLatest
|
||||
};
|
||||
|
||||
const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue