Skip to content

Commit 0eae123

Browse files
committed
20230719A
1 parent ebbd94e commit 0eae123

17 files changed

+466
-400
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ Import-Module -Name 'hugoalh.GitHubActionsToolkit' -Prefix 'GitHubActions' -Scop
9393

9494
### Example
9595

96+
```ps1
97+
Set-GitHubActionsOutput -Name 'foo' -Value 'bar'
98+
```
99+
96100
```ps1
97101
Write-GitHubActionNotice -Message 'Hello, world!'
98102
```

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RootModule = 'hugoalh.GitHubActionsToolkit.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '1.6.0'
6+
ModuleVersion = '1.7.0'
77

88
# Supported PSEditions
99
# CompatiblePSEditions = @()
@@ -70,6 +70,10 @@
7070
'Add-StepSummaryLink',
7171
'Add-StepSummarySubscriptText',
7272
'Add-StepSummarySuperscriptText',
73+
'Clear-FileCommand',
74+
'Clear-Output',
75+
'Clear-State',
76+
'Clear-StepSummary',
7377
'ConvertFrom-CsvM',
7478
'ConvertFrom-CsvS',
7579
'Disable-StdOutCommandEcho',
@@ -89,11 +93,11 @@
8993
'Get-WebhookEventPayload',
9094
'Get-WorkflowRunUri',
9195
'Import-Artifact',
96+
'Invoke-NodeJsWrapper',
9297
'Invoke-ToolCacheToolDownloader',
9398
'Register-ToolCacheDirectory',
9499
'Register-ToolCacheFile',
95100
'Remove-ProblemMatcher',
96-
'Remove-StepSummary',
97101
'Restore-Cache',
98102
'Save-Cache',
99103
'Set-EnvironmentVariable',
@@ -175,6 +179,10 @@
175179
'Get-WebhookPayload',
176180
'Get-WorkflowRunUrl',
177181
'Import-Cache',
182+
'Remove-FileCommand',
183+
'Remove-Output',
184+
'Remove-State',
185+
'Remove-StepSummary',
178186
'Restore-Artifact',
179187
'Restore-State',
180188
'Resume-CommandProcess',
@@ -266,7 +274,7 @@
266274
ReleaseNotes = '(Please visit https://github.com/hugoalh-studio/ghactions-toolkit-powershell/releases.)'
267275

268276
# Prerelease string of this module
269-
# Prerelease = ''
277+
Prerelease = 'beta1'
270278

271279
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
272280
RequireLicenseAcceptance = $False

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psm1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Requires -PSEdition Core -Version 7.2
2-
[String[]]$ModulesNames = @(
2+
[String[]]$ModulesName = @(
33
'artifact',
44
'cache',
55
'command-base',
@@ -16,14 +16,14 @@
1616
'utility'
1717
)
1818
Import-Module -Name (
19-
$ModulesNames |
19+
$ModulesName |
2020
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath 'module' -AdditionalChildPath "$_.psm1" }
2121
) -Scope 'Local'
22-
[PSCustomObject[]]$PackageCommands = Get-Command -Module $ModulesNames -ListImported
23-
[String[]]$PackageCommandsFunctions = $PackageCommands |
22+
[PSCustomObject[]]$PackageCommands = Get-Command -Module $ModulesName -ListImported
23+
[String[]]$PackageFunctions = $PackageCommands |
2424
Where-Object -FilterScript { $_.CommandType -ieq 'Function' } |
2525
Select-Object -ExpandProperty 'Name'
26-
[String[]]$PackageCommandsAliases = $PackageCommands |
26+
[String[]]$PackageAliases = $PackageCommands |
2727
Where-Object -FilterScript { $_.CommandType -ieq 'Alias' } |
2828
Select-Object -ExpandProperty 'Name'
29-
Export-ModuleMember -Function $PackageCommandsFunctions -Alias $PackageCommandsAliases
29+
Export-ModuleMember -Function $PackageFunctions -Alias $PackageAliases

hugoalh.GitHubActionsToolkit/module/artifact.psm1

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ Export artifact to persist the data and/or share with the future jobs in the sam
1313
.PARAMETER Name
1414
Name of the artifact.
1515
.PARAMETER Path
16-
Paths of the files that need to export as artifact.
16+
Path of the files that need to export as artifact.
1717
.PARAMETER LiteralPath
18-
Literal paths of the files that need to export as artifact.
19-
.PARAMETER BaseRoot
20-
Absolute literal path of the base root directory of the files for control files structure.
21-
.PARAMETER ContinueOnIssue
18+
Literal path of the files that need to export as artifact.
19+
.PARAMETER RootDirectory
20+
Absolute literal path of the root directory of the files for control files structure.
21+
.PARAMETER ContinueOnError
2222
Whether the export should continue in the event of files fail to export; If not set and issue is encountered, export will stop and queued files will not export, the partial artifact availables which include files up until the issue; If set and issue is encountered, the issue file will ignore and skip, and queued files will still export, the partial artifact availables which include everything but exclude issue files.
23-
.PARAMETER RetentionTime
24-
Retention time of the artifact, by days.
23+
.PARAMETER RetentionDays
24+
Retention days of the artifact.
2525
.OUTPUTS
2626
[PSCustomObject] Metadata of the exported artifact.
2727
#>
@@ -32,36 +32,38 @@ Function Export-Artifact {
3232
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][String]$Name,
3333
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][Alias('File', 'Files', 'Paths')][String[]]$Path,
3434
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
35-
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateScript({ [System.IO.Path]::IsPathRooted($_) -and (Test-Path -LiteralPath $_ -PathType 'Container') }, ErrorMessage = '`{0}` is not an exist and valid directory!')][Alias('Root')][String]$BaseRoot = $Env:GITHUB_WORKSPACE,
36-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('ContinueOnError')][Switch]$ContinueOnIssue,
37-
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, [Int16]::MaxValue)][Alias('RetentionDay')][Int16]$RetentionTime
35+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateScript({ [System.IO.Path]::IsPathRooted($_) -and (Test-Path -LiteralPath $_ -PathType 'Container') }, ErrorMessage = '`{0}` is not an exist and valid directory!')][Alias('BaseRoot', 'Root')][String]$RootDirectory = $Env:GITHUB_WORKSPACE,
36+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('ContinueOnIssue')][Switch]$ContinueOnError,
37+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, [Int16]::MaxValue)][Alias('RetentionDay', 'RetentionTime')][Int16]$RetentionDays
3838
)
3939
Process {
4040
Switch ($PSCmdlet.ParameterSetName) {
4141
'LiteralPath' {
42-
[String[]]$PathsProceed = $LiteralPath |
43-
ForEach-Object -Process { [System.IO.Path]::IsPathRooted($_) ? $_ : (Join-Path -Path $BaseRoot -ChildPath $_) }
42+
[String[]]$Items = $LiteralPath |
43+
ForEach-Object -Process { [System.IO.Path]::IsPathRooted($_) ? $_ : (Join-Path -Path $RootDirectory -ChildPath $_) }
4444
}
4545
'Path' {
46-
[String[]]$PathsProceed = @()
47-
ForEach ($Item In $Path) {
48-
Try {
49-
$PathsProceed += Resolve-Path -Path ([System.IO.Path]::IsPathRooted($Item) ? $Item : (Join-Path -Path $BaseRoot -ChildPath $Item))
46+
[String[]]$Items = $Path |
47+
ForEach-Object -Process {
48+
Try {
49+
Resolve-Path -Path ([System.IO.Path]::IsPathRooted($_) ? $_ : (Join-Path -Path $RootDirectory -ChildPath $_)) |
50+
Write-Output
51+
}
52+
Catch {
53+
$_ |
54+
Write-Output
55+
}
5056
}
51-
Catch {
52-
$PathsProceed += $Item
53-
}
54-
}
5557
}
5658
}
5759
[Hashtable]$Argument = @{
58-
Name = $Name
59-
Path = $PathsProceed
60-
BaseRoot = $BaseRoot
61-
ContinueOnIssue = $ContinueOnIssue.IsPresent
60+
'name' = $Name
61+
'items' = $Items
62+
'rootDirectory' = $RootDirectory
63+
'continueOnError' = $ContinueOnError.IsPresent
6264
}
63-
If ($RetentionTime -gt 0) {
64-
$Argument.RetentionTIme = $RetentionTime
65+
If ($RetentionDays -gt 0) {
66+
$Argument.('retentionDays') = $RetentionDays
6567
}
6668
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/upload' -Argument $Argument |
6769
Write-Output
@@ -99,15 +101,15 @@ Function Import-Artifact {
99101
Switch ($PSCmdlet.ParameterSetName) {
100102
'All' {
101103
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download-all' -Argument @{
102-
Destination = $Destination
104+
'destination' = $Destination
103105
} |
104106
Write-Output
105107
}
106108
'Single' {
107109
Invoke-GitHubActionsNodeJsWrapper -Name 'artifact/download' -Argument @{
108-
Name = $Name
109-
Destination = $Destination
110-
CreateSubfolder = $CreateSubfolder.IsPresent
110+
'name' = $Name
111+
'destination' = $Destination
112+
'createSubfolder' = $CreateSubfolder.IsPresent
111113
} |
112114
Write-Output
113115
}

hugoalh.GitHubActionsToolkit/module/cache.psm1

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,26 @@ Function Restore-Cache {
4444
)
4545
Process {
4646
[Hashtable]$Argument = @{
47-
PrimaryKey = $Key[0]
48-
Path = ($PSCmdlet.ParameterSetName -ieq 'LiteralPath') ? (
47+
'primaryKey' = $Key[0]
48+
'restoreKeys' = $Key |
49+
Select-Object -SkipIndex 0
50+
'paths' = ($PSCmdlet.ParameterSetName -ieq 'LiteralPath') ? (
4951
$LiteralPath |
5052
ForEach-Object -Process { [WildcardPattern]::Escape($_) }
5153
) : $Path
52-
UseAzureSdk = !$NotUseAzureSdk.IsPresent
53-
LookUp = $LookUp.IsPresent
54-
}
55-
[String[]]$RestoreKey = $Key |
56-
Select-Object -SkipIndex 0
57-
If ($RestoreKey.Count -gt 0) {
58-
$Argument.RestoreKey = $RestoreKey
54+
'useAzureSdk' = !$NotUseAzureSdk.IsPresent
55+
'lookup' = $LookUp.IsPresent
5956
}
6057
If ($DownloadConcurrency -gt 0) {
61-
$Argument.DownloadConcurrency = $DownloadConcurrency
58+
$Argument.('downloadConcurrency') = $DownloadConcurrency
6259
}
6360
If ($SegmentTimeout -gt 0) {
64-
$Argument.SegmentTimeout = $SegmentTimeout * 1000
61+
$Argument.('segmentTimeout') = $SegmentTimeout * 1000
6562
}
6663
If ($Timeout -gt 0) {
67-
$Argument.Timeout = $Timeout * 1000
64+
$Argument.('timeout') = $Timeout * 1000
6865
}
69-
(Invoke-GitHubActionsNodeJsWrapper -Name 'cache/restore' -Argument $Argument)?.CacheKey |
66+
Invoke-GitHubActionsNodeJsWrapper -Name 'cache/restore' -Argument $Argument |
7067
Write-Output
7168
}
7269
}
@@ -82,38 +79,38 @@ Key of the cache.
8279
Paths of the cache.
8380
.PARAMETER LiteralPath
8481
Literal paths of the cache.
85-
.PARAMETER UploadChunkSizes
86-
Maximum chunk size of the cache, by KB.
82+
.PARAMETER UploadChunkSize
83+
Upload chunk size of the cache, by KB.
8784
.PARAMETER UploadConcurrency
8885
Number of parallel uploads of the cache.
8986
.OUTPUTS
90-
[String] ID of the cache.
87+
[UInt64] ID of the cache.
9188
#>
9289
Function Save-Cache {
9390
[CmdletBinding(DefaultParameterSetName = 'Path', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_savegithubactionscache')]
94-
[OutputType([String])]
91+
[OutputType([UInt64])]
9592
Param (
9693
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][Alias('Name')][String]$Key,
9794
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][Alias('File', 'Files', 'Paths')][String[]]$Path,
9895
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
99-
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, 1MB)][Alias('ChunkSize', 'ChunkSizes', 'UploadChunkSize')][UInt32]$UploadChunkSizes,
96+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, 1MB)][Alias('ChunkSize', 'ChunkSizes', 'UploadChunkSizes')][UInt32]$UploadChunkSize,
10097
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, 16)][Alias('Concurrency')][Byte]$UploadConcurrency
10198
)
10299
Process {
103100
[Hashtable]$Argument = @{
104-
Key = $Key
105-
Path = ($PSCmdlet.ParameterSetName -ieq 'LiteralPath') ? (
101+
'key' = $Key
102+
'paths' = ($PSCmdlet.ParameterSetName -ieq 'LiteralPath') ? (
106103
$LiteralPath |
107104
ForEach-Object -Process { [WildcardPattern]::Escape($_) }
108105
) : $Path
109106
}
110-
If ($UploadChunkSizes -gt 0) {
111-
$Argument.UploadChunkSizes = $UploadChunkSizes * 1KB
107+
If ($UploadChunkSize -gt 0) {
108+
$Argument.('uploadChunkSize') = $UploadChunkSize * 1KB
112109
}
113110
If ($UploadConcurrency -gt 0) {
114-
$Argument.UploadConcurrency = $UploadConcurrency
111+
$Argument.('uploadConcurrency') = $UploadConcurrency
115112
}
116-
(Invoke-GitHubActionsNodeJsWrapper -Name 'cache/save' -Argument $Argument)?.CacheId |
113+
Invoke-GitHubActionsNodeJsWrapper -Name 'cache/save' -Argument $Argument |
117114
Write-Output
118115
}
119116
}

hugoalh.GitHubActionsToolkit/module/command-base.psm1

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,43 @@ Class GitHubActionsStdOutCommand {
1515
}
1616
<#
1717
.SYNOPSIS
18+
GitHub Actions - Clear File Command
19+
.DESCRIPTION
20+
Clear file command.
21+
.PARAMETER FileCommand
22+
File command. (LEGACY: Literal path of the file command.)
23+
.OUTPUTS
24+
[Void]
25+
#>
26+
Function Clear-FileCommand {
27+
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_cleargithubactionsfilecommand')]
28+
[OutputType([Void])]
29+
Param (
30+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][Alias('Command', 'LiteralPath'<# LEGACY #>, 'Path'<# LEGACY #>)][String]$FileCommand
31+
)
32+
Process {
33+
If (<# LEGACY #>[System.IO.Path]::IsPathFullyQualified($FileCommand)) {
34+
[String]$FileCommandPath = $FileCommand
35+
}
36+
Else {
37+
Try {
38+
[String]$FileCommandPath = Get-Content -LiteralPath "Env:\$($FileCommand.ToUpper())" -ErrorAction 'Stop'
39+
}
40+
Catch {
41+
Write-Error -Message "Unable to clear the GitHub Actions file command: Environment path ``$($FileCommand.ToUpper())`` is not defined!" -Category 'ResourceUnavailable'
42+
Return
43+
}
44+
If (![System.IO.Path]::IsPathFullyQualified($FileCommandPath)) {
45+
Write-Error -Message "Unable to clear the GitHub Actions file command: Environment path ``$($FileCommand.ToUpper())`` is not contain a valid file path!" -Category 'ResourceUnavailable'
46+
Return
47+
}
48+
}
49+
Set-Content -LiteralPath $FileCommandPath -Value '' -Confirm:$False -Encoding 'UTF8NoBOM'
50+
}
51+
}
52+
Set-Alias -Name 'Remove-FileCommand' -Value 'Clear-FileCommand' -Option 'ReadOnly' -Scope 'Local'
53+
<#
54+
.SYNOPSIS
1855
GitHub Actions - Write File Command
1956
.DESCRIPTION
2057
Write file command to communicate with the runner machine.
@@ -41,7 +78,7 @@ Function Write-FileCommand {
4178
}
4279
Else {
4380
Try {
44-
[String]$FileCommandPath = Get-Content -LiteralPath "Env:\$([WildcardPattern]::Escape($FileCommand.ToUpper()))" -ErrorAction 'Stop'
81+
[String]$FileCommandPath = Get-Content -LiteralPath "Env:\$($FileCommand.ToUpper())" -ErrorAction 'Stop'
4582
}
4683
Catch {
4784
Write-Error -Message "Unable to write the GitHub Actions file command: Environment path ``$($FileCommand.ToUpper())`` is not defined!" -Category 'ResourceUnavailable'
@@ -103,8 +140,10 @@ Function Write-StdOutCommand {
103140
}
104141
Set-Alias -Name 'Write-Command' -Value 'Write-StdOutCommand' -Option 'ReadOnly' -Scope 'Local'
105142
Export-ModuleMember -Function @(
143+
'Clear-FileCommand',
106144
'Write-FileCommand',
107145
'Write-StdOutCommand'
108146
) -Alias @(
147+
'Remove-FileCommand',
109148
'Write-Command'
110149
)

hugoalh.GitHubActionsToolkit/module/environment-variable.psm1

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,25 @@ Function Add-PATH {
3838
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Scopes')][GitHubActionsEnvironmentVariableScopes]$Scope = [GitHubActionsEnvironmentVariableScopes]3
3939
)
4040
Process {
41-
ForEach ($Item In (
42-
$Path |
43-
Select-Object -Unique
44-
)) {
45-
If (!$NoValidator.IsPresent -and !([System.IO.Path]::IsPathRooted($Item) -and (Test-Path -Path $Item -PathType 'Container' -IsValid))) {
46-
Write-Error -Message "``$Item`` is not a valid PATH!" -Category 'SyntaxError'
47-
Continue
48-
}
49-
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Current) -ieq [GitHubActionsEnvironmentVariableScopes]::Current) {
50-
Add-Content -LiteralPath $Env:PATH -Value "$([System.IO.Path]::PathSeparator)$Item" -Confirm:$False -NoNewLine
51-
}
52-
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Subsequent) -ieq [GitHubActionsEnvironmentVariableScopes]::Subsequent) {
53-
If ([System.IO.Path]::IsPathFullyQualified($Env:GITHUB_PATH)) {
54-
Add-Content -LiteralPath $Env:GITHUB_PATH -Value $Item -Confirm:$False -Encoding 'UTF8NoBOM'
41+
$Path |
42+
Select-Object -Unique |
43+
ForEach-Object -Process {
44+
If (!$NoValidator.IsPresent -and !([System.IO.Path]::IsPathRooted($_) -and (Test-Path -Path $_ -PathType 'Container' -IsValid))) {
45+
Write-Error -Message "``$_`` is not a valid PATH!" -Category 'SyntaxError'
46+
Continue
5547
}
56-
Else {
57-
Write-Error -Message 'Unable to write the GitHub Actions path: Environment path `GITHUB_PATH` is not defined!' -Category 'ResourceUnavailable'
48+
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Current) -ieq [GitHubActionsEnvironmentVariableScopes]::Current) {
49+
Add-Content -LiteralPath $Env:PATH -Value "$([System.IO.Path]::PathSeparator)$_" -Confirm:$False -NoNewLine
50+
}
51+
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Subsequent) -ieq [GitHubActionsEnvironmentVariableScopes]::Subsequent) {
52+
If ([System.IO.Path]::IsPathFullyQualified($Env:GITHUB_PATH)) {
53+
Add-Content -LiteralPath $Env:GITHUB_PATH -Value $_ -Confirm:$False -Encoding 'UTF8NoBOM'
54+
}
55+
Else {
56+
Write-Error -Message 'Unable to write the GitHub Actions path: Environment path `GITHUB_PATH` is not defined!' -Category 'ResourceUnavailable'
57+
}
5858
}
5959
}
60-
}
6160
}
6261
}
6362
<#

0 commit comments

Comments
 (0)