mirror of
https://github.com/actions/setup-java.git
synced 2025-07-23 15:08:26 +02:00
fix review points
This commit is contained in:
parent
c13e4b13ba
commit
291b946ea5
2 changed files with 33 additions and 32 deletions
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 tc from '@actions/tool-cache';
|
||||
import { INPUT_JOB_STATUS } from './constants';
|
||||
import { INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION } from './constants';
|
||||
|
||||
export function getTempDir() {
|
||||
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
||||
|
@ -99,3 +99,34 @@ export function isCacheFeatureAvailable(): boolean {
|
|||
|
||||
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