forked from Amadevus/pwsh-script
-
Notifications
You must be signed in to change notification settings - Fork 0
259 lines (245 loc) · 8.68 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: CI
on:
push:
pull_request:
schedule:
- cron: "0 10 * * 1" # At 10:00 on Monday.
defaults:
run:
shell: pwsh
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Test with Pester
run: ./test.ps1
- name: Invoke action
env:
TEMP: ${{ runner.temp }}
run: |
$env:PWSH_SCRIPT_ACTION_TEXT = 'Write-Host "ok"; return "value"'
$output = pwsh -file ./action.ps1
if ($LASTEXITCODE -ne 0) {
$output | Write-Error
throw 'pwsh failed'
}
$diff = Compare-Object @('ok','::set-output name=result::value') $output -CaseSensitive
if ($diff) {
$diff | Format-Table | Write-Host
throw 'Output differed from the expected'
}
build-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build module docs
uses: ./
with:
script: |
./build-docs.ps1 -Clean
git status --porcelain || (throw "Documentation isn't up to date. Run 'build-docs.ps1' and commit changes.")
self-testing:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
# return string result
- name: Test that returned result string is not json serialized (act)
uses: ./
id: test-result-string
with:
script: return "testmsg"
- name: Test that returned result string is not json serialized (assert)
run: |
$result = '${{ steps.test-result-string.outputs.result }}'
if ($result -cne 'testmsg') {
Write-Host "::error::Return string test failed: invalid result.`n$result"
exit 1
}
# return object result
- name: Test that returned result object is json serialized (act)
uses: ./
id: test-result-object
with:
script: return [ordered]@{ a = 1; b = "c" }
- name: Test that returned result object is json serialized (assert)
run: |
$result = '${{ steps.test-result-object.outputs.result }}'
if ($result -cne '{"a":1,"b":"c"}') {
Write-Host "::error::Return object test failed: invalid result.`n$result"
exit 1
}
# throw
- name: Test that throwing causes action to fail (act)
uses: ./
id: test-throwing-fails-action
continue-on-error: true
with:
script: 'throw "test error message"'
- name: Test that throwing causes action to fail (assert)
run: |
$outcome = '${{ steps.test-throwing-fails-action.outcome }}'
if ($outcome -cne 'failure') {
Write-Host "::error::Throwing test failed: invalid outcome.`n$outcome"
exit 1
}
$errMsg = '${{ steps.test-throwing-fails-action.outputs.error }}'
if ($errMsg -cne 'test error message') {
Write-Host "::error::Throwing test failed: invalid error output.`n$errMsg"
exit 1
}
# check access to contexts
- name: Test that workflow contexts are available
uses: ./
with:
script: |
function Test-Value ($expression, $expected) {
$actual = Invoke-Expression $expression
if ($actual -cne $expected) {
throw "Failed assertion:'$expression' evaluated to '$actual', expected '$expected'."
}
}
Test-Value '$github.token' '${{ github.token }}'
Test-Value '$job.status' '${{ job.status }}'
Test-Value '$runner.os' '${{ runner.os }}'
Test-Value '$strategy."fail-fast"' ([bool]'${{ strategy.fail-fast }}')
Test-Value '$matrix.os' '${{ matrix.os }}'
# Get-ActionInput
# Get-ActionInput isn't really testable in a script
- name: Get-ActionInput test
if: "false"
uses: ./
with:
custom-input: "test"
script: |
$script = Get-ActionInput script
if ($script -notlike '$script = Get-ActionInput script*') {
throw "Get-ActionInput for 'script' failed.`n$script"
}
$custom = Get-ActionInput custom-input
if ($custom -cne 'test') {
throw "Get-ActionInput for 'custom-input' failed.`n$custom"
}
# Set-ActionOutput
- name: Set-ActionOutput test (act)
id: Set-ActionOutput
run: |
Import-Module ./lib/GitHubActionsCore -Force
Set-ActionOutput testout testval
- name: Set-ActionOutput test (assert)
uses: ./
with:
script: |
$output = '${{ steps.Set-ActionOutput.outputs.testout }}'
if ($output -cne 'testval') {
throw "Set-ActionOutput failed.`n$output"
}
# Add-ActionPath
- name: Add-ActionPath test (act)
uses: ./
with:
script: Add-ActionPath 'testing add-path'
- name: Add-ActionPath test (assert)
uses: ./
with:
script: |
if ($env:PATH -notlike "*testing add-path$([System.IO.Path]::PathSeparator)*") {
throw "Add-ActionPath failed.`n$env:PATH"
}
# Add-ActionSecret
- name: Add-ActionSecret test (manual check whether host-sent value is masked)
uses: ./
with:
script: |
$secret = [System.Guid]::NewGuid()
Add-ActionSecret $secret
Write-Host $secret
# Set-ActionVariable
- name: Set-ActionVariable test (act and first assert)
uses: ./
with:
script: |
$props = [ordered]@{ a = 1; b = 'c' }
Set-ActionVariable testvar $props
if ($env:testvar -cne '{"a":1,"b":"c"}') {
throw "Set-ActionVariable failed.`n$env:testvar"
}
- name: Set-ActionVariable test (second assert)
uses: ./
with:
script: |
if ($env:testvar -cne '{"a":1,"b":"c"}') {
throw "Set-ActionVariable failed.`n$env:testvar"
}
# Set-ActionCommandEcho
- name: Set-ActionCommandEcho test (manual check whether commands are shown in log)
uses: ./
with:
script: |
Set-ActionCommandEcho $false
Set-ActionOutput echo-off offval # shouldn't show up in logs
Set-ActionCommandEcho $true
Set-ActionOutput echo-on onval # should show up in logs
Set-ActionCommandEcho $false
# Set-ActionFailed
- name: Set-ActionFailed test (act)
uses: ./
id: Set-ActionFailed
continue-on-error: true
with:
script: |
Set-ActionFailed "test error"
- name: Set-ActionFailed test (assert)
uses: ./
with:
script: |
$result = '${{ steps.Set-ActionFailed.outcome }}'
if ($result -cne 'failure') {
throw "Set-ActionFailed failed.`n$result"
}
# Get-ActionIsDebug
- name: Get-ActionIsDebug test
uses: ./
with:
script: |
$result = Get-ActionIsDebug
if ($result -ne ($env:RUNNER_DEBUG -eq '1')) {
throw "Get-ActionIsDebug failed.`n$result"
}
# Invoke-ActionNoCommandsBlock
- name: Invoke-ActionNoCommandsBlock test (act)
id: Invoke-ActionNoCommandsBlock
run: |
Import-Module ./lib/GitHubActionsCore -Force
Invoke-ActionNoCommandsBlock -GenerateToken {
Set-ActionOutput testout testval
}
- name: Invoke-ActionNoCommandsBlock test (assert)
uses: ./
with:
script: |
$result = '${{ steps.Invoke-ActionNoCommandsBlock.outputs.testout }}'
if ($result) {
throw "Invoke-ActionNoCommandsBlock failed.`n$result"
}
# Write-Action -Debug, -Info, -Warning, -Error and Grouping are not testable in any sensible manner
- name: Write-Action... and Group... sample runs (manual check)
uses: ./
continue-on-error: true # since we're printing errors
with:
script: |
Enter-ActionOutputGroup 'testing log levels'
Write-ActionDebug "dbg msg"
Write-ActionInfo "info msg"
Write-ActionWarning "wrn msg"
Write-ActionError "err msg"
Exit-ActionOutputGroup
Invoke-ActionGroup "Invoke-ActionGroup group" {
Write-Host "output within Invoke-ActionGroup"
}