-
Notifications
You must be signed in to change notification settings - Fork 1
301 lines (260 loc) · 10 KB
/
test.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
name: 'Continuous Testing'
on:
push:
pull_request: # Need to have coverallsapp action comment in the pull_request
permissions:
contents: read
jobs:
test-script:
name: Script Tests
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
contents: write
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Install Test Tool
id: install-bats
run: pip install -r ./test/requirements.txt
- name: Install Dependencies
id: install-jinja2
run: pip install -r ./requirements.txt
- name: Test
id: script-test
# Add option `-html=report.html --self-contained-html` to pytest to get html output if need on test
# Add `coverage html` command to get html output on coverage if needed
run: |
pytest --cov --junitxml report.xml
coverage xml
- name: Publish Coverage Report to Coveralls.io
id: coverage
if: always() && hashFiles('coverage.xml') != ''
uses: coverallsapp/github-action@v2
- name: Code Coverage Report
uses: irongut/[email protected]
if: always() && hashFiles('coverage.xml') != ''
with:
filename: coverage.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: true
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'
# As irongut/CodeCoverageSummary does not support file by file mode, add it
# See https://github.com/irongut/CodeCoverageSummary/issues/236
- name: Write Coverage to Job Summary
run: |
cat code-coverage-results.md > my-code-coverage-results.md
echo "\`\`\`" >> my-code-coverage-results.md
coverage report >> my-code-coverage-results.md
echo "\`\`\`" >> my-code-coverage-results.md
cat my-code-coverage-results.md >> $GITHUB_STEP_SUMMARY
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: my-code-coverage-results.md
- name: Testspace client install & config
id: testspace_init
if: always() && hashFiles('report.xml') != ''
uses: testspace-com/setup-testspace@v1
with:
domain: ${{github.repository_owner}}
- name: Testspace push test content
if: always() && (steps.testspace_init.outcome == 'success')
run: |
output=$(testspace "[Unit Tests]report.xml" --link=coveralls)
REGEX="(https://[a-z0-9]+.testspace.com/spaces/[0-9]+/result_sets/[0-9]+)"
[[ $output =~ $REGEX ]]
result_set_link="${BASH_REMATCH[1]}"
echo "[TestSpace Test Result set]($result_set_link)" >> $GITHUB_STEP_SUMMARY
- name: Publish Test Results in GitHub
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: report.xml
check_name: 'Unit Test Results'
test-action-matrix:
name: Test With Matrix
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
strategy:
matrix:
test: [1]
env:
VAR_TEST1_VALUE: mytest
VAR_TEST2_VALUE: isfunny
FILE_KEY_1_VALUE: myfile
FILE_KEY_2_VALUE: isused
TEST: integ
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Install bats
id: install-bats
run: ./test/install_bats.sh
- name: Prepare Test File
run: |
echo "exemple:" > test-data.yml
echo " FILE_KEY_1: ${{ env.FILE_KEY_1_VALUE }}" >> test-data.yml
echo " FILE_KEY_2: ${{ env.FILE_KEY_2_VALUE }}" >> test-data.yml
echo "{{ github.repository }}" > all_test.j2
echo "${{ github.repository }}" > expected
echo "{{ github.repository_owner }}" >> all_test.j2
echo "${{ github.repository_owner }}" >> expected
echo "{{ github.event.repository.license.key }}" >> all_test.j2
echo "${{ github.event.repository.license.key }}" >> expected
echo "{{ job.status }}" >> all_test.j2
echo "${{ job.status }}" >> expected
echo "{{ runner.os }}" >> all_test.j2
echo "${{ runner.os }}" >> expected
echo "{{ strategy.job_index }}" >> all_test.j2
echo "${{ strategy.job-index }}" >> expected
echo "{{ matrix.test }}" >> all_test.j2
echo "${{ matrix.test }}" >> expected
echo "{{ environ('TEST') }}" >> all_test.j2
echo "${{ env.TEST }}" >> expected
echo "{{ TEST1 }}" >> all_test.j2
echo "${{ env.VAR_TEST1_VALUE }}" >> expected
echo "{{ TEST2 }}" >> all_test.j2
echo "${{ env.VAR_TEST2_VALUE }}" >> expected
echo "{{ env.TEST }}" >> all_test.j2
echo "${{ env.TEST }}" >> expected
echo "{{ exemple.FILE_KEY_1 }}" >> all_test.j2
echo "${{ env.FILE_KEY_1_VALUE }}" >> expected
echo "{{ exemple.FILE_KEY_2 }}" >> all_test.j2
echo "${{ env.FILE_KEY_2_VALUE }}" >> expected
echo "{{ url.URL_KEY_1 }}" >> all_test.j2
echo "from_url" >> expected
echo "{{ url.URL_KEY_2 }}" >> all_test.j2
echo "it_is_working" >> expected
echo "" >> all_test.j2
cat all_test.j2
cat expected
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Test Local Action
id: test-action
uses: ./
with:
#keep_template: true
data_file: test-data.yml
data_format: yaml
data_url: https://raw.githubusercontent.com/${{ github.repository }}/refs/heads/${{ steps.extract_branch.outputs.branch }}/test/url_data.yml
data_url_format: yaml
variables: |
TEST1=${{ env.VAR_TEST1_VALUE }}
TEST2=${{ env.VAR_TEST2_VALUE }}
- name: Check If Template file is managed
id: test-action-result
run: |
./test/bats/bin/bats --report-formatter junit test/test_action.bats
- name: Testspace client install & config
id: testspace_init
if: always() && hashFiles('report.xml') != ''
uses: testspace-com/setup-testspace@v1
with:
domain: ${{github.repository_owner}}
- name: Testspace push test content
if: always() && (steps.test-action-result.outcome == 'success')
run: |
testspace "[Integ Tests/With Matrix]report.xml"
- name: Publish Test Results in GitHub
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: report.xml
check_name: 'Integ Test Results'
test-action-no-matrix:
name: Test Without Matrix
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
env:
VAR_TEST1_VALUE: mytest
VAR_TEST2_VALUE: isfunny
FILE_KEY_1_VALUE: myfile
FILE_KEY_2_VALUE: isused
TEST: integ
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Install bats
id: install-bats
run: ./test/install_bats.sh
- name: Prepare Test File
run: |
echo "exemple:" > test-data.yml
echo " FILE_KEY_1: ${{ env.FILE_KEY_1_VALUE }}" >> test-data.yml
echo " FILE_KEY_2: ${{ env.FILE_KEY_2_VALUE }}" >> test-data.yml
echo "{{ github.repository }}" > all_test.j2
echo "${{ github.repository }}" > expected
echo "{{ github.repository_owner }}" >> all_test.j2
echo "${{ github.repository_owner }}" >> expected
echo "{{ github.event.repository.license.key }}" >> all_test.j2
echo "${{ github.event.repository.license.key }}" >> expected
echo "{{ job.status }}" >> all_test.j2
echo "${{ job.status }}" >> expected
echo "{{ runner.os }}" >> all_test.j2
echo "${{ runner.os }}" >> expected
echo "{{ strategy.job_index }}" >> all_test.j2
echo "${{ strategy.job-index }}" >> expected
echo "{{ environ('TEST') }}" >> all_test.j2
echo "${{ env.TEST }}" >> expected
echo "{{ TEST1 }}" >> all_test.j2
echo "${{ env.VAR_TEST1_VALUE }}" >> expected
echo "{{ TEST2 }}" >> all_test.j2
echo "${{ env.VAR_TEST2_VALUE }}" >> expected
echo "{{ env.TEST }}" >> all_test.j2
echo "${{ env.TEST }}" >> expected
echo "{{ exemple.FILE_KEY_1 }}" >> all_test.j2
echo "${{ env.FILE_KEY_1_VALUE }}" >> expected
echo "{{ exemple.FILE_KEY_2 }}" >> all_test.j2
echo "${{ env.FILE_KEY_2_VALUE }}" >> expected
echo "" >> all_test.j2
cat all_test.j2
cat expected
- name: Test Local Action
id: test-action
uses: ./
with:
#keep_template: true
data_file: test-data.yml
data_format: yaml
variables: |
TEST1=${{ env.VAR_TEST1_VALUE }}
TEST2=${{ env.VAR_TEST2_VALUE }}
- name: Check If Template file is managed
id: test-action-result
run: |
./test/bats/bin/bats --report-formatter junit test/test_action.bats
- name: Testspace client install & config
id: testspace_init
if: always() && hashFiles('report.xml') != ''
uses: testspace-com/setup-testspace@v1
with:
domain: ${{github.repository_owner}}
- name: Testspace push test content
if: always() && (steps.test-action-result.outcome == 'success')
run: |
testspace "[Integ Tests/Without Matrix]report.xml"
- name: Publish Test Results in GitHub
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: report.xml
check_name: 'Integ Test Results'