generated from im-open/javascript-action-template
-
Notifications
You must be signed in to change notification settings - Fork 2
639 lines (540 loc) · 32.4 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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
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'
test:
runs-on: ubuntu-latest
env:
# NOTE: This relies on the last release being v2.0.0. If it is removed, the test
# that relies on it will fail, specifically the auto-generated release notes test.
# Releases aren't utilized by users (tags are), it is just there for testing.
COMMITISH: 'main'
# Generated tags for each of the scenarios we'll be testing
TAG_RELEASE_NO_ASSET: ''
TAG_RELEASE_WITH_ASSET: ''
TAG_RELEASE_WITH_NAME: ''
TAG_BODY_FROM_INPUT: ''
TAG_BODY_FROM_FILE: ''
TAG_DRAFT_RELEASE: ''
TAG_PRE_RELEASE: ''
TAG_AUTO_GENERATED_NOTES: ''
TAG_DUPLICATE_NO_ERROR: ''
TAG_DUPLICATE_WITH_ERROR: ''
TAG_ASSET_PATH_ERROR: ''
TAG_ASSET_NAME_ERROR: ''
TAG_ASSET_TYPE_ERROR: ''
steps:
#--------------------------------------
# SETUP
#--------------------------------------
- name: Fail test job if fork
run: |
if [ "${{ github.event.pull_request.head.repo.fork }}" == "true" ]; then
echo "This test job requires write scopes on GITHUB_TOKEN that PRs from forks will not have access to. Before this PR can be merged, the tests should be run on an intermediate branch created by repository owners."
exit 1
fi
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: Setup - Checkout the action
uses: actions/checkout@v4
- name: Setup - Dynamically generate tags for each of the scenarios to use with their release
run: |
tag=$(date +'%Y%m%d%H%M%S')
echo "TAG_RELEASE_NO_ASSET=releaseNoAssetTag_$tag" >> $GITHUB_ENV
echo "TAG_RELEASE_WITH_ASSET=releaseWithAssetTag_$tag" >> $GITHUB_ENV
echo "TAG_RELEASE_WITH_NAME=releaseWithNameTag_$tag" >> $GITHUB_ENV
echo "TAG_BODY_FROM_INPUT=bodyFromArgTag_$tag" >> $GITHUB_ENV
echo "TAG_BODY_FROM_FILE=bodyFromFileTag_$tag" >> $GITHUB_ENV
echo "TAG_DRAFT_RELEASE=draftReleaseTag_$tag" >> $GITHUB_ENV
echo "TAG_PRE_RELEASE=preReleaseTag_$tag" >> $GITHUB_ENV
# All three of these releases will use the same tag. The release notes tag
# will stand on its own and should succeed. The other two purposely duplicate it.
echo "TAG_AUTO_GENERATED_NOTES=autoGeneratedReleaseNotesTag_$tag" >> $GITHUB_ENV
echo "TAG_DUPLICATE_NO_ERROR=autoGeneratedReleaseNotesTag_$tag" >> $GITHUB_ENV
echo "TAG_DUPLICATE_WITH_ERROR=autoGeneratedReleaseNotesTag_$tag" >> $GITHUB_ENV
echo "TAG_ASSET_PATH_ERROR=assetPathErrorTag_$tag" >> $GITHUB_ENV
echo "TAG_ASSET_NAME_ERROR=assetNameErrorTag_$tag" >> $GITHUB_ENV
echo "TAG_ASSET_TYPE_ERROR=assetTypeErrorTag_$tag" >> $GITHUB_ENV
#--------------------------------------
# REGULAR RELEASE WITH DEFAULT VALUES
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a production ready release
uses: ./
if: always()
id: prod-release
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ env.TAG_RELEASE_NO_ASSET }}
commitish: ${{ env.COMMITISH}}
#release-name: ''
- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.prod-release.outcome }}"
- name: And the release should exist on GitHub with props that match the inputs and defaults
uses: actions/github-script@v7
with:
script: |
const assertReleaseExists = require('./test/assert-release-exists.js');
const assertReleasePropsMatchActionOutputs = require('./test/assert-release-props-match-action-outputs.js');
const assertReleasePropsMatchInputArgs = require('./test/assert-release-props-match-input-args.js');
const releaseId = '${{ steps.prod-release.outputs.release-id }}';
const actualRelease = await assertReleaseExists(github, core, releaseId);
const expectedPropsFromInputs = {
// These items should match the args exactly
tagName: '${{ env.TAG_RELEASE_NO_ASSET }}',
commitish: '${{ env.COMMITISH }}',
// These items have default values, test here so we don't need specific tests for the defaults
releaseName: '${{ env.TAG_RELEASE_NO_ASSET }}',
draft: false,
preRelease: false,
body: ''
};
assertReleasePropsMatchInputArgs(core, actualRelease, expectedPropsFromInputs);
const hasAssets = false;
const expectedPropsFromOutputs = JSON.parse(`${{ toJSON(steps.prod-release.outputs) }}`);
assertReleasePropsMatchActionOutputs(core, actualRelease, hasAssets, expectedPropsFromOutputs);
#--------------------------------------
# REGULAR RELEASE WITH AN ASSET
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a production ready release with an asset
uses: ./
if: always()
id: prod-release-asset
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ env.TAG_RELEASE_WITH_ASSET }}
commitish: ${{ env.COMMITISH}}
asset-path: './test/files/test-asset.txt'
asset-name: 'prod-release-test-asset'
asset-content-type: 'application/text'
- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.prod-release-asset.outcome }}"
- name: And the release should exist on GitHub with the populated release url props
uses: actions/github-script@v7
with:
script: |
const assertReleaseExists = require('./test/assert-release-exists.js');
const assertReleasePropsMatchActionOutputs = require('./test/assert-release-props-match-action-outputs.js');
const releaseId = '${{ steps.prod-release-asset.outputs.release-id }}';
const actualRelease = await assertReleaseExists(github, core, releaseId);
const hasAssets = true;
const expectedPropsFromOutputs = JSON.parse(`${{ toJSON(steps.prod-release-asset.outputs) }}`);
assertReleasePropsMatchActionOutputs(core, actualRelease, hasAssets, expectedPropsFromOutputs);
#--------------------------------------
# RELEASE WITH A NAME
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a production ready release with a name
uses: ./
if: always()
id: with-name
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ env.TAG_RELEASE_WITH_NAME }}
commitish: ${{ env.COMMITISH }}
release-name: 'My test release'
- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.with-name.outcome }}"
- name: And the release should exist on GitHub with the specified name
if: always()
uses: actions/github-script@v7
with:
script: |
const assertReleaseExists = require('./test/assert-release-exists.js');
const assertReleasePropsMatchInputArgs = require('./test/assert-release-props-match-input-args.js');
const releaseId = '${{ steps.with-name.outputs.release-id }}';
const actualRelease = await assertReleaseExists(github, core, releaseId);
const expectedPropsFromInputs = {
releaseName: 'My test release',
tagName: '${{ env.TAG_RELEASE_WITH_NAME }}'
};
assertReleasePropsMatchInputArgs(core, actualRelease, expectedPropsFromInputs);
#--------------------------------------
# BODY FROM INPUT ARG
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a release with a body that comes from an input arg
uses: ./
if: always()
id: body-from-input
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ env.TAG_BODY_FROM_INPUT }}
commitish: ${{ env.COMMITISH }}
body: 'This is the body of the commit that came from an input arg.'
- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.body-from-input.outcome }}"
- name: And the release should exist on GitHub with the specified body
if: always()
uses: actions/github-script@v7
with:
script: |
const assertReleaseExists = require('./test/assert-release-exists.js');
const assertReleasePropsMatchInputArgs = require('./test/assert-release-props-match-input-args.js');
const releaseId = '${{ steps.body-from-input.outputs.release-id }}';
const actualRelease = await assertReleaseExists(github, core, releaseId);
const expectedPropsFromInputs = { body: 'This is the body of the commit that came from an input arg.' };
assertReleasePropsMatchInputArgs(core, actualRelease, expectedPropsFromInputs);
#--------------------------------------
# BODY FROM INPUT FILE
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a release with a body that comes from a file
uses: ./
if: always()
id: body-from-file
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ env.TAG_BODY_FROM_FILE }}
commitish: ${{ env.COMMITISH }}
body-path: './test/files/test-body.txt'
- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.body-from-file.outcome }}"
- name: And the release should exist on GitHub with the specified body
if: always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const assertReleaseExists = require('./test/assert-release-exists.js');
const assertReleasePropsMatchInputArgs = require('./test/assert-release-props-match-input-args.js');
const releaseId = '${{ steps.body-from-file.outputs.release-id }}';
const actualRelease = await assertReleaseExists(github, core, releaseId);
const expectedBody = fs.readFileSync('./test/files/test-body.txt', 'utf8');
const expectedPropsFromInputs = { body: expectedBody };
assertReleasePropsMatchInputArgs(core, actualRelease, expectedPropsFromInputs);
#-----------------------------------------------
# DRAFT RELEASE
#-----------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a draft release
uses: ./
if: always()
id: draft-release
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ env.TAG_DRAFT_RELEASE }}
commitish: ${{ env.COMMITISH }}
draft: 'true'
- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.draft-release.outcome }}"
- name: And the release should exist on GitHub as a draft release
if: always()
uses: actions/github-script@v7
with:
script: |
const assertReleaseExists = require('./test/assert-release-exists.js');
const assertReleasePropsMatchActionOutputs = require('./test/assert-release-props-match-action-outputs.js');
const assertReleasePropsMatchInputArgs = require('./test/assert-release-props-match-input-args.js');
const releaseId = '${{ steps.draft-release.outputs.release-id }}';
const actualRelease = await assertReleaseExists(github, core, releaseId);
const expectedPropsFromInputs = { draft: true };
assertReleasePropsMatchInputArgs(core, actualRelease, expectedPropsFromInputs);
const hasAssets = false;
const expectedPropsFromOutputs = JSON.parse(`${{ toJSON(steps.draft-release.outputs) }}`);
assertReleasePropsMatchActionOutputs(core, actualRelease, hasAssets, expectedPropsFromOutputs);
#-----------------------------------------------
# PRE-RELEASE
#-----------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a pre-release
uses: ./
if: always()
id: pre-release
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ env.TAG_PRE_RELEASE }}
commitish: ${{ env.COMMITISH }}
prerelease: 'true'
- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.pre-release.outcome }}"
- name: And the release should exist on GitHub as a pre-release
if: always()
uses: actions/github-script@v7
with:
script: |
const assertReleaseExists = require('./test/assert-release-exists.js');
const assertReleasePropsMatchActionOutputs = require('./test/assert-release-props-match-action-outputs.js');
const assertReleasePropsMatchInputArgs = require('./test/assert-release-props-match-input-args.js');
const releaseId = '${{ steps.pre-release.outputs.release-id }}';
const actualRelease = await assertReleaseExists(github, core, releaseId);
const expectedPropsFromInputs = { preRelease: true };
assertReleasePropsMatchInputArgs(core, actualRelease, expectedPropsFromInputs);
const hasAssets = false;
const expectedPropsFromOutputs = JSON.parse(`${{ toJSON(steps.pre-release.outputs) }}`);
assertReleasePropsMatchActionOutputs(core, actualRelease, hasAssets, expectedPropsFromOutputs);
#-----------------------------------------------
# AUTO GENERATE RELEASE NOTES
#-----------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a release with auto-generated release notes
uses: ./
if: always()
id: auto-generated-notes
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ env.TAG_AUTO_GENERATED_NOTES }}
commitish: ${{ env.COMMITISH }}
generate-release-notes: true
- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.auto-generated-notes.outcome }}"
- name: And the release should exist on GitHub with the release notes generated from the commits
if: always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const assertReleaseExists = require('./test/assert-release-exists.js');
const assertBodyIncludesFragments = require('./test/assert-value-includes-fragments.js');
const releaseId = '${{ steps.auto-generated-notes.outputs.release-id }}';
const actualRelease = await assertReleaseExists(github, core, releaseId);
const expectedStart = fs.readFileSync('./test/files/test-notes-start.txt', 'utf8');
let expectedEnd = fs.readFileSync('./test/files/test-notes-end.txt', 'utf8');
expectedEnd = expectedEnd.replace('REPLACEME', '${{ env.TAG_AUTO_GENERATED_NOTES }}')
assertBodyIncludesFragments(core, actualRelease.body, expectedStart, expectedEnd);
#-----------------------------------------------
# DUPLICATE EXISTING RELEASE WITHOUT REMOVING IT
#-----------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a release that duplicates another release without including the flag to first remove it
uses: ./
if: always()
id: duplicate-with-error
continue-on-error: true # This is needed because we expect the step to fail. We need it to "pass" in order for the test job to succeed.
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# Use the same tag-name and commitish that the release we are duplicating used
tag-name: ${{ env.TAG_AUTO_GENERATED_NOTES }}
commitish: ${{ env.COMMITISH }}
delete-existing-release: false
- name: Then the outcome should be failure
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.duplicate-with-error.outcome }}"
#-----------------------------------------
# DUPLICATE EXISTING RELEASE AND REMOVE IT
#-----------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a duplicate release with flag to remove existing release set
uses: ./
if: always()
id: duplicate-no-error
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# This flag should delete the existing release and let it be re-created
delete-existing-release: true
# Use the same tag-name and commitish that the release we are duplicating used
tag-name: ${{ env.TAG_AUTO_GENERATED_NOTES }}
commitish: ${{ env.COMMITISH }}
- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.duplicate-no-error.outcome }}"
- name: And the release should have been re-created with a new id
if: always()
run: |
./test/assert-values-do-not-match.sh --name "Release Id" \
--value1 "${{ steps.auto-generated-notes.outputs.release-id }}" \
--value2 "${{ steps.duplicate-no-error.outputs.release-id }}"
- name: And the new release should exist on GitHub
if: always()
uses: actions/github-script@v7
with:
script: |
const assertReleaseExists = require('./test/assert-release-exists.js');
const releaseId = '${{ steps.duplicate-no-error.outputs.release-id }}';
const actualRelease = await assertReleaseExists(github, core, releaseId);
- name: And the original release should no longer exist
if: always()
uses: actions/github-script@v7
with:
script: |
const assertReleaseDoesNotExists = require('./test/assert-release-does-not-exist.js');
const originalId = '${{ steps.auto-generated-notes.outputs.release-id }}';
await assertReleaseDoesNotExists(github, core, originalId);
#----------------------------------------------------------------
# ASSET ERROR - exclude asset-path BUT INCLUDE OTHERS
#----------------------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a
uses: ./
if: always()
id: error-asset-path
continue-on-error: true # This is needed because we expect the step to fail. We need it to "pass" in order for the test job to succeed.
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ env.TAG_ASSET_PATH_ERROR }}
commitish: ${{ env.COMMITISH }}
asset-path: '' # cause a failure by ommitting one of the required asset args
asset-name: 'prod-release-test-asset'
asset-content-type: 'application/text'
- name: Then the outcome should be failure
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.error-asset-path.outcome }}"
- name: And the action should return undefined values
if: always()
run: |
./test/assert-values-match.sh --name "release ID" --expected "" --actual "${{ steps.error-asset-path.outputs.release-id }}"
./test/assert-values-match.sh --name "html url" --expected "" --actual "${{ steps.error-asset-path.outputs.release-html-url }}"
./test/assert-values-match.sh --name "asset upload url" --expected "" --actual "${{ steps.error-asset-path.outputs.asset-upload-url }}"
./test/assert-values-match.sh --name "asset download url" --expected "" --actual "${{ steps.error-asset-path.outputs.asset-browser-download-url }}"
#----------------------------------------------------------------
# ASSET ERROR - exclude asset-name - BUT INCLUDE OTHERS
#----------------------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a
uses: ./
if: always()
id: error-asset-name
continue-on-error: true # This is needed because we expect the step to fail. We need it to "pass" in order for the test job to succeed.
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ env.TAG_ASSET_PATH_ERROR }}
commitish: ${{ env.COMMITISH }}
asset-path: './test/files/test-asset.txt'
asset-name: '' # cause a failure by ommitting one of the required asset args
asset-content-type: 'application/text'
- name: Then the outcome should be failure
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.error-asset-name.outcome }}"
- name: And the action should return undefined values
if: always()
run: |
./test/assert-values-match.sh --name "release ID" --expected "" --actual "${{ steps.error-asset-name.outputs.release-id }}"
./test/assert-values-match.sh --name "html url" --expected "" --actual "${{ steps.error-asset-name.outputs.release-html-url }}"
./test/assert-values-match.sh --name "asset upload url" --expected "" --actual "${{ steps.error-asset-name.outputs.asset-upload-url }}"
./test/assert-values-match.sh --name "asset download url" --expected "" --actual "${{ steps.error-asset-name.outputs.asset-browser-download-url }}"
#----------------------------------------------------------------
# ASSET ERROR - exclude asset-content-type - BUT INCLUDE OTHERS
#----------------------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
- name: When creating a
uses: ./
if: always()
id: error-asset-type
continue-on-error: true # This is needed because we expect the step to fail. We need it to "pass" in order for the test job to succeed.
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-name: ${{ env.TAG_ASSET_PATH_ERROR }}
commitish: ${{ env.COMMITISH }}
asset-path: './test/files/test-asset.txt'
asset-name: 'prod-release-test-asset'
asset-content-type: '' # cause a failure by ommitting one of the required asset args
- name: Then the outcome should be failure
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.error-asset-type.outcome }}"
- name: And the action should return undefined values
if: always()
run: |
./test/assert-values-match.sh --name "release ID" --expected "" --actual "${{ steps.error-asset-type.outputs.release-id }}"
./test/assert-values-match.sh --name "html url" --expected "" --actual "${{ steps.error-asset-type.outputs.release-html-url }}"
./test/assert-values-match.sh --name "asset upload url" --expected "" --actual "${{ steps.error-asset-type.outputs.asset-upload-url }}"
./test/assert-values-match.sh --name "asset download url" --expected "" --actual "${{ steps.error-asset-type.outputs.asset-browser-download-url }}"
- name: Teardown - Cleanup all the releases by deleting them
if: always()
uses: actions/github-script@v7
with:
script: |
// Not all of these will end up with a tag and a release, but run them all just in case any of the tests
// fail unexpectedly. We don't want a bunch of test releases and tags cluttering up the real thing.
const deleteReleaseFromGitHub = require('./test/teardown/delete-release-from-github.js');
await deleteReleaseFromGitHub(github, core, '${{ steps.prod-release.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.prod-release-asset.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.with-name.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.body-from-input.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.body-from-file.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.draft-release.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.pre-release.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.auto-generated-notes.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.duplicate-with-error.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.duplicate-no-error.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.error-asset-path.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.error-asset-name.outputs.release-id }}');
await deleteReleaseFromGitHub(github, core, '${{ steps.error-asset-type.outputs.release-id }}');
const deleteTagFromGitHub = require('./test/teardown/delete-tag-from-github.js');
await deleteTagFromGitHub(github, core, '${{ env.TAG_RELEASE_NO_ASSET }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_RELEASE_WITH_ASSET }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_RELEASE_WITH_NAME }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_BODY_FROM_INPUT }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_BODY_FROM_FILE }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_DRAFT_RELEASE }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_PRE_RELEASE }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_AUTO_GENERATED_NOTES }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_AUTO_GENERATED_NOTES }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_AUTO_GENERATED_NOTES }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_ASSET_PATH_ERROR }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_ASSET_NAME_ERROR }}');
await deleteTagFromGitHub(github, core, '${{ env.TAG_ASSET_TYPE_ERROR }}');
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""