-
Notifications
You must be signed in to change notification settings - Fork 0
610 lines (562 loc) · 24 KB
/
Copy pathe2e-action-pull-request.yml
File metadata and controls
610 lines (562 loc) · 24 KB
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
name: (T) Action Pull Request
on:
workflow_call:
inputs:
mode:
description: Execution mode (ref or image)
required: false
type: string
default: ref
action_ref:
description: Ref for devops-infra/action-pull-request when mode=ref
required: false
type: string
default: master
image_tag:
description: Image tag for docker mode (for example v1.2.3-test or v1.2.3-rc)
required: false
type: string
default: v1
workflow_dispatch:
inputs:
mode:
description: Execution mode (ref or image)
required: false
default: ref
type: choice
options:
- ref
- image
action_ref:
description: Ref for devops-infra/action-pull-request when mode=ref
required: false
default: master
type: string
image_tag:
description: Image tag for docker mode (for example v1.2.3-test or v1.2.3-rc)
required: false
default: v1
type: string
permissions:
contents: write
pull-requests: write
issues: write
jobs:
preflight:
name: Validate workflow inputs
runs-on: ubuntu-latest
steps:
- name: Validate mode input
run: |
case "${{ inputs.mode }}" in
ref|image) ;;
*)
echo "Unsupported mode '${{ inputs.mode }}'. Expected 'ref' or 'image'."
exit 1
;;
esac
- name: Enforce organization caller for reusable workflow
if: ${{ github.event_name == 'workflow_call' }}
run: |
if [ "${{ github.repository_owner }}" != "devops-infra" ]; then
echo "This reusable workflow can only be called by devops-infra repositories."
exit 1
fi
basic-pull-request:
name: Basic pull request creation
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Create test branch with a commit
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b test/e2e-pr-basic-${{ github.run_id }}
echo "E2E PR basic test $(date -u)" > e2e-pr-test.txt
git add -f e2e-pr-test.txt
git commit -m "test(pull-request): basic PR test"
git push origin test/e2e-pr-basic-${{ github.run_id }}
- name: Checkout action under test
if: ${{ inputs.mode == 'ref' }}
uses: actions/checkout@v6
with:
repository: devops-infra/action-pull-request
ref: ${{ inputs.action_ref }}
path: .tmp/action-pull-request
- name: Create pull request
if: ${{ inputs.mode == 'ref' }}
id: pr
uses: ./.tmp/action-pull-request
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
title: "test(pull-request): basic pull request test - safe to close"
body: "Automated end-to-end test pull request. Will be closed automatically."
target_branch: master
- name: Create pull request via docker image
if: ${{ inputs.mode == 'image' }}
env:
ACTION_IMAGE: devopsinfra/action-pull-request:${{ inputs.image_tag }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
mkdir -p .tmp
: > .tmp/e2e-pr-basic.outputs
docker pull "${ACTION_IMAGE}"
docker run --rm \
-e GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
-e GITHUB_REPOSITORY="${{ github.repository }}" \
-e GITHUB_WORKSPACE=/github/workspace \
-e GITHUB_ACTOR="${{ github.actor }}" \
-e GITHUB_OUTPUT=/github/workspace/.tmp/e2e-pr-basic.outputs \
-e INPUT_GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
-e INPUT_SOURCE_BRANCH="test/e2e-pr-basic-${{ github.run_id }}" \
-e INPUT_TITLE="test(pull-request): basic pull request test - safe to close" \
-e INPUT_BODY="Automated end-to-end test pull request. Will be closed automatically." \
-e INPUT_TARGET_BRANCH=master \
-v "$PWD:/github/workspace" \
-w /github/workspace \
"${ACTION_IMAGE}"
- name: Verify outputs
if: ${{ inputs.mode == 'ref' }}
run: |
echo "url=${{ steps.pr.outputs.url }}"
echo "pr_number=${{ steps.pr.outputs.pr_number }}"
test -n "${{ steps.pr.outputs.url }}"
test -n "${{ steps.pr.outputs.pr_number }}"
- name: Verify outputs from docker image
if: ${{ inputs.mode == 'image' }}
run: |
URL="$(sed -n 's/^url=//p' .tmp/e2e-pr-basic.outputs | tail -1)"
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-basic.outputs | tail -1)"
echo "url=${URL}"
echo "pr_number=${PR_NUMBER}"
test -n "${URL}"
test -n "${PR_NUMBER}"
- name: Cleanup - close PR and delete test branch
if: ${{ always() }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ steps.pr.outputs.pr_number }}"
if [ -z "$PR_NUMBER" ] && [ -f .tmp/e2e-pr-basic.outputs ]; then
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-basic.outputs | tail -1)"
fi
if [ -n "$PR_NUMBER" ]; then
gh pr close "$PR_NUMBER" --repo "${{ github.repository }}" 2>/dev/null || true
fi
git push origin --delete test/e2e-pr-basic-${{ github.run_id }} 2>/dev/null || true
pull-request-with-title-body:
name: Pull request with custom title and body
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Create test branch with a commit
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b test/e2e-pr-custom-${{ github.run_id }}
echo "E2E PR custom title/body test $(date -u)" > e2e-pr-custom-test.txt
git add -f e2e-pr-custom-test.txt
git commit -m "test(pull-request): custom title/body PR test"
git push origin test/e2e-pr-custom-${{ github.run_id }}
- name: Checkout action under test
if: ${{ inputs.mode == 'ref' }}
uses: actions/checkout@v6
with:
repository: devops-infra/action-pull-request
ref: ${{ inputs.action_ref }}
path: .tmp/action-pull-request
- name: Create pull request with custom title and body
if: ${{ inputs.mode == 'ref' }}
id: pr
uses: ./.tmp/action-pull-request
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
title: "test(pull-request): custom title test - safe to close"
body: |
Automated end-to-end test.
Testing custom title and body fields.
Safe to close automatically.
target_branch: master
allow_no_diff: "false"
- name: Create pull request via docker image
if: ${{ inputs.mode == 'image' }}
env:
ACTION_IMAGE: devopsinfra/action-pull-request:${{ inputs.image_tag }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
mkdir -p .tmp
: > .tmp/e2e-pr-custom.outputs
docker pull "${ACTION_IMAGE}"
docker run --rm \
-e GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
-e GITHUB_REPOSITORY="${{ github.repository }}" \
-e GITHUB_WORKSPACE=/github/workspace \
-e GITHUB_ACTOR="${{ github.actor }}" \
-e GITHUB_OUTPUT=/github/workspace/.tmp/e2e-pr-custom.outputs \
-e INPUT_GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
-e INPUT_SOURCE_BRANCH="test/e2e-pr-custom-${{ github.run_id }}" \
-e INPUT_TITLE="test(pull-request): custom title test - safe to close" \
-e INPUT_BODY=$'Automated end-to-end test.\nTesting custom title and body fields.\nSafe to close automatically.' \
-e INPUT_TARGET_BRANCH=master \
-e INPUT_ALLOW_NO_DIFF=false \
-v "$PWD:/github/workspace" \
-w /github/workspace \
"${ACTION_IMAGE}"
- name: Verify outputs
if: ${{ inputs.mode == 'ref' }}
run: |
echo "url=${{ steps.pr.outputs.url }}"
echo "pr_number=${{ steps.pr.outputs.pr_number }}"
test -n "${{ steps.pr.outputs.url }}"
test -n "${{ steps.pr.outputs.pr_number }}"
- name: Verify outputs from docker image
if: ${{ inputs.mode == 'image' }}
run: |
URL="$(sed -n 's/^url=//p' .tmp/e2e-pr-custom.outputs | tail -1)"
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-custom.outputs | tail -1)"
echo "url=${URL}"
echo "pr_number=${PR_NUMBER}"
test -n "${URL}"
test -n "${PR_NUMBER}"
- name: Cleanup - close PR and delete test branch
if: ${{ always() }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ steps.pr.outputs.pr_number }}"
if [ -z "$PR_NUMBER" ] && [ -f .tmp/e2e-pr-custom.outputs ]; then
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-custom.outputs | tail -1)"
fi
if [ -n "$PR_NUMBER" ]; then
gh pr close "$PR_NUMBER" --repo "${{ github.repository }}" 2>/dev/null || true
fi
git push origin --delete test/e2e-pr-custom-${{ github.run_id }} 2>/dev/null || true
pull-request-with-project:
name: Pull request with project assignment
needs: [preflight]
if: ${{ vars.E2E_ACTION_PULL_REQUEST_PROJECT != '' }}
runs-on: ubuntu-latest
env:
GH_PROJECT_TOKEN: ${{ secrets.GH_PROJECT_TOKEN }}
PROJECT_TITLE: ${{ vars.E2E_ACTION_PULL_REQUEST_PROJECT }}
steps:
- name: Skip when project token is not configured
if: ${{ env.GH_PROJECT_TOKEN == '' }}
run: echo "Skipping project assignment E2E because GH_PROJECT_TOKEN is not configured."
- name: Checkout repository
if: ${{ env.GH_PROJECT_TOKEN != '' }}
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Create test branch with a commit
if: ${{ env.GH_PROJECT_TOKEN != '' }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b test/e2e-pr-project-${{ github.run_id }}
echo "E2E PR project test $(date -u)" > e2e-pr-project-test.txt
git add -f e2e-pr-project-test.txt
git commit -m "test(pull-request): project assignment PR test"
git push origin test/e2e-pr-project-${{ github.run_id }}
- name: Checkout action under test
if: ${{ env.GH_PROJECT_TOKEN != '' && inputs.mode == 'ref' }}
uses: actions/checkout@v6
with:
repository: devops-infra/action-pull-request
ref: ${{ inputs.action_ref }}
path: .tmp/action-pull-request
- name: Create pull request with project assignment
if: ${{ env.GH_PROJECT_TOKEN != '' && inputs.mode == 'ref' }}
id: pr
uses: ./.tmp/action-pull-request
with:
github_token: ${{ env.GH_PROJECT_TOKEN }}
title: "test(pull-request): project assignment test - safe to close"
body: "Automated end-to-end test for project assignment."
target_branch: master
project: ${{ env.PROJECT_TITLE }}
- name: Create pull request via docker image
if: ${{ env.GH_PROJECT_TOKEN != '' && inputs.mode == 'image' }}
env:
ACTION_IMAGE: devopsinfra/action-pull-request:${{ inputs.image_tag }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
mkdir -p .tmp
: > .tmp/e2e-pr-project.outputs
docker pull "${ACTION_IMAGE}"
docker run --rm \
-e GITHUB_TOKEN="${GH_PROJECT_TOKEN}" \
-e GITHUB_REPOSITORY="${{ github.repository }}" \
-e GITHUB_WORKSPACE=/github/workspace \
-e GITHUB_ACTOR="${{ github.actor }}" \
-e GITHUB_OUTPUT=/github/workspace/.tmp/e2e-pr-project.outputs \
-e INPUT_GITHUB_TOKEN="${GH_PROJECT_TOKEN}" \
-e INPUT_SOURCE_BRANCH="test/e2e-pr-project-${{ github.run_id }}" \
-e INPUT_TITLE="test(pull-request): project assignment test - safe to close" \
-e INPUT_BODY="Automated end-to-end test for project assignment." \
-e INPUT_TARGET_BRANCH=master \
-e INPUT_PROJECT="${PROJECT_TITLE}" \
-v "$PWD:/github/workspace" \
-w /github/workspace \
"${ACTION_IMAGE}"
- name: Verify outputs
if: ${{ env.GH_PROJECT_TOKEN != '' && inputs.mode == 'ref' }}
run: |
echo "url=${{ steps.pr.outputs.url }}"
echo "pr_number=${{ steps.pr.outputs.pr_number }}"
test -n "${{ steps.pr.outputs.url }}"
test -n "${{ steps.pr.outputs.pr_number }}"
- name: Verify outputs from docker image
if: ${{ env.GH_PROJECT_TOKEN != '' && inputs.mode == 'image' }}
run: |
URL="$(sed -n 's/^url=//p' .tmp/e2e-pr-project.outputs | tail -1)"
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-project.outputs | tail -1)"
echo "url=${URL}"
echo "pr_number=${PR_NUMBER}"
test -n "${URL}"
test -n "${PR_NUMBER}"
- name: Verify project assignment
if: ${{ env.GH_PROJECT_TOKEN != '' }}
env:
GH_TOKEN: ${{ env.GH_PROJECT_TOKEN }}
run: |
PR_NUMBER="${{ steps.pr.outputs.pr_number }}"
if [ -z "$PR_NUMBER" ] && [ -f .tmp/e2e-pr-project.outputs ]; then
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-project.outputs | tail -1)"
fi
test -n "${PR_NUMBER}"
PROJECT_FOUND="$(
gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json projectItems,projectCards \
| jq -r --arg title "${PROJECT_TITLE}" \
'([.projectItems[]?.project.title?, .projectCards[]?.project.name?, .projectCards[]?.project.title?]
| any(. == $title))'
)"
test "${PROJECT_FOUND}" = "true"
- name: Cleanup - remove project assignment, close PR, and delete test branch
if: ${{ always() }}
env:
GH_TOKEN: ${{ env.GH_PROJECT_TOKEN }}
run: |
if [ -z "${GH_TOKEN}" ]; then
exit 0
fi
PR_NUMBER="${{ steps.pr.outputs.pr_number }}"
if [ -z "$PR_NUMBER" ] && [ -f .tmp/e2e-pr-project.outputs ]; then
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-project.outputs | tail -1)"
fi
if [ -n "$PR_NUMBER" ]; then
gh pr edit "$PR_NUMBER" --repo "${{ github.repository }}" --remove-project "${PROJECT_TITLE}" 2>/dev/null || true
gh pr close "$PR_NUMBER" --repo "${{ github.repository }}" 2>/dev/null || true
fi
git push origin --delete test/e2e-pr-project-${{ github.run_id }} 2>/dev/null || true
pull-request-with-repository-path:
name: Pull request using custom checkout path and explicit repository
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository into custom path
uses: actions/checkout@v6
with:
fetch-depth: 0
path: work/repo
- name: Create test branch with a commit inside custom path
run: |
cd work/repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b test/e2e-pr-repo-path-${{ github.run_id }}
echo "E2E PR repository_path test $(date -u)" > e2e-pr-path-test.txt
git add -f e2e-pr-path-test.txt
git commit -m "test(pull-request): repository path PR test"
git push origin test/e2e-pr-repo-path-${{ github.run_id }}
- name: Checkout action under test
if: ${{ inputs.mode == 'ref' }}
uses: actions/checkout@v6
with:
repository: devops-infra/action-pull-request
ref: ${{ inputs.action_ref }}
path: .tmp/action-pull-request
- name: Create pull request with repository and repository_path
if: ${{ inputs.mode == 'ref' }}
id: pr
uses: ./.tmp/action-pull-request
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
repository_path: work/repo
title: "test(pull-request): repository path PR test - safe to close"
body: "Automated end-to-end test for repository_path input."
target_branch: master
- name: Create pull request via docker image
if: ${{ inputs.mode == 'image' }}
env:
ACTION_IMAGE: devopsinfra/action-pull-request:${{ inputs.image_tag }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
mkdir -p .tmp
: > .tmp/e2e-pr-repo-path.outputs
docker pull "${ACTION_IMAGE}"
docker run --rm \
-e GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
-e GITHUB_REPOSITORY="${{ github.repository }}" \
-e GITHUB_WORKSPACE=/github/workspace \
-e GITHUB_ACTOR="${{ github.actor }}" \
-e GITHUB_OUTPUT=/github/workspace/.tmp/e2e-pr-repo-path.outputs \
-e INPUT_GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
-e INPUT_REPOSITORY="${{ github.repository }}" \
-e INPUT_REPOSITORY_PATH=work/repo \
-e INPUT_SOURCE_BRANCH="test/e2e-pr-repo-path-${{ github.run_id }}" \
-e INPUT_TITLE="test(pull-request): repository path PR test - safe to close" \
-e INPUT_BODY="Automated end-to-end test for repository_path input." \
-e INPUT_TARGET_BRANCH=master \
-v "$PWD:/github/workspace" \
-w /github/workspace \
"${ACTION_IMAGE}"
- name: Verify outputs
if: ${{ inputs.mode == 'ref' }}
run: |
echo "url=${{ steps.pr.outputs.url }}"
echo "pr_number=${{ steps.pr.outputs.pr_number }}"
test -n "${{ steps.pr.outputs.url }}"
test -n "${{ steps.pr.outputs.pr_number }}"
- name: Verify outputs from docker image
if: ${{ inputs.mode == 'image' }}
run: |
URL="$(sed -n 's/^url=//p' .tmp/e2e-pr-repo-path.outputs | tail -1)"
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-repo-path.outputs | tail -1)"
echo "url=${URL}"
echo "pr_number=${PR_NUMBER}"
test -n "${URL}"
test -n "${PR_NUMBER}"
- name: Cleanup - close PR and delete test branch
if: ${{ always() }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ steps.pr.outputs.pr_number }}"
if [ -z "$PR_NUMBER" ] && [ -f .tmp/e2e-pr-repo-path.outputs ]; then
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-repo-path.outputs | tail -1)"
fi
if [ -n "$PR_NUMBER" ]; then
gh pr close "$PR_NUMBER" --repo "${{ github.repository }}" 2>/dev/null || true
fi
cd work/repo
git push origin --delete test/e2e-pr-repo-path-${{ github.run_id }} 2>/dev/null || true
pull-request-draft-with-diff:
name: Draft pull request with get_diff enabled
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Create test branch with a commit
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b test/e2e-pr-draft-${{ github.run_id }}
echo "E2E draft PR test $(date -u)" > e2e-pr-draft-test.txt
git add -f e2e-pr-draft-test.txt
git commit -m "test(pull-request): draft PR with diff test"
git push origin test/e2e-pr-draft-${{ github.run_id }}
- name: Checkout action under test
if: ${{ inputs.mode == 'ref' }}
uses: actions/checkout@v6
with:
repository: devops-infra/action-pull-request
ref: ${{ inputs.action_ref }}
path: .tmp/action-pull-request
- name: Create draft pull request with diff injection
if: ${{ inputs.mode == 'ref' }}
id: pr
uses: ./.tmp/action-pull-request
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
title: "test(pull-request): draft PR with diff - safe to close"
body: |
Automated end-to-end test.
<!-- Diff commits - START -->
<!-- Diff commits - END -->
<!-- Diff files - START -->
<!-- Diff files - END -->
target_branch: master
draft: "true"
get_diff: "true"
- name: Create draft pull request via docker image
if: ${{ inputs.mode == 'image' }}
env:
ACTION_IMAGE: devopsinfra/action-pull-request:${{ inputs.image_tag }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
mkdir -p .tmp
: > .tmp/e2e-pr-draft.outputs
docker pull "${ACTION_IMAGE}"
docker run --rm \
-e GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
-e GITHUB_REPOSITORY="${{ github.repository }}" \
-e GITHUB_WORKSPACE=/github/workspace \
-e GITHUB_ACTOR="${{ github.actor }}" \
-e GITHUB_OUTPUT=/github/workspace/.tmp/e2e-pr-draft.outputs \
-e INPUT_GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
-e INPUT_SOURCE_BRANCH="test/e2e-pr-draft-${{ github.run_id }}" \
-e INPUT_TITLE="test(pull-request): draft PR with diff - safe to close" \
-e INPUT_BODY=$'Automated end-to-end test.\n<!-- Diff commits - START -->\n<!-- Diff commits - END -->\n<!-- Diff files - START -->\n<!-- Diff files - END -->' \
-e INPUT_TARGET_BRANCH=master \
-e INPUT_DRAFT=true \
-e INPUT_GET_DIFF=true \
-v "$PWD:/github/workspace" \
-w /github/workspace \
"${ACTION_IMAGE}"
- name: Verify outputs
if: ${{ inputs.mode == 'ref' }}
run: |
echo "url=${{ steps.pr.outputs.url }}"
echo "pr_number=${{ steps.pr.outputs.pr_number }}"
test -n "${{ steps.pr.outputs.url }}"
test -n "${{ steps.pr.outputs.pr_number }}"
- name: Verify outputs from docker image
if: ${{ inputs.mode == 'image' }}
run: |
URL="$(sed -n 's/^url=//p' .tmp/e2e-pr-draft.outputs | tail -1)"
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-draft.outputs | tail -1)"
echo "url=${URL}"
echo "pr_number=${PR_NUMBER}"
test -n "${URL}"
test -n "${PR_NUMBER}"
- name: Cleanup - close PR and delete test branch
if: ${{ always() }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ steps.pr.outputs.pr_number }}"
if [ -z "$PR_NUMBER" ] && [ -f .tmp/e2e-pr-draft.outputs ]; then
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-draft.outputs | tail -1)"
fi
if [ -n "$PR_NUMBER" ]; then
gh pr close "$PR_NUMBER" --repo "${{ github.repository }}" 2>/dev/null || true
fi
git push origin --delete test/e2e-pr-draft-${{ github.run_id }} 2>/dev/null || true