mirror of https://github.com/actions/toolkit
Export isExplicitVersion and evaluateVersions (#796)
* Export isExplicitVersion and evaluateVersions * Lint * Add docspull/801/head
parent
09e59b9a5c
commit
1c367e0a26
|
@ -472,9 +472,9 @@ export function find(
|
||||||
arch = arch || os.arch()
|
arch = arch || os.arch()
|
||||||
|
|
||||||
// attempt to resolve an explicit version
|
// attempt to resolve an explicit version
|
||||||
if (!_isExplicitVersion(versionSpec)) {
|
if (!isExplicitVersion(versionSpec)) {
|
||||||
const localVersions: string[] = findAllVersions(toolName, arch)
|
const localVersions: string[] = findAllVersions(toolName, arch)
|
||||||
const match = _evaluateVersions(localVersions, versionSpec)
|
const match = evaluateVersions(localVersions, versionSpec)
|
||||||
versionSpec = match
|
versionSpec = match
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,7 +514,7 @@ export function findAllVersions(toolName: string, arch?: string): string[] {
|
||||||
if (fs.existsSync(toolPath)) {
|
if (fs.existsSync(toolPath)) {
|
||||||
const children: string[] = fs.readdirSync(toolPath)
|
const children: string[] = fs.readdirSync(toolPath)
|
||||||
for (const child of children) {
|
for (const child of children) {
|
||||||
if (_isExplicitVersion(child)) {
|
if (isExplicitVersion(child)) {
|
||||||
const fullPath = path.join(toolPath, child, arch || '')
|
const fullPath = path.join(toolPath, child, arch || '')
|
||||||
if (fs.existsSync(fullPath) && fs.existsSync(`${fullPath}.complete`)) {
|
if (fs.existsSync(fullPath) && fs.existsSync(`${fullPath}.complete`)) {
|
||||||
versions.push(child)
|
versions.push(child)
|
||||||
|
@ -652,7 +652,12 @@ function _completeToolPath(tool: string, version: string, arch?: string): void {
|
||||||
core.debug('finished caching tool')
|
core.debug('finished caching tool')
|
||||||
}
|
}
|
||||||
|
|
||||||
function _isExplicitVersion(versionSpec: string): boolean {
|
/**
|
||||||
|
* Check if version string is explicit
|
||||||
|
*
|
||||||
|
* @param versionSpec version string to check
|
||||||
|
*/
|
||||||
|
export function isExplicitVersion(versionSpec: string): boolean {
|
||||||
const c = semver.clean(versionSpec) || ''
|
const c = semver.clean(versionSpec) || ''
|
||||||
core.debug(`isExplicit: ${c}`)
|
core.debug(`isExplicit: ${c}`)
|
||||||
|
|
||||||
|
@ -662,7 +667,17 @@ function _isExplicitVersion(versionSpec: string): boolean {
|
||||||
return valid
|
return valid
|
||||||
}
|
}
|
||||||
|
|
||||||
function _evaluateVersions(versions: string[], versionSpec: string): string {
|
/**
|
||||||
|
* Get the highest satisfiying semantic version in `versions` which satisfies `versionSpec`
|
||||||
|
*
|
||||||
|
* @param versions array of versions to evaluate
|
||||||
|
* @param versionSpec semantic version spec to satisfy
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function evaluateVersions(
|
||||||
|
versions: string[],
|
||||||
|
versionSpec: string
|
||||||
|
): string {
|
||||||
let version = ''
|
let version = ''
|
||||||
core.debug(`evaluating ${versions.length} versions`)
|
core.debug(`evaluating ${versions.length} versions`)
|
||||||
versions = versions.sort((a, b) => {
|
versions = versions.sort((a, b) => {
|
||||||
|
|
Loading…
Reference in New Issue