mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 09:56:46 +00:00
fix review points
This commit is contained in:
parent
c13e4b13ba
commit
291b946ea5
2 changed files with 33 additions and 32 deletions
|
@ -1,14 +1,13 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as auth from './auth';
|
import * as auth from './auth';
|
||||||
import { getBooleanInput, isCacheFeatureAvailable } from './util';
|
import { getBooleanInput, isCacheFeatureAvailable, getVersionFromFileContent, avoidOldNotation } from './util';
|
||||||
import * as toolchains from './toolchains';
|
import * as toolchains from './toolchains';
|
||||||
import * as constants from './constants';
|
import * as constants from './constants';
|
||||||
import { restore } from './cache';
|
import { restore } from './cache';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { getJavaDistribution } from './distributions/distribution-factory';
|
import { getJavaDistribution } from './distributions/distribution-factory';
|
||||||
import { JavaInstallerOptions } from './distributions/base-models';
|
import { JavaInstallerOptions } from './distributions/base-models';
|
||||||
import * as semver from 'semver';
|
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
|
@ -122,32 +121,3 @@ interface installerInputsOptions {
|
||||||
toolchainIds: Array<string>;
|
toolchainIds: Array<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVersionFromFileContent(content: string, distributionName: string): string | null {
|
|
||||||
const javaVersionRegExp = /(?<version>(?<=(^|\s|\-))(\d+\S*))(\s|$)/;
|
|
||||||
const fileContent = content.match(javaVersionRegExp)?.groups?.version
|
|
||||||
? (content.match(javaVersionRegExp)?.groups?.version as string)
|
|
||||||
: '';
|
|
||||||
if (!fileContent) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const tentativeVersion = avoidOldNotation(fileContent);
|
|
||||||
|
|
||||||
let version = semver.validRange(tentativeVersion)
|
|
||||||
? tentativeVersion
|
|
||||||
: semver.coerce(tentativeVersion);
|
|
||||||
|
|
||||||
if (!version) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (constants.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
|
|
||||||
version = semver.major(version).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return version.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
|
||||||
function avoidOldNotation(content: string): string {
|
|
||||||
return content.startsWith('1.') ? content.substring(2) : content;
|
|
||||||
}
|
|
||||||
|
|
33
src/util.ts
33
src/util.ts
|
@ -6,7 +6,7 @@ import * as cache from '@actions/cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import { INPUT_JOB_STATUS } from './constants';
|
import { INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION } from './constants';
|
||||||
|
|
||||||
export function getTempDir() {
|
export function getTempDir() {
|
||||||
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
||||||
|
@ -99,3 +99,34 @@ export function isCacheFeatureAvailable(): boolean {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function getVersionFromFileContent(content: string, distributionName: string): string | null {
|
||||||
|
const javaVersionRegExp = /(?<version>(?<=(^|\s|\-))(\d+\S*))(\s|$)/;
|
||||||
|
const fileContent = content.match(javaVersionRegExp)?.groups?.version
|
||||||
|
? (content.match(javaVersionRegExp)?.groups?.version as string)
|
||||||
|
: '';
|
||||||
|
if (!fileContent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const tentativeVersion = avoidOldNotation(fileContent);
|
||||||
|
|
||||||
|
let version = semver.validRange(tentativeVersion)
|
||||||
|
? tentativeVersion
|
||||||
|
: semver.coerce(tentativeVersion);
|
||||||
|
|
||||||
|
if (!version) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
|
||||||
|
version = semver.major(version).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return version.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||||
|
export function avoidOldNotation(content: string): string {
|
||||||
|
return content.startsWith('1.') ? content.substring(2) : content;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue