-
Notifications
You must be signed in to change notification settings - Fork 0
478 lines (403 loc) · 22.6 KB
/
build-and-review-pr.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
name: Build and Review PR
run-name: 'Build and Review PR #${{ github.event.pull_request.number }}'
on:
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
#
# This workflow uses the pull_request trigger which prevents write permissions on the
# GH_TOKEN and secrets access from public forks. This should remain as a pull_request
# trigger to minimize the access public forks have in the repository. The reduced
# permissions are adequate but do mean that re-compiles and readme changes will have to be
# made manually by the PR author. These auto-updates could be done by this workflow
# for branches but in order to re-trigger a PR build (which is needed for status checks),
# we would make the commits with a different user and their PAT. To minimize exposure
# and complication we will request those changes be manually made by the PR author.
pull_request:
types: [opened, synchronize, reopened]
# paths:
# Do not include specific paths here. We always want this build to run and produce a
# status check which are branch protection rules can use. If this is skipped because of
# path filtering, a status check will not be created and we won't be able to merge the PR
# without disabling that requirement. If we have a status check that is always produced,
# we can also use that to require all branches be up to date before they are merged.
jobs:
build-and-review-pr:
# This reusable workflow will check to see if an action's source code has changed based on
# whether the PR includes files that match the files-with-code arg or are in one of the
# dirs-with-code directories. If there are source code changes, this reusable workflow
# will then run the action's build (if one was provided) and update the README.md with the
# the latest version of the action. If those two steps result in any changes that need to
# be committed, the workflow will fail because the PR needs some updates. Instructions for
# updating the PR will be available in the build log, the workflow summary and as a PR
# comment if the PR came from a branch (not a fork).
# This workflow assumes:
# - The main README.md is at the root of the repo
# - The README contains a contribution guidelines and usage examples section
uses: im-open/.github/.github/workflows/reusable-build-and-review-pr.yml@v1
with:
action-name: ${{ github.repository }}
default-branch: main
readme-name: 'README.md'
# The id of the contribution guidelines section of the README.md
readme-contribution-id: '#contributing'
# The id of the usage examples section of the README.md
readme-examples-id: '#usage-examples'
# The files that contain source code for the action. Only files that affect the action's execution
# should be included like action.yml or package.json. Do not include files like README.md or .gitignore.
# Files do not need to be explicitly provided here if they fall under one of the dirs in dirs-with-code.
# ** This value must match the same files-with-code argument specified in increment-version-on-merge.yml.
files-with-code: 'action.yml,package.json,package-lock.json'
# The directories that contain source code for the action. Only dirs with files that affect the action's
# execution should be included like src or dist. Do not include dirs like .github or node_modules.
# ** This value must match the same dirs-with-code argument specified in increment-version-on-merge.yml.
dirs-with-code: 'src,dist'
# The npm script to run to build the action. This is typically 'npm run build' if the
# action needs to be compiled. For composite-run-steps actions this is typically empty.
build-command: 'npm run build'
unit-tests:
runs-on: ubuntu-latest
env:
# These env vars are reused and set for each test scenario
REPORTS_INPUT: ''
TARGETDIR_INPUT: ''
ERROR_REASON: ''
GENERATED_FILE: ''
FILE_WITH_SUBSTRING: ''
steps:
- name: '-------------------------------------------------------------------------------------------------------------'
run: echo ""
- name: ' SETUP '
run: echo ""
- name: Setup - Checkout the action
uses: actions/checkout@v4
- name: Setup - Create the test-results directory
run: mkdir -p ./test-results
- name: '-------------------------------------------------------------------------------------------------------------'
run: echo ""
- name: ' TEST 1 - INVALID VERBOSITY INPUT '
run: echo ""
- name: Setup - Set variables for Test 1
if: always()
run: |
errorReason="Invalid verbosity"
reports="./test/input-files/valid/*.xml"
targetDir="./test-results/invalid-verbosity"
generatedFile=""
fileWithSubstring=""
echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV"
echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV"
echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV"
echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV"
echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV"
- name: 1a - When code-coverage-report-generator is called with an invalid 'verbosity' input
id: invalid-verbosity
if: always()
continue-on-error: true # This is needed because we expect the step to fail but we need it to "pass" in order for the test job to succeed.
uses: ./
with:
reports: '${{ env.REPORTS_INPUT }}'
targetdir: '${{ env.TARGETDIR_INPUT }}'
reporttypes: 'MarkdownSummary'
verbosity: 'InVaLId_VeRbOsItY'
- name: 1b - Then the action outcome should be failure
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.invalid-verbosity.outcome }}"
- name: 1c - And the 'error-reason' output should be '${{ env.ERROR_REASON }}'
if: always()
run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON }}" --actual "${{ steps.invalid-verbosity.outputs.error-reason }}"
- name: 1d - And the target directory should not exist
if: always()
run: ./test/assert-dir-does-not-exist.sh --dir "${{ env.TARGETDIR_INPUT }}"
- name: '-------------------------------------------------------------------------------------------------------------'
run: echo ""
- name: ' TEST 2 - INVALID REPORTTYPES INPUT '
run: echo ""
- name: Setup - Set variables for Test 2
if: always()
run: |
errorReason="Invalid report type"
reports="./test/input-files/valid/*.xml"
targetDir="./test-results/invalid-reporttypes"
generatedFile=""
fileWithSubstring=""
echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV"
echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV"
echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV"
echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV"
echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV"
- name: 2a - When code-coverage-report-generator is called with an invalid 'reporttypes' input
id: invalid-reporttypes
if: always()
continue-on-error: true # This is needed because we expect the step to fail but we need it to "pass" in order for the test job to succeed.
uses: ./
with:
reports: '${{ env.REPORTS_INPUT }}'
targetdir: '${{ env.TARGETDIR_INPUT }}'
reporttypes: 'BarkdownSummary'
verbosity: 'Info'
- name: 2b - Then the action outcome should be failure
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.invalid-reporttypes.outcome }}"
- name: 2c - And the 'error-reason' output should be '${{ env.ERROR_REASON }}'
if: always()
run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON }}" --actual "${{ steps.invalid-reporttypes.outputs.error-reason }}"
- name: 2d - And the target directory should not exist
if: always()
run: ./test/assert-dir-does-not-exist.sh --dir "${{ env.TARGETDIR_INPUT }}"
- name: '-------------------------------------------------------------------------------------------------------------'
run: echo ""
- name: ' TEST 3 - BAD REPORTS INPUT (DIR DOES NOT EXIST) '
run: echo ""
- name: Setup - Set variables for Test 3
if: always()
run: |
errorReason="No matching files found"
reports="./test/input-files/bad-dir/*.xml"
targetDir="./test-results/dir-does-not-exist"
generatedFile=""
fileWithSubstring=""
echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV"
echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV"
echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV"
echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV"
echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV"
- name: 3a - When code-coverage-report-generator is called with a 'reports' input dir that does not exist
id: dir-does-not-exist
if: always()
continue-on-error: true # This is needed because we expect the step to fail but we need it to "pass" in order for the test job to succeed.
uses: ./
with:
reports: '${{ env.REPORTS_INPUT }}'
targetdir: '${{ env.TARGETDIR_INPUT }}'
reporttypes: 'MarkdownSummary'
verbosity: 'Info'
- name: 3b - Then the action outcome should be failure
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.dir-does-not-exist.outcome }}"
- name: 3c - And the 'error-reason' output should be '${{ env.ERROR_REASON }}'
if: always()
run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON }}" --actual "${{ steps.dir-does-not-exist.outputs.error-reason }}"
- name: 3d - And the target directory should be empty
if: always()
run: ./test/assert-dir-is-empty.sh --dir "${{ env.TARGETDIR_INPUT }}"
- name: '-------------------------------------------------------------------------------------------------------------'
run: echo ""
- name: ' TEST 4 - BAD REPORTS INPUT (PATTERN DOES NOT MATCH ANY FILES) '
run: echo ""
- name: Setup - Set variables for Test 4
if: always()
run: |
errorReason="No matching files found"
reports="./test/input-files/valid/*.opncvr.xml"
targetDir="./test-results/bad-pattern"
generatedFile=""
fileWithSubstring=""
echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV"
echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV"
echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV"
echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV"
echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV"
- name: 4a - When code-coverage-report-generator is called with a 'reports' input pattern that does not match any files
id: bad-pattern
if: always()
continue-on-error: true # This is needed because we expect the step to fail but we need it to "pass" in order for the test job to succeed.
uses: ./
with:
reports: '${{ env.REPORTS_INPUT }}'
targetdir: '${{ env.TARGETDIR_INPUT }}'
reporttypes: 'MarkdownSummary'
verbosity: 'Info'
- name: 4b - Then the action outcome should be failure
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.bad-pattern.outcome }}"
- name: 4c - And the 'error-reason' output should be '${{ env.ERROR_REASON }}'
if: always()
run: ./test/assert-values-match.sh --name "error-reason output" --expected "${{ env.ERROR_REASON }}" --actual "${{ steps.bad-pattern.outputs.error-reason }}"
- name: 4d - And the target directory should be empty
if: always()
run: ./test/assert-dir-is-empty.sh --dir "${{ env.TARGETDIR_INPUT }}"
- name: '-------------------------------------------------------------------------------------------------------------'
run: echo ""
- name: ' TEST 5 - MATCHING REPORTS '
run: echo ""
- name: Setup - Set variables for Test 5
if: always()
run: |
errorReason=""
reports="./test/input-files/valid/*.xml"
targetDir="./test-results/matching-reports"
generatedFile="$targetDir/Summary.md"
fileWithSubstring="./test/expected-contents/matching-reports.md"
echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV"
echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV"
echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV"
echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV"
echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV"
- name: 5a - When code-coverage-report-generator is called with a 'reports' input pattern that matches files
id: matching-reports
if: always()
uses: ./
with:
reports: '${{ env.REPORTS_INPUT }}'
targetdir: '${{ env.TARGETDIR_INPUT}}'
reporttypes: ' MarkDoWNSummary;Html '
verbosity: ' InFo '
title: 'MyProj Code Coverage'
tag: 'matching-tag'
- name: 5b - Then the action outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.matching-reports.outcome }}"
- name: 5c - And the 'error-reason' output should be empty
if: always()
run: ./test/assert-value-is-empty.sh --name "error-reason output" --value "${{ steps.matching-reports.outputs.error-reason }}"
- name: 5d - And the target directory should exist
if: always()
run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT }}"
- name: 5e - And '${{ env.GENERATED_FILE }}' should contain the expected contents
if: always()
run: |
# Comparing the Summary.md file will ensure that:
# - The provided tag is included
# - The title is not included (reporttype=MarkDoWNSummary does not support it)
# - None of the assemblies/classes/files have been filtered out because those inputs were not supplied
generatedFile="${{ env.GENERATED_FILE }}"
substringFile="${{ env.FILE_WITH_SUBSTRING }}"
./test/assert-file-contains-substring.sh --fullFile $generatedFile --substringFile $substringFile
- name: '-------------------------------------------------------------------------------------------------------------'
run: echo ""
- name: ' TEST 6 - ASSEMBLY FILTERS '
run: echo ""
- name: Setup - Set variables for Test 6
if: always()
run: |
errorReason=""
reports="./test/input-files/valid/*.xml"
targetDir="./test-results/assembly-filters"
generatedFile="$targetDir/Summary.xml"
fileWithSubstring="./test/expected-contents/assembly-filters.xml"
echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV"
echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV"
echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV"
echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV"
echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV"
- name: 6a - When code-coverage-report-generator is called with assembly filters
id: assembly-filters
if: always()
uses: ./
with:
reports: '${{ env.REPORTS_INPUT }}'
targetdir: '${{ env.TARGETDIR_INPUT }}'
reporttypes: 'XmlSummary'
title: 'MyProj Code Coverage AssemblyFilter'
assemblyfilters: '+MyProj*;-MyProj.Tests.*'
tag: 'assembly-filter-tag'
- name: 6b - Then the action outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.assembly-filters.outcome }}"
- name: 6c - And the 'error-reason' output should be empty
if: always()
run: ./test/assert-value-is-empty.sh --name "error-reason output" --value "${{ steps.assembly-filters.outputs.error-reason }}"
- name: 6d - And the target directory should exist
if: always()
run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT }}"
- name: 6e - And '${{ env.GENERATED_FILE }}' should contain the expected contents
if: always()
run: |
# Comparing the Summary.xml file will ensure that:
# - The tag is included (reporttype=XmlSummary supports it)
# - The title is included (reporttype=XmlSummary supports it)
# - The assemblies have been filtered
generatedFile="${{ env.GENERATED_FILE }}"
substringFile="${{ env.FILE_WITH_SUBSTRING }}"
./test/assert-file-contains-substring.sh --fullFile $generatedFile --substringFile $substringFile
- name: '-------------------------------------------------------------------------------------------------------------'
run: echo ""
- name: ' TEST 7 - CLASS FILTERS '
run: echo ""
- name: Setup - Set variables for Test 7
if: always()
run: |
errorReason=""
reports="./test/input-files/valid/*.xml"
targetDir="./test-results/class-filters"
generatedFile="$targetDir/Summary.json"
fileWithSubstring="./test/expected-contents/class-filters.json"
echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV"
echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV"
echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV"
echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV"
echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV"
- name: 7a - When code-coverage-report-generator is called with class filters
id: class-filters
if: always()
uses: ./
with:
reports: '${{ env.REPORTS_INPUT }}'
targetdir: '${{ env.TARGETDIR_INPUT }}'
reporttypes: 'JsonSummary'
classfilters: '-MyProj.Tests.*;-MyProj.Core*'
tag: 'class-filter-tag'
- name: 7b - Then the action outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.class-filters.outcome }}"
- name: 7c - And the 'error-reason' output should be empty
if: always()
run: ./test/assert-value-is-empty.sh --name "error-reason output" --value "${{ steps.class-filters.outputs.error-reason }}"
- name: 7d - And the target directory should exist
if: always()
run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT }}"
- name: 7e - And '${{ env.GENERATED_FILE }}' should contain the expected contents
if: always()
run: |
# Comparing the Summary.json file will ensure that:
# - No tag is included (reporttype=JsonSummary does not support it)
# - No title is included (the input was not supplied)
# - The classes have been filtered
generatedFile="${{ env.GENERATED_FILE }}"
substringFile="${{ env.FILE_WITH_SUBSTRING }}"
./test/assert-file-contains-substring.sh --fullFile $generatedFile --substringFile $substringFile
- name: '-------------------------------------------------------------------------------------------------------------'
run: echo ""
- name: ' TEST 8 - FILE FILTERS '
run: echo ""
- name: Setup - Set variables for Test 8
if: always()
run: |
errorReason=""
reports="./test/input-files/valid/*.xml"
targetDir="./test-results/file-filters"
generatedFile="$targetDir/Summary.txt"
fileWithSubstring="./test/expected-contents/file-filters.txt"
echo "ERROR_REASON=$errorReason" >> "$GITHUB_ENV"
echo "REPORTS_INPUT=$reports" >> "$GITHUB_ENV"
echo "TARGETDIR_INPUT=$targetDir" >> "$GITHUB_ENV"
echo "GENERATED_FILE=$generatedFile" >> "$GITHUB_ENV"
echo "FILE_WITH_SUBSTRING=$fileWithSubstring" >> "$GITHUB_ENV"
- name: 8a - When code-coverage-report-generator is called with file filters
id: file-filters
if: always()
uses: ./
with:
reports: '${{ env.REPORTS_INPUT }}'
targetdir: '${{ env.TARGETDIR_INPUT }}'
reporttypes: 'TextSummary'
filefilters: '+*EnumExtensions.cs'
tag: 'file-filter-tag'
- name: 8b - Then the action outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.file-filters.outcome }}"
- name: 8c - And the 'error-reason' output should be empty
if: always()
run: ./test/assert-value-is-empty.sh --name "error-reason output" --value "${{ steps.file-filters.outputs.error-reason }}"
- name: 8d - And the target directory should exist
if: always()
run: ./test/assert-dir-exists.sh --dir "${{ env.TARGETDIR_INPUT }}"
- name: 8e - And '${{ env.GENERATED_FILE }}' should contain the expected contents
if: always()
run: |
# Comparing the Summary.txt file will ensure that:
# - No tag is included (reporttype=TextSummary does not support it)
# - No title is included (the input was not supplied)
# - The files have been filtered
generatedFile="${{ env.GENERATED_FILE }}"
substringFile="${{ env.FILE_WITH_SUBSTRING }}"
./test/assert-file-contains-substring.sh --fullFile $generatedFile --substringFile $substringFile