Skip to content

Commit cceb951

Browse files
committed
20230323A
1 parent d36e8c4 commit cceb951

File tree

5 files changed

+26
-54
lines changed

5 files changed

+26
-54
lines changed

hugoalh.GitHubActionsToolkit/module/command-base.psm1

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#Requires -PSEdition Core -Version 7.2
22
Import-Module -Name (
33
@(
4-
'internal\new-random-token',
5-
'internal\test-environment-path'
4+
'internal\new-random-token'
65
) |
76
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath "$_.psm1" }
87
) -Prefix 'GitHubActions' -Scope 'Local'
@@ -79,18 +78,18 @@ Function Write-FileCommand {
7978
[Parameter(Mandatory = $True, Position = 2, ValueFromPipelineByPropertyName = $True)][String]$Value
8079
)
8180
Process {
82-
If (<# LEGACY #>Test-GitHubActionsEnvironmentPath -InputObject $FileCommand) {
81+
If (<# LEGACY #>[System.IO.Path]::IsPathFullyQualified($FileCommand)) {
8382
[String]$FileCommandPath = $FileCommand
8483
}
8584
Else {
8685
Try {
8786
[String]$FileCommandPath = Get-Content -LiteralPath "Env:\$([WildcardPattern]::Escape($FileCommand.ToUpper()))" -ErrorAction 'Stop'
88-
If (!(Test-GitHubActionsEnvironmentPath -InputObject $FileCommandPath)) {
87+
If (![System.IO.Path]::IsPathFullyQualified($FileCommandPath)) {
8988
Throw
9089
}
9190
}
9291
Catch {
93-
Write-Error -Message "Unable to write the GitHub Actions file command: Environment path ``$($FileCommand.ToUpper())`` is undefined!" -Category 'ResourceUnavailable'
92+
Write-Error -Message "Unable to write the GitHub Actions file command: Environment path ``$($FileCommand.ToUpper())`` is not defined!" -Category 'ResourceUnavailable'
9493
Return
9594
}
9695
}

hugoalh.GitHubActionsToolkit/module/environment-variable.psm1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ Function Add-PATH {
4545
Add-Content -LiteralPath $Env:PATH -Value "$([System.IO.Path]::PathSeparator)$Item" -Confirm:$False -NoNewLine
4646
}
4747
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Subsequent) -ieq [GitHubActionsEnvironmentVariableScopes]::Subsequent) {
48-
Add-Content -LiteralPath $Env:GITHUB_PATH -Value $Item -Confirm:$False -Encoding 'UTF8NoBOM'
48+
If ([System.IO.Path]::IsPathFullyQualified($Env:GITHUB_PATH)) {
49+
Add-Content -LiteralPath $Env:GITHUB_PATH -Value $Item -Confirm:$False -Encoding 'UTF8NoBOM'
50+
}
51+
Else {
52+
Write-Error -Message 'Unable to write the GitHub Actions path: Environment path `GITHUB_PATH` is not defined!' -Category 'ResourceUnavailable'
53+
}
4954
}
5055
}
5156
}

hugoalh.GitHubActionsToolkit/module/internal/test-environment-path.psm1

Lines changed: 0 additions & 25 deletions
This file was deleted.

hugoalh.GitHubActionsToolkit/module/step-summary.psm1

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
#Requires -PSEdition Core -Version 7.2
2-
Import-Module -Name (
3-
@(
4-
'internal\test-environment-path'
5-
) |
6-
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath "$_.psm1" }
7-
) -Prefix 'GitHubActions' -Scope 'Local'
82
<#
93
.SYNOPSIS
104
GitHub Actions - Add Step Summary (Raw)
@@ -29,8 +23,8 @@ Function Add-StepSummary {
2923
[Parameter(ValueFromPipelineByPropertyName = $True)][Switch]$NoNewLine
3024
)
3125
Process {
32-
If (!(Test-GitHubActionsEnvironmentPath -InputObject $Env:GITHUB_STEP_SUMMARY)) {
33-
Write-Error -Message 'Unable to write the GitHub Actions step summary: Environment path `GITHUB_STEP_SUMMARY` is undefined!' -Category 'ResourceUnavailable'
26+
If (![System.IO.Path]::IsPathFullyQualified($Env:GITHUB_STEP_SUMMARY)) {
27+
Write-Error -Message 'Unable to write the GitHub Actions step summary: Environment path `GITHUB_STEP_SUMMARY` is not defined!' -Category 'ResourceUnavailable'
3428
Return
3529
}
3630
If ($Value.Count -igt 0) {
@@ -227,8 +221,8 @@ Function Get-StepSummary {
227221
[Parameter(ParameterSetName = 'Content')][Switch]$Raw,
228222
[Parameter(Mandatory = $True, ParameterSetName = 'Sizes')][Alias('Size')][Switch]$Sizes
229223
)
230-
If (!(Test-GitHubActionsEnvironmentPath -InputObject $Env:GITHUB_STEP_SUMMARY)) {
231-
Write-Error -Message 'Unable to get the GitHub Actions step summary: Environment path `GITHUB_STEP_SUMMARY` is undefined!' -Category 'ResourceUnavailable'
224+
If (![System.IO.Path]::IsPathFullyQualified($Env:GITHUB_STEP_SUMMARY)) {
225+
Write-Error -Message 'Unable to get the GitHub Actions step summary: Environment path `GITHUB_STEP_SUMMARY` is not defined!' -Category 'ResourceUnavailable'
232226
Return
233227
}
234228
Switch ($PSCmdlet.ParameterSetName) {
@@ -257,8 +251,8 @@ Function Remove-StepSummary {
257251
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_removegithubactionsstepsummary')]
258252
[OutputType([Void])]
259253
Param ()
260-
If (!(Test-GitHubActionsEnvironmentPath -InputObject $Env:GITHUB_STEP_SUMMARY)) {
261-
Write-Error -Message 'Unable to remove the GitHub Actions step summary: Environment path `GITHUB_STEP_SUMMARY` is undefined!' -Category 'ResourceUnavailable'
254+
If (![System.IO.Path]::IsPathFullyQualified($Env:GITHUB_STEP_SUMMARY)) {
255+
Write-Error -Message 'Unable to remove the GitHub Actions step summary: Environment path `GITHUB_STEP_SUMMARY` is not defined!' -Category 'ResourceUnavailable'
262256
Return
263257
}
264258
Remove-Item -LiteralPath $Env:GITHUB_STEP_SUMMARY -Confirm:$False -ErrorAction 'Continue'
@@ -296,8 +290,8 @@ Function Set-StepSummary {
296290
}
297291
}
298292
End {
299-
If (!(Test-GitHubActionsEnvironmentPath -InputObject $Env:GITHUB_STEP_SUMMARY)) {
300-
Write-Error -Message 'Unable to write the GitHub Actions step summary: Environment path `GITHUB_STEP_SUMMARY` is undefined!' -Category 'ResourceUnavailable'
293+
If (![System.IO.Path]::IsPathFullyQualified($Env:GITHUB_STEP_SUMMARY)) {
294+
Write-Error -Message 'Unable to write the GitHub Actions step summary: Environment path `GITHUB_STEP_SUMMARY` is not defined!' -Category 'ResourceUnavailable'
301295
Return
302296
}
303297
If ($Result.Count -igt 0) {

hugoalh.GitHubActionsToolkit/module/utility.psm1

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#Requires -PSEdition Core -Version 7.2
22
Import-Module -Name (
33
@(
4-
'command-base',
5-
'log'
4+
'command-base'
65
) |
76
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath "$_.psm1" }
87
) -Prefix 'GitHubActions' -Scope 'Local'
@@ -74,7 +73,7 @@ Function Get-WebhookEventPayload {
7473
[Alias('ToHashtable')][Switch]$AsHashtable
7574
)
7675
If ([String]::IsNullOrEmpty($Env:GITHUB_EVENT_PATH)) {
77-
Write-Error -Message 'Unable to read the GitHub Actions webhook event payload: Environment path `GITHUB_EVENT_PATH` is undefined!' -Category 'ResourceUnavailable'
76+
Write-Error -Message 'Unable to get the GitHub Actions webhook event payload: Environment path `GITHUB_EVENT_PATH` is not defined!' -Category 'ResourceUnavailable'
7877
Return
7978
}
8079
Get-Content -LiteralPath $Env:GITHUB_EVENT_PATH -Raw -Encoding 'UTF8NoBOM' |
@@ -99,7 +98,7 @@ Function Get-WorkflowRunUri {
9998
Param ()
10099
ForEach ($EnvironmentPath In @('GITHUB_SERVER_URL', 'GITHUB_REPOSITORY', 'GITHUB_RUN_ID')) {
101100
If ([String]::IsNullOrEmpty((Get-Content -LiteralPath "Env:\$EnvironmentPath"))) {
102-
Write-Error -Message "Unable to get the GitHub Actions workflow run URI: Environment path ``$EnvironmentPath`` is undefined!" -Category 'ResourceUnavailable'
101+
Write-Error -Message "Unable to get the GitHub Actions workflow run URI: Environment path ``$EnvironmentPath`` is not defined!" -Category 'ResourceUnavailable'
103102
Return
104103
}
105104
}
@@ -187,25 +186,25 @@ Function Test-Environment {
187186
Try {
188187
If ($Null -ieq $Condition.ExpectedValue) {
189188
If ([String]::IsNullOrEmpty((Get-Content -LiteralPath "Env:\$($Condition.Name)" -ErrorAction 'SilentlyContinue'))) {
190-
Throw
189+
Throw "Unable to get the GitHub Actions resources: Environment path ``$($Condition.Name)`` is not defined!"
191190
}
192191
}
193192
Else {
194193
If ((Get-Content -LiteralPath "Env:\$($Condition.Name)" -ErrorAction 'SilentlyContinue') -ine $Condition.ExpectedValue) {
195-
Throw
194+
Throw "Unable to get the GitHub Actions resources: Environment path ``$($Condition.Name)`` is not defined or not equal to expected value!"
196195
}
197196
}
198197
}
199198
Catch {
200199
$Failed = $True
201-
Write-Warning -Message "Unable to get the GitHub Actions resources: Environment path ``$($Condition.Name)`` is undefined or not equal to expected value!"
200+
Write-Warning -Message $_
202201
}
203202
}
204203
}
205204
If ($Failed) {
206205
If ($Mandatory.IsPresent) {
207-
Write-GitHubActionsFail -Message $MandatoryMessage
208-
Throw
206+
Write-Error -Message $MandatoryMessage -Category 'InvalidOperation' -ErrorAction 'Stop'
207+
Exit 1
209208
}
210209
Write-Output -InputObject $False
211210
Return

0 commit comments

Comments
 (0)