forked from actions/github-script
-
Notifications
You must be signed in to change notification settings - Fork 1
270 lines (261 loc) · 9.76 KB
/
integration.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
260
261
262
263
264
265
266
267
268
269
270
name: Integration
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test-return:
name: 'Integration test: return'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: output-set
uses: ./
with:
script: return core.getInput('input-value')
result-encoding: string
input-value: output
- run: |
echo "- Validating output is produced"
expected="output"
if [[ "${{steps.output-set.outputs.result}}" != "$expected" ]]; then
echo $'::error::\u274C' "Expected '$expected', got ${{steps.output-set.outputs.result}}"
exit 1
fi
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
test-relative-require:
name: 'Integration test: relative-path require'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: relative-require
uses: ./
with:
script: return require('./package.json').name
result-encoding: string
- run: |
echo "- Validating relative require output"
if [[ "${{steps.relative-require.outputs.result}}" != "github-script" ]]; then
echo $'::error::\u274C' "Expected '$expected', got ${{steps.relative-require.outputs.result}}"
exit 1
fi
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
test-npm-require:
name: 'Integration test: npm package require'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
restore-keys: ${{runner.os}}-npm-
- run: npm ci
- id: npm-require
uses: ./
with:
script: return require('@actions/core/package.json').name
result-encoding: string
- run: |
echo "- Validating npm require output"
expected="@actions/core"
if [[ "${{steps.npm-require.outputs.result}}" != "$expected" ]]; then
echo $'::error::\u274C' "Expected '$expected', got ${{steps.npm-require.outputs.result}}"
exit 1
fi
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
test-previews:
name: 'Integration test: previews option'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
restore-keys: ${{runner.os}}-npm-
- run: npm ci
- id: previews-default
name: Default previews not set
uses: ./
with:
script: |
const endpoint = github.request.endpoint
return endpoint({}).headers.accept
result-encoding: string
- id: previews-set-single
name: Previews set to a single value
uses: ./
with:
previews: foo
script: |
const endpoint = github.request.endpoint
return endpoint({}).headers.accept
result-encoding: string
- id: previews-set-multiple
name: Previews set to comma-separated list
uses: ./
with:
previews: foo,bar,baz
script: |
const endpoint = github.request.endpoint
return endpoint({}).headers.accept
result-encoding: string
- run: |
echo "- Validating previews default"
expected="application/vnd.github.v3+json"
if [[ "${{steps.previews-default.outputs.result}}" != $expected ]]; then
echo $'::error::\u274C' "Expected '$expected', got ${{steps.previews-default.outputs.result}}"
exit 1
fi
echo "- Validating previews set to a single value"
expected="application/vnd.github.foo-preview+json"
if [[ "${{steps.previews-set-single.outputs.result}}" != $expected ]]; then
echo $'::error::\u274C' "Expected '$expected', got ${{steps.previews-set-single.outputs.result}}"
exit 1
fi
echo "- Validating previews set to multiple values"
expected="application/vnd.github.foo-preview+json,application/vnd.github.bar-preview+json,application/vnd.github.baz-preview+json"
if [[ "${{steps.previews-set-multiple.outputs.result}}" != $expected ]]; then
echo $'::error::\u274C' "Expected '$expected', got ${{steps.previews-set-multiple.outputs.result}}"
exit 1
fi
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
test-user-agent:
name: 'Integration test: user-agent option'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
restore-keys: ${{runner.os}}-npm-
- run: npm ci
- id: user-agent-default
name: Default user-agent not set
uses: ./
with:
script: |
const endpoint = github.request.endpoint
return endpoint({}).headers['user-agent']
result-encoding: string
- id: user-agent-set
name: User-agent set
uses: ./
with:
user-agent: foobar
script: |
const endpoint = github.request.endpoint
return endpoint({}).headers['user-agent']
result-encoding: string
- id: user-agent-empty
name: User-agent set to an empty string
uses: ./
with:
user-agent: ''
script: |
const endpoint = github.request.endpoint
return endpoint({}).headers['user-agent']
result-encoding: string
- run: |
echo "- Validating user-agent default"
expected="actions/github-script octokit-core.js/"
if [[ "${{steps.user-agent-default.outputs.result}}" != "$expected"* ]]; then
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-default.outputs.result}}"
exit 1
fi
echo "- Validating user-agent set to a value"
expected="foobar octokit-core.js/"
if [[ "${{steps.user-agent-set.outputs.result}}" != "$expected"* ]]; then
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-set.outputs.result}}"
exit 1
fi
echo "- Validating user-agent set to an empty string"
expected="octokit-core.js/"
if [[ "${{steps.user-agent-empty.outputs.result}}" != "$expected"* ]]; then
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-empty.outputs.result}}"
exit 1
fi
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
test-debug:
strategy:
matrix:
environment: ['', 'debug-integration-test']
environment: ${{ matrix.environment }}
name: "Integration test: debug option (runner.debug mode ${{ matrix.environment && 'enabled' || 'disabled' }})"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
restore-keys: ${{runner.os}}-npm-
- run: npm ci
- id: debug-default
name: Default debug not set
uses: ./
with:
script: |
const log = github.log
return {
runnerDebugMode: core.isDebug(),
debug: log.debug === console.debug,
info: log.info === console.info
}
- id: debug-true
name: Debug set to true
uses: ./
with:
debug: true
script: |
const log = github.log
return {
runnerDebugMode: core.isDebug(),
debug: log.debug === console.debug,
info: log.info === console.info
}
- id: debug-false
name: Debug set to false
uses: ./
with:
debug: false
script: |
const log = github.log
return {
runnerDebugMode: core.isDebug(),
debug: log.debug === console.debug,
info: log.info === console.info
}
- id: evaluate-tests
name: Evaluate test outputs
env:
RDMODE: ${{ runner.debug == '1' }}
run: |
# tests table, pipe separated: label | output | expected
# leading and trailing spaces on any field are trimmed
tests=$(cat << 'TESTS'
Validating debug default |\
${{ steps.debug-default.outputs.result }} |\
{"runnerDebugMode":${{ env.RDMODE }},"debug":${{ env.RDMODE }},"info":${{ env.RDMODE }}}
Validating debug set to true |\
${{ steps.debug-true.outputs.result }} |\
{"runnerDebugMode":${{ env.RDMODE }},"debug":true,"info":true}
Validating debug set to false |\
${{ steps.debug-false.outputs.result }} |\
{"runnerDebugMode":${{ env.RDMODE }},"debug":false,"info":false}
TESTS
)
strim() { shopt -s extglob; lt="${1##+( )}"; echo "${lt%%+( )}"; }
while IFS='|' read label output expected; do
label="$(strim "$label")"; output="$(strim "$output")"; expected="$(strim "$expected")"
echo -n "- $label:"
if [[ "$output" != "$expected" ]]; then
echo $'\n::error::\u274C' "Expected '$expected', got '$output'"
exit 1
fi
echo $' \u2705'
done <<< "$tests"
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY