Skip to content

Commit 802b5e1

Browse files
committed
20220620B
1 parent 280cbfb commit 802b5e1

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

hugoalh.GitHubActionsToolkit/module/step-summary.psm1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#Requires -PSEdition Core
22
#Requires -Version 7.2
3+
Import-Module -Name @(
4+
(Join-Path -Path $PSScriptRoot -ChildPath 'utility.psm1')
5+
) -Prefix 'GitHubActions' -Scope 'Local'
36
<#
47
.SYNOPSIS
58
GitHub Actions - Add Step Summary (Raw)
@@ -20,6 +23,9 @@ Function Add-StepSummary {
2023
[Switch]$NoNewLine
2124
)
2225
Begin {
26+
If (!(Test-GitHubActionsEnvironment -StepSummary)) {
27+
Return (Write-Error -Message 'Unable to get GitHub Actions step summary resources!' -Category 'ResourceUnavailable')
28+
}
2329
[String[]]$Result = @()
2430
}
2531
Process {
@@ -204,6 +210,9 @@ Function Get-StepSummary {
204210
[Parameter(ParameterSetName = 'Content')][Switch]$Raw,
205211
[Parameter(Mandatory = $True, ParameterSetName = 'Sizes')][Alias('Size')][Switch]$Sizes
206212
)
213+
If (!(Test-GitHubActionsEnvironment -StepSummary)) {
214+
Return (Write-Error -Message 'Unable to get GitHub Actions step summary resources!' -Category 'ResourceUnavailable')
215+
}
207216
Switch ($PSCmdlet.ParameterSetName) {
208217
'Content' {
209218
Return (Get-Content -LiteralPath $Env:GITHUB_STEP_SUMMARY -Raw:$Raw -Encoding 'UTF8NoBOM')
@@ -225,6 +234,9 @@ Function Remove-StepSummary {
225234
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_remove-githubactionsstepsummary#Remove-GitHubActionsStepSummary')]
226235
[OutputType([Void])]
227236
Param ()
237+
If (!(Test-GitHubActionsEnvironment -StepSummary)) {
238+
Return (Write-Error -Message 'Unable to get GitHub Actions step summary resources!' -Category 'ResourceUnavailable')
239+
}
228240
Return (Remove-Item -LiteralPath $Env:GITHUB_STEP_SUMMARY -Confirm:$False)
229241
}
230242
<#
@@ -247,6 +259,9 @@ Function Set-StepSummary {
247259
[Switch]$NoNewLine
248260
)
249261
Begin {
262+
If (!(Test-GitHubActionsEnvironment -StepSummary)) {
263+
Return (Write-Error -Message 'Unable to get GitHub Actions step summary resources!' -Category 'ResourceUnavailable')
264+
}
250265
[String[]]$Result = @()
251266
}
252267
Process {

hugoalh.GitHubActionsToolkit/module/utility.psm1

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,16 @@ Set-Alias -Name 'Get-WorkflowRunUrl' -Value 'Get-WorkflowRunUri' -Option 'ReadOn
110110
GitHub Actions - Test Environment
111111
.DESCRIPTION
112112
Test the current process whether is executing inside the GitHub Actions environment.
113+
.PARAMETER Artifact
114+
Also test the current process whether has GitHub Actions artifact resources.
115+
.PARAMETER Cache
116+
Also test the current process whether has GitHub Actions cache resources.
113117
.PARAMETER OpenIdConnect
114118
Also test the current process whether has GitHub Actions OpenID Connect (OIDC) resources.
119+
.PARAMETER StepSummary
120+
Also test the current process whether has GitHub Actions step summary resources.
121+
.PARAMETER ToolCache
122+
Also test the current process whether has GitHub Actions tool cache resources.
115123
.PARAMETER Mandatory
116124
The requirement whether is mandatory; If mandatory but not fulfill, will throw an error.
117125
.PARAMETER MandatoryMessage
@@ -121,14 +129,18 @@ Function Test-Environment {
121129
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_test-githubactionsenvironment#Test-GitHubActionsEnvironment')]
122130
[OutputType([Boolean])]
123131
Param (
132+
[Switch]$Artifact,
133+
[Switch]$Cache,
124134
[Alias('Oidc')][Switch]$OpenIdConnect,
135+
[Alias('Summary')][Switch]$StepSummary,
136+
[Switch]$ToolCache,
125137
[Alias('Force', 'Forced', 'Require', 'Required')][Switch]$Mandatory,
126138
[Alias('RequiredMessage', 'RequireMessage')][String]$MandatoryMessage = 'This process require to execute inside the GitHub Actions environment!'
127139
)
128140
If (
129141
$Env:CI -ine 'true' -or
130-
$Null -ieq $Env:GITHUB_ACTION_REPOSITORY -or
131142
$Null -ieq $Env:GITHUB_ACTION -or
143+
$Null -ieq $Env:GITHUB_ACTION_REPOSITORY -or
132144
$Null -ieq $Env:GITHUB_ACTIONS -or
133145
$Null -ieq $Env:GITHUB_ACTOR -or
134146
$Null -ieq $Env:GITHUB_API_URL -or
@@ -141,24 +153,30 @@ Function Test-Environment {
141153
$Null -ieq $Env:GITHUB_REF_NAME -or
142154
$Null -ieq $Env:GITHUB_REF_PROTECTED -or
143155
$Null -ieq $Env:GITHUB_REF_TYPE -or
144-
$Null -ieq $Env:GITHUB_REPOSITORY_OWNER -or
145156
$Null -ieq $Env:GITHUB_REPOSITORY -or
146-
$Null -ieq $Env:GITHUB_RETENTION_DAYS -or
157+
$Null -ieq $Env:GITHUB_REPOSITORY_OWNER -or
147158
$Null -ieq $Env:GITHUB_RUN_ATTEMPT -or
148159
$Null -ieq $Env:GITHUB_RUN_ID -or
149160
$Null -ieq $Env:GITHUB_RUN_NUMBER -or
150161
$Null -ieq $Env:GITHUB_SERVER_URL -or
151162
$Null -ieq $Env:GITHUB_SHA -or
152-
$Null -ieq $Env:GITHUB_STEP_SUMMARY -or
153163
$Null -ieq $Env:GITHUB_WORKFLOW -or
154164
$Null -ieq $Env:GITHUB_WORKSPACE -or
155165
$Null -ieq $Env:RUNNER_ARCH -or
156166
$Null -ieq $Env:RUNNER_NAME -or
157167
$Null -ieq $Env:RUNNER_OS -or
158168
$Null -ieq $Env:RUNNER_TEMP -or
159-
$Null -ieq $Env:RUNNER_TOOL_CACHE -or
169+
((
170+
$Artifact -or
171+
$Cache
172+
) -and $Null -ieq $Env:ACTIONS_RUNTIME_TOKEN) -or
173+
($Artifact -and $Null -ieq $Env:ACTIONS_RUNTIME_URL) -or
174+
($Artifact -and $Null -ieq $Env:GITHUB_RETENTION_DAYS) -or
175+
($Cache -and $Null -ieq $Env:ACTIONS_CACHE_URL) -or
160176
($OpenIdConnect -and $Null -ieq $Env:ACTIONS_ID_TOKEN_REQUEST_TOKEN) -or
161-
($OpenIdConnect -and $Null -ieq $Env:ACTIONS_ID_TOKEN_REQUEST_URL)
177+
($OpenIdConnect -and $Null -ieq $Env:ACTIONS_ID_TOKEN_REQUEST_URL) -or
178+
($StepSummary -and $Null -ieq $Env:GITHUB_STEP_SUMMARY) -or
179+
($ToolCache -and $Null -ieq $Env:RUNNER_TOOL_CACHE)
162180
) {
163181
If ($Mandatory) {
164182
Return (Write-GitHubActionsFail -Message $MandatoryMessage)

0 commit comments

Comments
 (0)