Skip to content

Commit

Permalink
Export findVersions() (actions#14)
Browse files Browse the repository at this point in the history
* Export findVersions()

* Rename `findVersions()` to `findAllVersions()`
  • Loading branch information
davidstaheli authored and Danny McCormick committed Jun 7, 2019
1 parent 71a9b2d commit e3317c6
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions packages/tool-cache/src/tool-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export async function cacheFile(
}

/**
* finds the path to a tool in the local installed tool cache
* Finds the path to a tool version in the local installed tool cache
*
* @param toolName name of the tool
* @param versionSpec version of the tool
Expand All @@ -353,7 +353,7 @@ export function find(

// attempt to resolve an explicit version
if (!_isExplicitVersion(versionSpec)) {
const localVersions: string[] = _findLocalToolVersions(toolName, arch)
const localVersions: string[] = findAllVersions(toolName, arch)
const match = _evaluateVersions(localVersions, versionSpec)
versionSpec = match
}
Expand All @@ -374,6 +374,33 @@ export function find(
return toolPath
}

/**
* Finds the paths to all versions of a tool that are installed in the local tool cache
*
* @param toolName name of the tool
* @param arch optional arch. defaults to arch of computer
*/
export function findAllVersions(toolName: string, arch?: string): string[] {
const versions: string[] = []

arch = arch || os.arch()
const toolPath = path.join(cacheRoot, toolName)

if (fs.existsSync(toolPath)) {
const children: string[] = fs.readdirSync(toolPath)
for (const child of children) {
if (_isExplicitVersion(child)) {
const fullPath = path.join(toolPath, child, arch || '')
if (fs.existsSync(fullPath) && fs.existsSync(`${fullPath}.complete`)) {
versions.push(child)
}
}
}
}

return versions
}

async function _createExtractFolder(dest?: string): Promise<string> {
if (!dest) {
// create a temp dir
Expand Down Expand Up @@ -450,24 +477,3 @@ function _evaluateVersions(versions: string[], versionSpec: string): string {

return version
}

function _findLocalToolVersions(toolName: string, arch?: string): string[] {
const versions: string[] = []

arch = arch || os.arch()
const toolPath = path.join(cacheRoot, toolName)

if (fs.existsSync(toolPath)) {
const children: string[] = fs.readdirSync(toolPath)
for (const child of children) {
if (_isExplicitVersion(child)) {
const fullPath = path.join(toolPath, child, arch || '')
if (fs.existsSync(fullPath) && fs.existsSync(`${fullPath}.complete`)) {
versions.push(child)
}
}
}
}

return versions
}

0 comments on commit e3317c6

Please sign in to comment.