Skip to content

Commit 43257c1

Browse files
committed
20220626C
1 parent 98709ac commit 43257c1

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper/tool-cache/cache-directory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import { cacheDir as ghactionsToolCacheCacheDirectory } from "@actions/tool-cache";
33
const input = JSON.parse(process.argv[2]);
4-
const result = await ghactionsToolCacheCacheDirectory(input.SourceDirectory, input.ToolName, input.Version, input.Architecture).catch((reason) => {
4+
const result = await ghactionsToolCacheCacheDirectory(input.SourceDirectory, input.Name, input.Version, input.Architecture).catch((reason) => {
55
console.error(reason);
66
return process.exit(1);
77
});

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper/tool-cache/cache-file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import { cacheFile as ghactionsToolCacheCacheFile } from "@actions/tool-cache";
33
const input = JSON.parse(process.argv[2]);
4-
const result = await ghactionsToolCacheCacheFile(input.SourceFile, input.TargetFile, input.ToolName, input.Version, input.Architecture).catch((reason) => {
4+
const result = await ghactionsToolCacheCacheFile(input.SourceFile, input.TargetFile, input.Name, input.Version, input.Architecture).catch((reason) => {
55
console.error(reason);
66
return process.exit(1);
77
});

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper/tool-cache/find-all-versions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import { findAllVersions as ghactionsToolCacheFindAllVersions } from "@actions/tool-cache";
33
const input = JSON.parse(process.argv[2]);
4-
const result = ghactionsToolCacheFindAllVersions(input.ToolName, input.Architecture);
4+
const result = ghactionsToolCacheFindAllVersions(input.Name, input.Architecture);
55
console.log(process.argv[3]);
66
console.log(JSON.stringify({
77
Paths: result

hugoalh.GitHubActionsToolkit/module/nodejs-wrapper/tool-cache/find.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import { find as ghactionsToolCacheFind } from "@actions/tool-cache";
33
const input = JSON.parse(process.argv[2]);
4-
const result = ghactionsToolCacheFind(input.ToolName, input.Version, input.Architecture);
4+
const result = ghactionsToolCacheFind(input.Name, input.Version, input.Architecture);
55
console.log(process.argv[3]);
66
console.log(JSON.stringify({
77
Path: result

hugoalh.GitHubActionsToolkit/module/tool-cache.psm1

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,51 @@ Set-Alias -Name 'Expand-ToolCacheCompressedArchive' -Value 'Expand-ToolCacheComp
8585
Set-Alias -Name 'Expand-ToolCacheFile' -Value 'Expand-ToolCacheCompressedFile' -Option 'ReadOnly' -Scope 'Local'
8686
<#
8787
.SYNOPSIS
88+
GitHub Actions - Find Tool Cache
89+
.DESCRIPTION
90+
Find the path of a tool in the local installed tool cache.
91+
.PARAMETER Name
92+
Tool name.
93+
.PARAMETER Architecture
94+
Tool architecture.
95+
.PARAMETER Version
96+
Tool version, by Semantic Versioning (SevVer).
97+
.OUTPUTS
98+
[String] Path of a version of a tool.
99+
[String[]] Paths of all versions of a tool.
100+
#>
101+
Function Find-ToolCache {
102+
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_find-githubactionstoolcache#Find-GitHubActionsToolCache')]
103+
[OutputType(([String], [String[]]))]
104+
Param (
105+
[Alias('ToolName')][String]$Name,
106+
[String]$Architecture,
107+
[String]$Version = '*'
108+
)
109+
If (!(Test-GitHubActionsEnvironment -ToolCache)) {
110+
Return (Write-Error -Message 'Unable to get GitHub Actions tool cache resources!' -Category 'ResourceUnavailable')
111+
}
112+
[Hashtable]$InputObject = @{
113+
Name = $Name
114+
}
115+
[Boolean]$IsFindAll = $False
116+
If ($Version -ieq '*') {
117+
$IsFindAll = $True
118+
} ElseIf ($Version.Length -igt 0) {
119+
$InputObject.Version = $Version
120+
}
121+
If ($Architecture.Length -igt 0) {
122+
$InputObject.Architecture = $Architecture
123+
}
124+
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path "tool-cache\find$($IsFindAll ? '-all-versions' : '').js" -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)
125+
If ($ResultRaw -ieq $False) {
126+
Return
127+
}
128+
[PSCUstomObject]$Result = ($ResultRaw | ConvertFrom-Json -Depth 100)
129+
Return ($IsFindAll ? $Result.Paths : $Result.Path)
130+
}
131+
<#
132+
.SYNOPSIS
88133
GitHub Actions - Invoke Tool Cache Tool Downloader
89134
.DESCRIPTION
90135
Download a tool from URI and stream it into a file.
@@ -145,6 +190,7 @@ Function Invoke-ToolCacheToolDownloader {
145190
}
146191
Export-ModuleMember -Function @(
147192
'Expand-ToolCacheCompressedFile',
193+
'Find-ToolCache',
148194
'Invoke-ToolCacheToolDownloader'
149195
) -Alias @(
150196
'Expand-ToolCacheArchive',

0 commit comments

Comments
 (0)