Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export isExplicitVersion and evaluateVersions #796

Merged
merged 3 commits into from May 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions packages/tool-cache/src/tool-cache.ts
Expand Up @@ -472,9 +472,9 @@ export function find(
arch = arch || os.arch()

// attempt to resolve an explicit version
if (!_isExplicitVersion(versionSpec)) {
if (!isExplicitVersion(versionSpec)) {
const localVersions: string[] = findAllVersions(toolName, arch)
const match = _evaluateVersions(localVersions, versionSpec)
const match = evaluateVersions(localVersions, versionSpec)
versionSpec = match
}

Expand Down Expand Up @@ -514,7 +514,7 @@ export function findAllVersions(toolName: string, arch?: string): string[] {
if (fs.existsSync(toolPath)) {
const children: string[] = fs.readdirSync(toolPath)
for (const child of children) {
if (_isExplicitVersion(child)) {
if (isExplicitVersion(child)) {
const fullPath = path.join(toolPath, child, arch || '')
if (fs.existsSync(fullPath) && fs.existsSync(`${fullPath}.complete`)) {
versions.push(child)
Expand Down Expand Up @@ -652,7 +652,12 @@ function _completeToolPath(tool: string, version: string, arch?: string): void {
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) || ''
core.debug(`isExplicit: ${c}`)

Expand All @@ -662,7 +667,17 @@ function _isExplicitVersion(versionSpec: string): boolean {
return valid
}

thboop marked this conversation as resolved.
Show resolved Hide resolved
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 = ''
core.debug(`evaluating ${versions.length} versions`)
versions = versions.sort((a, b) => {
Expand Down