mirror of
https://github.com/actions/setup-java.git
synced 2025-04-21 02:16:45 +00:00
handle 4th digit
This commit is contained in:
parent
fb17d0223d
commit
408d6f3eea
8 changed files with 3172 additions and 86 deletions
31
src/util.ts
31
src/util.ts
|
@ -1,10 +1,13 @@
|
|||
import os from 'os';
|
||||
import path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as semver from 'semver';
|
||||
|
||||
import * as tc from '@actions/tool-cache';
|
||||
|
||||
export function getTempDir() {
|
||||
return process.env['RUNNER_TEMP'] || os.tmpdir();
|
||||
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
||||
|
||||
return tempDirectory;
|
||||
}
|
||||
|
||||
export function getVersionFromToolcachePath(toolPath: string) {
|
||||
|
@ -37,3 +40,27 @@ export async function extractJdkFile(toolPath: string, extension?: string) {
|
|||
export function getDownloadArchiveExtension() {
|
||||
return process.platform === 'win32' ? 'zip' : 'tar.gz';
|
||||
}
|
||||
|
||||
export function isVersionSatisfies(range: string, version: string): boolean {
|
||||
if (semver.valid(range)) {
|
||||
// if full version with build digit is provided as a range (such as '1.2.3+4')
|
||||
// we should check for exact equal via compareBuild
|
||||
// since semver.satisfies doesn't handle 4th digit
|
||||
const semRange = semver.parse(range);
|
||||
if (semRange && semRange.build?.length > 0) {
|
||||
return semver.compareBuild(range, version) === 0;
|
||||
}
|
||||
}
|
||||
|
||||
return semver.satisfies(version, range);
|
||||
}
|
||||
|
||||
export function getToolcachePath(toolName: string, version: string, architecture: string) {
|
||||
const toolcacheRoot = process.env['RUNNER_TOOL_CACHE'] ?? '';
|
||||
const fullPath = path.join(toolcacheRoot, toolName, version, architecture);
|
||||
if (fs.existsSync(fullPath)) {
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue