Skip to content

Commit bafd544

Browse files
committed
20230323B
1 parent cceb951 commit bafd544

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

hugoalh.GitHubActionsToolkit/module/command-base.psm1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ Function Write-FileCommand {
8484
Else {
8585
Try {
8686
[String]$FileCommandPath = Get-Content -LiteralPath "Env:\$([WildcardPattern]::Escape($FileCommand.ToUpper()))" -ErrorAction 'Stop'
87-
If (![System.IO.Path]::IsPathFullyQualified($FileCommandPath)) {
88-
Throw
89-
}
9087
}
9188
Catch {
9289
Write-Error -Message "Unable to write the GitHub Actions file command: Environment path ``$($FileCommand.ToUpper())`` is not defined!" -Category 'ResourceUnavailable'
9390
Return
9491
}
92+
If (![System.IO.Path]::IsPathFullyQualified($FileCommandPath)) {
93+
Write-Error -Message "Unable to write the GitHub Actions file command: Environment path ``$($FileCommand.ToUpper())`` is not contain a valid file path!" -Category 'ResourceUnavailable'
94+
Return
95+
}
9596
}
9697
If ($Value -imatch '^.+$') {
9798
Add-Content -LiteralPath $FileCommandPath -Value "$Name=$Value" -Confirm:$False -Encoding 'UTF8NoBOM'

hugoalh.GitHubActionsToolkit/module/utility.psm1

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ Function Test-Environment {
139139
[Switch]$StepSummary# Deprecated, keep as legacy.
140140
)
141141
[Hashtable[]]$Conditions = @(
142-
@{ NeedTest = $True; Name = 'CI'; ExpectedValue = 'true' },
142+
@{ NeedTest = $True; Name = 'CI'; ExpectValue = 'true' },
143143
@{ NeedTest = $True; Name = 'GITHUB_ACTION'; },
144-
@{ NeedTest = $True; Name = 'GITHUB_ACTIONS'; ExpectedValue = 'true' },
144+
@{ NeedTest = $True; Name = 'GITHUB_ACTIONS'; ExpectValue = 'true' },
145145
@{ NeedTest = $True; Name = 'GITHUB_ACTOR'; },
146146
@{ NeedTest = $True; Name = 'GITHUB_ACTOR_ID'; },
147147
@{ NeedTest = $True; Name = 'GITHUB_API_URL'; },
@@ -183,21 +183,17 @@ Function Test-Environment {
183183
[Boolean]$Failed = $False
184184
ForEach ($Condition In $Conditions) {
185185
If ($Condition.NeedTest) {
186-
Try {
187-
If ($Null -ieq $Condition.ExpectedValue) {
188-
If ([String]::IsNullOrEmpty((Get-Content -LiteralPath "Env:\$($Condition.Name)" -ErrorAction 'SilentlyContinue'))) {
189-
Throw "Unable to get the GitHub Actions resources: Environment path ``$($Condition.Name)`` is not defined!"
190-
}
191-
}
192-
Else {
193-
If ((Get-Content -LiteralPath "Env:\$($Condition.Name)" -ErrorAction 'SilentlyContinue') -ine $Condition.ExpectedValue) {
194-
Throw "Unable to get the GitHub Actions resources: Environment path ``$($Condition.Name)`` is not defined or not equal to expected value!"
195-
}
186+
If ($Null -ieq $Condition.ExpectValue) {
187+
If ([String]::IsNullOrEmpty((Get-Content -LiteralPath "Env:\$($Condition.Name)" -ErrorAction 'SilentlyContinue'))) {
188+
$Failed = $True
189+
Write-Warning -Message "Unable to get the GitHub Actions resources: Environment path ``$($Condition.Name)`` is not defined!"
196190
}
197191
}
198-
Catch {
199-
$Failed = $True
200-
Write-Warning -Message $_
192+
Else {
193+
If ((Get-Content -LiteralPath "Env:\$($Condition.Name)" -ErrorAction 'SilentlyContinue') -ine $Condition.ExpectValue) {
194+
$Failed = $True
195+
Write-Warning -Message "Unable to get the GitHub Actions resources: Environment path ``$($Condition.Name)`` is not defined or not equal to expect value!"
196+
}
201197
}
202198
}
203199
}

0 commit comments

Comments
 (0)