Skip to content

Commit 44af067

Browse files
committed
20221016A
1 parent 42b8c18 commit 44af067

File tree

10 files changed

+86
-56
lines changed

10 files changed

+86
-56
lines changed

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Import-Module -Name 'hugoalh.GitHubActionsToolkit' -Prefix 'GitHubActions' -Scop
8181
- `Invoke-GitHubActionsToolCacheToolDownloader` 🔘
8282
- `Register-GitHubActionsToolCacheDirectory` 🔘
8383
- `Register-GitHubActionsToolCacheFile` 🔘
84+
- `Remove-GitHubActionsFileCommand`
8485
- `Remove-GitHubActionsProblemMatcher`
8586
- `Remove-GitHubActionsStepSummary`
8687
- `Restore-GitHubActionsCache` 🔘
@@ -99,10 +100,3 @@ Import-Module -Name 'hugoalh.GitHubActionsToolkit' -Prefix 'GitHubActions' -Scop
99100
- `Write-GitHubActionsNotice`
100101
- `Write-GitHubActionsRaw`
101102
- `Write-GitHubActionsWarning`
102-
103-
### Example
104-
105-
```ps1
106-
Set-GitHubActionsOutput -Name 'foo' -Value 'bar'
107-
#=> ::set-output name=foo::bar
108-
```

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
'Invoke-ToolCacheToolDownloader',
9191
'Register-ToolCacheDirectory',
9292
'Register-ToolCacheFile',
93+
'Remove-FileCommand',
9394
'Remove-ProblemMatcher',
9495
'Remove-StepSummary',
9596
'Restore-Cache',

hugoalh.GitHubActionsToolkit/module/command-base.psm1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Import-Module -Name (
66
) |
77
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath $_ }
88
) -Prefix 'GitHubActions' -Scope 'Local'
9+
[Flags()] Enum GitHubActionsFileCommandTypes {
10+
EnvironmentVariable = 1
11+
Output = 2
12+
Path = 4
13+
State = 8
14+
StepSummary = 16
15+
}
916
<#
1017
.SYNOPSIS
1118
GitHub Actions (Private) - Format Command Parameter Value
@@ -53,6 +60,38 @@ Set-Alias -Name 'Format-CommandContent' -Value 'Format-CommandValue' -Option 'Re
5360
Set-Alias -Name 'Format-CommandMessage' -Value 'Format-CommandValue' -Option 'ReadOnly' -Scope 'Local'
5461
<#
5562
.SYNOPSIS
63+
GitHub Actions - Remove File Command
64+
.DESCRIPTION
65+
Remove the file commands.
66+
.PARAMETER Type
67+
Types of the file commands.
68+
.OUTPUTS
69+
[Void]
70+
#>
71+
Function Remove-FileCommand {
72+
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_remove-githubactionsfilecommand#Remove-GitHubActionsFileCommand')]
73+
[OutputType([Void])]
74+
Param (
75+
[Parameter(Mandatory = $True, Position = 0)][Alias('Types')][GitHubActionsFileCommandTypes]$Type
76+
)
77+
If (($Type -band [GitHubActionsFileCommandTypes]::EnvironmentVariable) -ieq [GitHubActionsFileCommandTypes]::EnvironmentVariable) {
78+
Remove-Item -LiteralPath $Env:GITHUB_ENV -Confirm:$False -ErrorAction 'Continue'
79+
}
80+
If (($Type -band [GitHubActionsFileCommandTypes]::Output) -ieq [GitHubActionsFileCommandTypes]::Output) {
81+
Remove-Item -LiteralPath $Env:GITHUB_OUTPUT -Confirm:$False -ErrorAction 'Continue'
82+
}
83+
If (($Type -band [GitHubActionsFileCommandTypes]::Path) -ieq [GitHubActionsFileCommandTypes]::Path) {
84+
Remove-Item -LiteralPath $Env:GITHUB_PATH -Confirm:$False -ErrorAction 'Continue'
85+
}
86+
If (($Type -band [GitHubActionsFileCommandTypes]::State) -ieq [GitHubActionsFileCommandTypes]::State) {
87+
Remove-Item -LiteralPath $Env:GITHUB_STATE -Confirm:$False -ErrorAction 'Continue'
88+
}
89+
If (($Type -band [GitHubActionsFileCommandTypes]::StepSummary) -ieq [GitHubActionsFileCommandTypes]::StepSummary) {
90+
Remove-Item -LiteralPath $Env:GITHUB_STEP_SUMMARY -Confirm:$False -ErrorAction 'Continue'
91+
}
92+
}
93+
<#
94+
.SYNOPSIS
5695
GitHub Actions - Write Command
5796
.DESCRIPTION
5897
Write command to communicate with the runner machine.
@@ -124,6 +163,7 @@ Function Write-FileCommand {
124163
}
125164
}
126165
Export-ModuleMember -Function @(
166+
'Remove-FileCommand',
127167
'Write-Command',
128168
'Write-FileCommand'
129169
)

hugoalh.GitHubActionsToolkit/module/command-control.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ GitHub Actions - Disable Processing Commands
6060
.DESCRIPTION
6161
Disable processing any commands, to allow log anything without accidentally execute any commands.
6262
.PARAMETER EndToken
63-
An end token for the function `Enable-GitHubActionsProcessingCommands`.
63+
An end token for re-enable processing commands.
6464
.OUTPUTS
65-
[String] An end token for the function `Enable-GitHubActionsProcessingCommands`.
65+
[String] An end token for re-enable processing commands.
6666
#>
6767
Function Disable-ProcessingCommands {
6868
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_disable-githubactionsprocessingcommands#Disable-GitHubActionsProcessingCommands')]
@@ -123,7 +123,7 @@ GitHub Actions - Enable Processing Commands
123123
.DESCRIPTION
124124
Enable processing any commands, to allow execute any commands.
125125
.PARAMETER EndToken
126-
An end token from the function `Disable-GitHubActionsProcessingCommands`.
126+
An end token from disable processing commands.
127127
.OUTPUTS
128128
[Void]
129129
#>

hugoalh.GitHubActionsToolkit/module/environment-variable.psm1

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ Function Add-PATH {
3737
[Boolean]$Legacy = [String]::IsNullOrWhiteSpace($Env:GITHUB_PATH)
3838
}
3939
Process {
40-
[String[]]$ScopeArray = $Scope.ToString() -isplit ', '
4140
ForEach ($Item In (
4241
$Path |
4342
Select-Object -Unique
@@ -46,17 +45,15 @@ Function Add-PATH {
4645
Write-Error -Message "``$Item`` is not a valid PATH!" -Category 'SyntaxError'
4746
Continue
4847
}
49-
Switch -Exact ($ScopeArray) {
50-
'Current' {
51-
Add-Content -LiteralPath $Env:PATH -Value "$([System.IO.Path]::PathSeparator)$Item" -Confirm:$False -NoNewLine
48+
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Current) -ieq [GitHubActionsEnvironmentVariableScopes]::Current) {
49+
Add-Content -LiteralPath $Env:PATH -Value "$([System.IO.Path]::PathSeparator)$Item" -Confirm:$False -NoNewLine
50+
}
51+
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Subsequent) -ieq [GitHubActionsEnvironmentVariableScopes]::Subsequent) {
52+
If ($Legacy) {
53+
Write-GitHubActionsCommand -Command 'add-path' -Value $Item
5254
}
53-
'Subsequent' {
54-
If ($Legacy) {
55-
Write-GitHubActionsCommand -Command 'add-path' -Value $Item
56-
}
57-
Else {
58-
Add-Content -LiteralPath $Env:GITHUB_PATH -Value $Item -Confirm:$False -Encoding 'UTF8NoBOM'
59-
}
55+
Else {
56+
Add-Content -LiteralPath $Env:GITHUB_PATH -Value $Item -Confirm:$False -Encoding 'UTF8NoBOM'
6057
}
6158
}
6259
}
@@ -107,18 +104,16 @@ Function Set-EnvironmentVariable {
107104
Set-EnvironmentVariable -NoToUpper:$NoToUpper.IsPresent -Scope $Scope
108105
Return
109106
}
110-
Switch -Exact ($Scope.ToString() -isplit ', ') {
111-
'Current' {
112-
[System.Environment]::SetEnvironmentVariable($Name, $Value) |
113-
Out-Null
107+
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Current) -ieq [GitHubActionsEnvironmentVariableScopes]::Current) {
108+
[System.Environment]::SetEnvironmentVariable($Name, $Value) |
109+
Out-Null
110+
}
111+
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Subsequent) -ieq [GitHubActionsEnvironmentVariableScopes]::Subsequent) {
112+
If ($Legacy) {
113+
Write-GitHubActionsCommand -Command 'set-env' -Parameter @{ 'name' = $Name } -Value $Value
114114
}
115-
'Subsequent' {
116-
If ($Legacy) {
117-
Write-GitHubActionsCommand -Command 'set-env' -Parameter @{ 'name' = $Name } -Value $Value
118-
}
119-
Else {
120-
Write-GitHubActionsFileCommand -LiteralPath $Env:GITHUB_ENV -Name $Name -Value $Value
121-
}
115+
Else {
116+
Write-GitHubActionsFileCommand -LiteralPath $Env:GITHUB_ENV -Name $Name -Value $Value
122117
}
123118
}
124119
}

hugoalh.GitHubActionsToolkit/module/log.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Enum GitHubActionsAnnotationType {
2121
.SYNOPSIS
2222
GitHub Actions - Enter Log Group
2323
.DESCRIPTION
24-
Create an expandable group in the log; Anything write to the log between functions `Enter-GitHubActionsLogGroup` and `Exit-GitHubActionsLogGroup` are inside this expandable group in the log.
24+
Create an expandable group in the log; Anything write to the log are inside this expandable group in the log.
2525
.PARAMETER Title
2626
Title of the log group.
2727
.OUTPUTS

hugoalh.GitHubActionsToolkit/module/problem-matcher.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ Function Add-ProblemMatcher {
3737
.SYNOPSIS
3838
GitHub Actions - Remove Problem Matcher
3939
.DESCRIPTION
40-
Remove problem matcher that previously added from function `Add-GitHubActionsProblemMatcher`.
40+
Remove problem matcher.
4141
.PARAMETER Owner
42-
Owners of the problem matchers that previously added from function `Add-GitHubActionsProblemMatcher`.
42+
Owners of the problem matchers.
4343
.OUTPUTS
4444
[Void]
4545
#>

hugoalh.GitHubActionsToolkit/module/step-summary.psm1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ Set-Alias -Name 'Add-StepSummarySuperscript' -Value 'Add-StepSummarySuperscriptT
215215
.SYNOPSIS
216216
GitHub Actions - Get Step Summary
217217
.DESCRIPTION
218-
Get step summary that previously added/set from functions `Add-GitHubActionsStepSummary` and `Set-GitHubActionsStepSummary`.
218+
Get the step summary.
219219
.PARAMETER Raw
220220
Whether to ignore newline characters and output the entire contents of a file in one string with the newlines preserved; By default, newline characters in a file are used as delimiters to separate the input into an array of strings.
221221
.PARAMETER Sizes
222-
Whether to get step summary sizes instead of the contents.
222+
Whether to get the sizes of the step summary instead of the contents of the step summary.
223223
.OUTPUTS
224224
[String] Step summary with the entire contents in one string.
225-
[String[]] Step summary with separate contents in multiple string by newline characters.
226-
[UInt32] Step summary sizes.
225+
[String[]] Step summary with the entire contents in multiple strings separated by newline characters.
226+
[UInt32] Sizes of the step summary.
227227
#>
228228
Function Get-StepSummary {
229229
[CmdletBinding(DefaultParameterSetName = 'Content', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_get-githubactionsstepsummary#Get-GitHubActionsStepSummary')]
@@ -253,7 +253,7 @@ Function Get-StepSummary {
253253
.SYNOPSIS
254254
GitHub Actions - Remove Step Summary
255255
.DESCRIPTION
256-
Remove step summary that previously added/set from functions `Add-GitHubActionsStepSummary` and `Set-GitHubActionsStepSummary`.
256+
Remove the step summary.
257257
.OUTPUTS
258258
[Void]
259259
#>
@@ -265,7 +265,7 @@ Function Remove-StepSummary {
265265
Write-Error -Message 'Unable to get GitHub Actions step summary resources!' -Category 'ResourceUnavailable'
266266
Return
267267
}
268-
Remove-Item -LiteralPath $Env:GITHUB_STEP_SUMMARY -Confirm:$False
268+
Remove-Item -LiteralPath $Env:GITHUB_STEP_SUMMARY -Confirm:$False -ErrorAction 'Continue'
269269
}
270270
<#
271271
.SYNOPSIS

hugoalh.GitHubActionsToolkit/module/tool-cache.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Path for the expand destination.
1919
.PARAMETER Method
2020
Method to expand compressed archive/file; Define this parameter will enforce to use defined method.
2121
.PARAMETER 7zrPath
22-
Path of the 7zr, for long path support (only when parameter `Method` is `7z`).
22+
Path of the 7zr application, for long path support (only when parameter `Method` is `7z`).
2323
2424
Most `.7z` archives do not have this problem, if `.7z` archive contains very long path, pass the path to `7zr` which will gracefully handle long paths, by default `7zdec` is used because it is a very small program and is bundled with the GitHub Actions NodeJS toolkit, however it does not support long paths, `7zr` is the reduced command line interface, it is smaller than the full command line interface, and it does support long paths, at the time of this writing, it is freely available from the LZMA SDK that is available on the 7-Zip website, be sure to check the current license agreement, if `7zr` is bundled with your action, then the path to `7zr` can be pass to this function.
2525
.PARAMETER Flag
@@ -114,7 +114,7 @@ Function Find-ToolCache {
114114
[OutputType(([String], [String[]]))]
115115
Param (
116116
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('ToolName')][String]$Name,
117-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Ver')][String]$Version,
117+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('V', 'Ver')][String]$Version,
118118
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Arch')][String]$Architecture
119119
)
120120
Begin {
@@ -217,7 +217,7 @@ Function Register-ToolCacheDirectory {
217217
Param (
218218
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][Alias('SourceDirectory')][String]$Source,
219219
[Parameter(Mandatory = $True, Position = 1, ValueFromPipelineByPropertyName = $True)][Alias('ToolName')][String]$Name,
220-
[Parameter(Mandatory = $True, Position = 2, ValueFromPipelineByPropertyName = $True)][Alias('Ver')][String]$Version,
220+
[Parameter(Mandatory = $True, Position = 2, ValueFromPipelineByPropertyName = $True)][Alias('V', 'Ver')][String]$Version,
221221
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Arch')][String]$Architecture
222222
)
223223
Begin {
@@ -267,7 +267,7 @@ Function Register-ToolCacheFile {
267267
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][Alias('SourceFile')][String]$Source,
268268
[Parameter(Mandatory = $True, Position = 1, ValueFromPipelineByPropertyName = $True)][Alias('TargetFile')][String]$Target,
269269
[Parameter(Mandatory = $True, Position = 2, ValueFromPipelineByPropertyName = $True)][Alias('ToolName')][String]$Name,
270-
[Parameter(Mandatory = $True, Position = 3, ValueFromPipelineByPropertyName = $True)][Alias('Ver')][String]$Version,
270+
[Parameter(Mandatory = $True, Position = 3, ValueFromPipelineByPropertyName = $True)][Alias('V', 'Ver')][String]$Version,
271271
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Arch')][String]$Architecture
272272
)
273273
Begin {

hugoalh.GitHubActionsToolkit/module/utility.psm1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ Function Add-SecretMask {
2424
[OutputType([Void])]
2525
Param (
2626
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][Alias('Key', 'Secret', 'Token')][String]$Value,
27-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Chunk', 'Chunks', 'WithChunk')][Switch]$WithChunks
27+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Advance', 'Advanced', 'Chunk', 'Chunks', 'WithChunk')][Switch]$WithChunks
2828
)
2929
Process {
3030
If ($Value.Length -igt 0) {
3131
Write-GitHubActionsCommand -Command 'add-mask' -Value $Value
3232
If ($WithChunks.IsPresent) {
33-
$Value -isplit '[\b\n\r\s\t_-]+' |
34-
Where-Object -FilterScript { $_ -ine $Value -and $_.Length -ige 4 } |
33+
$Value -isplit '[\b\n\r\s\t\\/_-]+' |
34+
Where-Object -FilterScript { $_.Length -ige 4 -and $_ -ine $Value } |
3535
ForEach-Object -Process { Write-GitHubActionsCommand -Command 'add-mask' -Value $_ }
3636
}
3737
}
@@ -76,13 +76,13 @@ Function Get-WebhookEventPayload {
7676
[UInt16]$Depth,# Deprecated, keep as legacy.
7777
[Switch]$NoEnumerate# Deprecated, keep as legacy.
7878
)
79-
If (Test-Environment) {
80-
Get-Content -LiteralPath $Env:GITHUB_EVENT_PATH -Raw -Encoding 'UTF8NoBOM' |
81-
ConvertFrom-Json -AsHashtable:$AsHashtable.IsPresent -Depth 100 -NoEnumerate |
82-
Write-Output
79+
If (!(Test-Environment)) {
80+
Write-Error -Message 'Unable to get GitHub Actions resources!' -Category 'ResourceUnavailable'
8381
Return
8482
}
85-
Write-Error -Message 'Unable to get GitHub Actions resources!' -Category 'ResourceUnavailable'
83+
Get-Content -LiteralPath $Env:GITHUB_EVENT_PATH -Raw -Encoding 'UTF8NoBOM' |
84+
ConvertFrom-Json -AsHashtable:$AsHashtable.IsPresent -Depth 100 -NoEnumerate |
85+
Write-Output
8686
}
8787
Set-Alias -Name 'Get-Event' -Value 'Get-WebhookEventPayload' -Option 'ReadOnly' -Scope 'Local'
8888
Set-Alias -Name 'Get-Payload' -Value 'Get-WebhookEventPayload' -Option 'ReadOnly' -Scope 'Local'
@@ -100,11 +100,11 @@ Function Get-WorkflowRunUri {
100100
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_get-githubactionsworkflowrunuri#Get-GitHubActionsWorkflowRunUri')]
101101
[OutputType([String])]
102102
Param ()
103-
If (Test-Environment) {
104-
Write-Output -InputObject "$Env:GITHUB_SERVER_URL/$Env:GITHUB_REPOSITORY/actions/runs/$Env:GITHUB_RUN_ID"
103+
If (!(Test-Environment)) {
104+
Write-Error -Message 'Unable to get GitHub Actions resources!' -Category 'ResourceUnavailable'
105105
Return
106106
}
107-
Write-Error -Message 'Unable to get GitHub Actions resources!' -Category 'ResourceUnavailable'
107+
Write-Output -InputObject "$Env:GITHUB_SERVER_URL/$Env:GITHUB_REPOSITORY/actions/runs/$Env:GITHUB_RUN_ID"
108108
}
109109
Set-Alias -Name 'Get-WorkflowRunUrl' -Value 'Get-WorkflowRunUri' -Option 'ReadOnly' -Scope 'Local'
110110
<#

0 commit comments

Comments
 (0)