@@ -110,8 +110,16 @@ Set-Alias -Name 'Get-WorkflowRunUrl' -Value 'Get-WorkflowRunUri' -Option 'ReadOn
110
110
GitHub Actions - Test Environment
111
111
. DESCRIPTION
112
112
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.
113
117
. PARAMETER OpenIdConnect
114
118
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.
115
123
. PARAMETER Mandatory
116
124
The requirement whether is mandatory; If mandatory but not fulfill, will throw an error.
117
125
. PARAMETER MandatoryMessage
@@ -121,14 +129,18 @@ Function Test-Environment {
121
129
[CmdletBinding (HelpUri = ' https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_test-githubactionsenvironment#Test-GitHubActionsEnvironment' )]
122
130
[OutputType ([Boolean ])]
123
131
Param (
132
+ [Switch ]$Artifact ,
133
+ [Switch ]$Cache ,
124
134
[Alias (' Oidc' )][Switch ]$OpenIdConnect ,
135
+ [Alias (' Summary' )][Switch ]$StepSummary ,
136
+ [Switch ]$ToolCache ,
125
137
[Alias (' Force' , ' Forced' , ' Require' , ' Required' )][Switch ]$Mandatory ,
126
138
[Alias (' RequiredMessage' , ' RequireMessage' )][String ]$MandatoryMessage = ' This process require to execute inside the GitHub Actions environment!'
127
139
)
128
140
If (
129
141
$Env: CI -ine ' true' -or
130
- $Null -ieq $Env: GITHUB_ACTION_REPOSITORY -or
131
142
$Null -ieq $Env: GITHUB_ACTION -or
143
+ $Null -ieq $Env: GITHUB_ACTION_REPOSITORY -or
132
144
$Null -ieq $Env: GITHUB_ACTIONS -or
133
145
$Null -ieq $Env: GITHUB_ACTOR -or
134
146
$Null -ieq $Env: GITHUB_API_URL -or
@@ -141,24 +153,30 @@ Function Test-Environment {
141
153
$Null -ieq $Env: GITHUB_REF_NAME -or
142
154
$Null -ieq $Env: GITHUB_REF_PROTECTED -or
143
155
$Null -ieq $Env: GITHUB_REF_TYPE -or
144
- $Null -ieq $Env: GITHUB_REPOSITORY_OWNER -or
145
156
$Null -ieq $Env: GITHUB_REPOSITORY -or
146
- $Null -ieq $Env: GITHUB_RETENTION_DAYS -or
157
+ $Null -ieq $Env: GITHUB_REPOSITORY_OWNER -or
147
158
$Null -ieq $Env: GITHUB_RUN_ATTEMPT -or
148
159
$Null -ieq $Env: GITHUB_RUN_ID -or
149
160
$Null -ieq $Env: GITHUB_RUN_NUMBER -or
150
161
$Null -ieq $Env: GITHUB_SERVER_URL -or
151
162
$Null -ieq $Env: GITHUB_SHA -or
152
- $Null -ieq $Env: GITHUB_STEP_SUMMARY -or
153
163
$Null -ieq $Env: GITHUB_WORKFLOW -or
154
164
$Null -ieq $Env: GITHUB_WORKSPACE -or
155
165
$Null -ieq $Env: RUNNER_ARCH -or
156
166
$Null -ieq $Env: RUNNER_NAME -or
157
167
$Null -ieq $Env: RUNNER_OS -or
158
168
$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
160
176
($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 )
162
180
) {
163
181
If ($Mandatory ) {
164
182
Return (Write-GitHubActionsFail - Message $MandatoryMessage )
0 commit comments