Skip to content

Commit 10e8beb

Browse files
committed
20220626D
1 parent 43257c1 commit 10e8beb

File tree

8 files changed

+120
-16
lines changed

8 files changed

+120
-16
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ Import-Module -Name 'hugoalh.GitHubActionsToolkit' -Prefix 'GitHubActions' -Scop
6161
- `Enable-GitHubActionsProcessingCommands`
6262
- `Enter-GitHubActionsLogGroup`
6363
- `Exit-GitHubActionsLogGroup`
64+
- `Expand-GitHubActionsToolCacheCompressedFile` 🧪
6465
- `Export-GitHubActionsArtifact` 🧪
66+
- `Find-GitHubActionsToolCache` 🧪
6567
- `Get-GitHubActionsInput`
6668
- `Get-GitHubActionsIsDebug`
6769
- `Get-GitHubActionsOpenIdConnectToken` 🧪
@@ -70,6 +72,9 @@ Import-Module -Name 'hugoalh.GitHubActionsToolkit' -Prefix 'GitHubActions' -Scop
7072
- `Get-GitHubActionsWebhookEventPayload`
7173
- `Get-GitHubActionsWorkflowRunUri`
7274
- `Import-GitHubActionsArtifact` 🧪
75+
- `Invoke-GitHubActionsToolCacheToolDownloader` 🧪
76+
- `Register-GitHubActionsToolCacheDirectory` 🧪
77+
- `Register-GitHubActionsToolCacheFile` 🧪
7378
- `Remove-GitHubActionsProblemMatcher`
7479
- `Remove-GitHubActionsStepSummary`
7580
- `Restore-GitHubActionsCache` 🧪

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@
7676
'Enable-ProcessingCommands',
7777
'Enter-LogGroup',
7878
'Exit-LogGroup',
79+
'Expand-ToolCacheCompressedFile',
7980
'Export-Artifact',
81+
'Find-ToolCache',
8082
'Get-Input',
8183
'Get-IsDebug',
8284
'Get-OpenIdConnectToken',
@@ -85,6 +87,9 @@
8587
'Get-WebhookEventPayload',
8688
'Get-WorkflowRunUri',
8789
'Import-Artifact',
90+
'Invoke-ToolCacheToolDownloader',
91+
'Register-ToolCacheDirectory',
92+
'Register-ToolCacheFile',
8893
'Remove-ProblemMatcher',
8994
'Remove-StepSummary',
9095
'Restore-Cache',
@@ -149,6 +154,9 @@
149154
'Enable-ProcessingCommand',
150155
'Enter-Group',
151156
'Exit-Group',
157+
'Expand-ToolCacheArchive',
158+
'Expand-ToolCacheCompressedArchive',
159+
'Expand-ToolCacheFile',
152160
'Export-Cache',
153161
'Get-Event',
154162
'Get-OidcToken',

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'parameter',
1414
'problem-matcher',
1515
'step-summary',
16+
'tool-cache',
1617
'utility'
1718
)
1819
Import-Module -Name ($ModulesNames | ForEach-Object -Process {

hugoalh.GitHubActionsToolkit/module/artifact.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Function Export-Artifact {
3737
Return ([System.IO.Path]::IsPathRooted($_) -and (Test-Path -LiteralPath $_ -PathType 'Container'))
3838
}, ErrorMessage = '`{0}` is not an exist and valid GitHub Actions artifact base root!')][Alias('Root')][String]$BaseRoot = $Env:GITHUB_WORKSPACE,
3939
[Alias('ContinueOnError', 'ContinueOnIssue', 'ContinueOnIssues', 'IgnoreIssuePath')][Switch]$IgnoreIssuePaths,
40-
[ValidateRange(1, 90)][AllowNull()][Alias('RetentionDay')][Byte]$RetentionTime = $Null
40+
[ValidateRange(1, 90)][Alias('RetentionDay')][Byte]$RetentionTime = 0
4141
)
4242
Begin {
4343
If (!(Test-GitHubActionsEnvironment -Artifact)) {
@@ -130,7 +130,7 @@ Function Export-Artifact {
130130
BaseRoot = $BaseRoot
131131
IgnoreIssuePaths = $IgnoreIssuePaths.IsPresent
132132
}
133-
If ($Null -ine $RetentionTime) {
133+
If ($RetentionTime -igt 0) {
134134
$InputObject.RetentionTIme = $RetentionTime
135135
}
136136
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path 'artifact\upload.js' -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)

hugoalh.GitHubActionsToolkit/module/cache.psm1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Function Restore-Cache {
3434
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][Alias('File', 'Files', 'Paths')][String[]]$Path,
3535
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
3636
[Alias('NoAzureSdk')][Switch]$NotUseAzureSdk,
37-
[ValidateRange(1, 16)][AllowNull()][Byte]$DownloadConcurrency = $Null,
38-
[ValidateRange(5, 900)][AllowNull()][UInt16]$Timeout = $Null
37+
[ValidateRange(1, 16)][Byte]$DownloadConcurrency = 0,
38+
[ValidateRange(5, 900)][UInt16]$Timeout = 0
3939
)
4040
Begin {
4141
If (!(Test-GitHubActionsEnvironment -Cache)) {
@@ -74,10 +74,10 @@ Function Restore-Cache {
7474
UseAzureSdk = !$NotUseAzureSdk.IsPresent
7575
}
7676
If (!$NotUseAzureSdk.IsPresent) {
77-
If ($Null -ine $DownloadConcurrency) {
77+
If ($DownloadConcurrency -igt 0) {
7878
$InputObject.DownloadConcurrency = $DownloadConcurrency
7979
}
80-
If ($Null -ine $Timeout) {
80+
If ($Timeout -igt 0) {
8181
$InputObject.Timeout = $Timeout * 1000
8282
}
8383
}
@@ -116,8 +116,8 @@ Function Save-Cache {
116116
}, ErrorMessage = '`{0}` is not a valid GitHub Actions cache key, and/or more than 512 characters!')][Alias('Name')][String]$Key,
117117
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][Alias('File', 'Files', 'Paths')][String[]]$Path,
118118
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
119-
[ValidateRange(1KB, 1GB)][AllowNull()][UInt32]$UploadChunkSizes = $Null,
120-
[ValidateRange(1, 16)][AllowNull()][Byte]$UploadConcurrency = $Null
119+
[ValidateRange(1KB, 1GB)][UInt32]$UploadChunkSizes = 0,
120+
[ValidateRange(1, 16)][Byte]$UploadConcurrency = 0
121121
)
122122
Begin {
123123
If (!(Test-GitHubActionsEnvironment -Cache)) {
@@ -146,10 +146,10 @@ Function Save-Cache {
146146
Key = $Key
147147
Path = $PathsProceed
148148
}
149-
If ($Null -ine $UploadChunkSizes) {
149+
If ($UploadChunkSizes -igt 0) {
150150
$InputObject.UploadChunkSizes = $UploadChunkSizes
151151
}
152-
If ($Null -ine $UploadConcurrency) {
152+
If ($UploadConcurrency -igt 0) {
153153
$InputObject.UploadConcurrency = $UploadConcurrency
154154
}
155155
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path 'cache\save.js' -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)

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.Name, input.Version, input.Architecture).catch((reason) => {
4+
const result = await ghactionsToolCacheCacheDirectory(input.Source, 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.Name, input.Version, input.Architecture).catch((reason) => {
4+
const result = await ghactionsToolCacheCacheFile(input.Source, input.Target, input.Name, input.Version, input.Architecture).catch((reason) => {
55
console.error(reason);
66
return process.exit(1);
77
});

hugoalh.GitHubActionsToolkit/module/tool-cache.psm1

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Tool name.
9393
.PARAMETER Architecture
9494
Tool architecture.
9595
.PARAMETER Version
96-
Tool version, by Semantic Versioning (SevVer).
96+
Tool version, by Semantic Versioning (SemVer).
9797
.OUTPUTS
9898
[String] Path of a version of a tool.
9999
[String[]] Paths of all versions of a tool.
@@ -103,8 +103,8 @@ Function Find-ToolCache {
103103
[OutputType(([String], [String[]]))]
104104
Param (
105105
[Alias('ToolName')][String]$Name,
106-
[String]$Architecture,
107-
[String]$Version = '*'
106+
[Alias('Arch')][String]$Architecture,
107+
[Alias('Ver')][String]$Version = '*'
108108
)
109109
If (!(Test-GitHubActionsEnvironment -ToolCache)) {
110110
Return (Write-Error -Message 'Unable to get GitHub Actions tool cache resources!' -Category 'ResourceUnavailable')
@@ -188,10 +188,100 @@ Function Invoke-ToolCacheToolDownloader {
188188
Return $OutputObject
189189
}
190190
}
191+
<#
192+
.SYNOPSIS
193+
GitHub Actions - Register Tool Cache Directory
194+
.DESCRIPTION
195+
Register a tool directory to cache and install in the tool cache.
196+
.PARAMETER Source
197+
Tool directory.
198+
.PARAMETER Name
199+
Tool name.
200+
.PARAMETER Version
201+
Tool version, by Semantic Versioning (SemVer).
202+
.PARAMETER Architecture
203+
Tool architecture.
204+
.OUTPUTS
205+
[String] Tool cached path.
206+
#>
207+
Function Register-ToolCacheDirectory {
208+
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_register-githubactionstoolcachedirectory#Register-GitHubActionsToolCacheDirectory')]
209+
[OutputType([String])]
210+
Param (
211+
[Parameter(Mandatory = $True, Position = 0)][Alias('SourceDirectory')]$Source,
212+
[Parameter(Mandatory = $True, Position = 1)][Alias('ToolName')][String]$Name,
213+
[Parameter(Mandatory = $True, Position = 2)][Alias('Ver')][String]$Version,
214+
[Alias('Arch')][String]$Architecture
215+
)
216+
If (!(Test-GitHubActionsEnvironment -ToolCache)) {
217+
Return (Write-Error -Message 'Unable to get GitHub Actions tool cache resources!' -Category 'ResourceUnavailable')
218+
}
219+
[Hashtable]$InputObject = @{
220+
Source = $Source
221+
Name = $Name
222+
Version = $Version
223+
}
224+
If ($Architecture.Length -igt 0) {
225+
$InputObject.Architecture = $Architecture
226+
}
227+
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path "tool-cache\cache-directory.js" -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)
228+
If ($ResultRaw -ieq $False) {
229+
Return
230+
}
231+
Return ($ResultRaw | ConvertFrom-Json -Depth 100).Path
232+
}
233+
<#
234+
.SYNOPSIS
235+
GitHub Actions - Register Tool Cache File
236+
.DESCRIPTION
237+
Register a tool file to cache and install in the tool cache.
238+
.PARAMETER Source
239+
Tool file.
240+
.PARAMETER Target
241+
Tool file in the tool cache.
242+
.PARAMETER Name
243+
Tool name.
244+
.PARAMETER Version
245+
Tool version, by Semantic Versioning (SemVer).
246+
.PARAMETER Architecture
247+
Tool architecture.
248+
.OUTPUTS
249+
[String] Tool cached path.
250+
#>
251+
Function Register-ToolCacheFile {
252+
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_register-githubactionstoolcachefile#Register-GitHubActionsToolCacheFile')]
253+
[OutputType([String])]
254+
Param (
255+
[Parameter(Mandatory = $True, Position = 0)][Alias('SourceFile')]$Source,
256+
[Parameter(Mandatory = $True, Position = 0)][Alias('TargetFile')]$Target,
257+
[Parameter(Mandatory = $True, Position = 1)][Alias('ToolName')][String]$Name,
258+
[Parameter(Mandatory = $True, Position = 2)][Alias('Ver')][String]$Version,
259+
[Alias('Arch')][String]$Architecture
260+
)
261+
If (!(Test-GitHubActionsEnvironment -ToolCache)) {
262+
Return (Write-Error -Message 'Unable to get GitHub Actions tool cache resources!' -Category 'ResourceUnavailable')
263+
}
264+
[Hashtable]$InputObject = @{
265+
Source = $Source
266+
Target = $Target
267+
Name = $Name
268+
Version = $Version
269+
}
270+
If ($Architecture.Length -igt 0) {
271+
$InputObject.Architecture = $Architecture
272+
}
273+
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path "tool-cache\cache-file.js" -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)
274+
If ($ResultRaw -ieq $False) {
275+
Return
276+
}
277+
Return ($ResultRaw | ConvertFrom-Json -Depth 100).Path
278+
}
191279
Export-ModuleMember -Function @(
192280
'Expand-ToolCacheCompressedFile',
193281
'Find-ToolCache',
194-
'Invoke-ToolCacheToolDownloader'
282+
'Invoke-ToolCacheToolDownloader',
283+
'Register-ToolCacheDirectory',
284+
'Register-ToolCacheFile'
195285
) -Alias @(
196286
'Expand-ToolCacheArchive',
197287
'Expand-ToolCacheCompressedArchive',

0 commit comments

Comments
 (0)