-
Notifications
You must be signed in to change notification settings - Fork 0
472 lines (413 loc) · 17.1 KB
/
e2e-action-commit-push.yml
File metadata and controls
472 lines (413 loc) · 17.1 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
name: (E2E) Action Commit Push
on:
workflow_call:
inputs:
mode:
description: Execution mode (ref or image)
required: false
type: string
default: ref
image_tag:
description: Image tag for docker mode (for example v1.2.3-test or v1.2.3-rc)
required: false
type: string
default: ''
workflow_dispatch:
inputs:
mode:
description: Execution mode (ref or image)
required: false
default: ref
type: choice
options:
- ref
- image
image_tag:
description: Image tag for docker mode (for example v1.2.3-test or v1.2.3-rc)
required: false
default: ''
type: string
permissions:
contents: 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-commit:
name: Basic commit and push to new branch
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Create test file
run: echo "E2E basic commit test $(date -u)" > e2e-test-file.txt
- name: Commit and push to new branch
if: ${{ inputs.mode == 'ref' }}
id: commit
uses: devops-infra/action-commit-push@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: "[E2E] Basic commit test"
target_branch: test/e2e-commit-push-basic-${{ github.run_id }}
- name: Commit and push via docker image (preview)
if: ${{ inputs.mode == 'image' }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
echo "Image mode placeholder for devopsinfra/action-commit-push:${{ inputs.image_tag }}"
echo "Use ref mode for authoritative validation until image-mode harness is finalized."
- name: Verify outputs
if: ${{ inputs.mode == 'ref' }}
run: |
echo "branch_name=${{ steps.commit.outputs.branch_name }}"
echo "files_changed=${{ steps.commit.outputs.files_changed }}"
test -n "${{ steps.commit.outputs.branch_name }}"
test -n "${{ steps.commit.outputs.files_changed }}"
- name: Cleanup - delete test branch
if: always()
run: git push origin --delete test/e2e-commit-push-basic-${{ github.run_id }} 2>/dev/null || true
commit-with-prefix-message:
name: Commit with custom prefix and message
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Create test file
run: echo "E2E prefix message test $(date -u)" > e2e-prefix-test.txt
- name: Commit with custom prefix and message
if: ${{ inputs.mode == 'ref' }}
id: commit
uses: devops-infra/action-commit-push@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_prefix: "[E2E-PREFIX]"
commit_message: " Custom message test"
target_branch: test/e2e-commit-push-prefix-${{ github.run_id }}
- name: Commit via docker image (preview)
if: ${{ inputs.mode == 'image' }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
echo "Image mode placeholder for devopsinfra/action-commit-push:${{ inputs.image_tag }}"
echo "Use ref mode for authoritative validation until image-mode harness is finalized."
- name: Verify outputs
if: ${{ inputs.mode == 'ref' }}
run: |
echo "branch_name=${{ steps.commit.outputs.branch_name }}"
echo "files_changed=${{ steps.commit.outputs.files_changed }}"
test -n "${{ steps.commit.outputs.branch_name }}"
test -n "${{ steps.commit.outputs.files_changed }}"
- name: Cleanup - delete test branch
if: always()
run: git push origin --delete test/e2e-commit-push-prefix-${{ github.run_id }} 2>/dev/null || true
allow-empty-commit:
name: Allow empty commit with no file changes
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Commit with no file changes to new branch
if: ${{ inputs.mode == 'ref' }}
id: commit
uses: devops-infra/action-commit-push@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
allow_empty_commit: "true"
commit_message: "[E2E] Empty commit test"
target_branch: test/e2e-commit-push-empty-${{ github.run_id }}
- name: Empty commit via docker image (preview)
if: ${{ inputs.mode == 'image' }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
echo "Image mode placeholder for devopsinfra/action-commit-push:${{ inputs.image_tag }}"
echo "Use ref mode for authoritative validation until image-mode harness is finalized."
- name: Verify branch output
if: ${{ inputs.mode == 'ref' }}
run: |
echo "branch_name=${{ steps.commit.outputs.branch_name }}"
test -n "${{ steps.commit.outputs.branch_name }}"
- name: Cleanup - delete test branch
if: always()
run: git push origin --delete test/e2e-commit-push-empty-${{ github.run_id }} 2>/dev/null || true
commit-with-timestamp-branch:
name: Commit to timestamped branch name
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Create test file
run: echo "E2E timestamp branch test $(date -u)" > e2e-timestamp-test.txt
- name: Commit and push to timestamped branch
if: ${{ inputs.mode == 'ref' }}
id: commit
uses: devops-infra/action-commit-push@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
add_timestamp: "true"
commit_message: "[E2E] Timestamp branch test"
target_branch: test/e2e-commit-push-timestamp
- name: Commit via docker image (preview)
if: ${{ inputs.mode == 'image' }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
echo "Image mode placeholder for devopsinfra/action-commit-push:${{ inputs.image_tag }}"
echo "Use ref mode for authoritative validation until image-mode harness is finalized."
- name: Verify timestamped branch output
if: ${{ inputs.mode == 'ref' }}
run: |
branch_name="${{ steps.commit.outputs.branch_name }}"
echo "branch_name=${branch_name}"
[[ "${branch_name}" =~ ^test/e2e-commit-push-timestamp-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}Z$ ]]
- name: Cleanup - delete test branch
if: ${{ always() && inputs.mode == 'ref' }}
run: |
branch_name="${{ steps.commit.outputs.branch_name }}"
if [ -n "${branch_name}" ]; then
git push origin --delete "${branch_name}" 2>/dev/null || true
fi
commit-with-repository-path:
name: Commit from custom repository_path
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository into custom path
uses: actions/checkout@v6
with:
fetch-depth: 0
path: repo
- name: Create test file in custom path
run: echo "E2E repository path test $(date -u)" > repo/e2e-repository-path.txt
- name: Commit and push using repository_path
if: ${{ inputs.mode == 'ref' }}
id: commit
uses: devops-infra/action-commit-push@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
repository_path: repo
commit_message: "[E2E] Repository path test"
target_branch: test/e2e-commit-push-path-${{ github.run_id }}
- name: Commit via docker image (preview)
if: ${{ inputs.mode == 'image' }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
echo "Image mode placeholder for devopsinfra/action-commit-push:${{ inputs.image_tag }}"
echo "Use ref mode for authoritative validation until image-mode harness is finalized."
- name: Verify repository_path output
if: ${{ inputs.mode == 'ref' }}
run: |
echo "files_changed=${{ steps.commit.outputs.files_changed }}"
test -n "${{ steps.commit.outputs.branch_name }}"
grep -Fq "e2e-repository-path.txt" <<'EOF'
${{ steps.commit.outputs.files_changed }}
EOF
- name: Cleanup - delete test branch
if: always()
run: git push origin --delete test/e2e-commit-push-path-${{ github.run_id }} 2>/dev/null || true
reset-target-branch-to-base:
name: Reset target branch to base branch
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Prepare base and target branches
if: ${{ inputs.mode == 'ref' }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
base_branch="test/e2e-commit-push-base-${{ github.run_id }}"
target_branch="test/e2e-commit-push-reset-${{ github.run_id }}"
git checkout -b "${base_branch}"
echo "base" > e2e-reset-base.txt
git add e2e-reset-base.txt
git commit -m "[E2E] base branch for reset"
git push origin "${base_branch}"
git checkout -b "${target_branch}" "${base_branch}"
echo "legacy" > e2e-reset-legacy.txt
git add e2e-reset-legacy.txt
git commit -m "[E2E] legacy target branch content"
git push origin "${target_branch}"
- name: Reset target branch using action
if: ${{ inputs.mode == 'ref' }}
id: reset
uses: devops-infra/action-commit-push@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
target_branch: test/e2e-commit-push-reset-${{ github.run_id }}
base_branch: test/e2e-commit-push-base-${{ github.run_id }}
reset_target_branch: "true"
force_with_lease: "true"
- name: Reset via docker image (preview)
if: ${{ inputs.mode == 'image' }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
echo "Image mode placeholder for devopsinfra/action-commit-push:${{ inputs.image_tag }}"
echo "Use ref mode for authoritative validation until image-mode harness is finalized."
- name: Verify branch reset effect
if: ${{ inputs.mode == 'ref' }}
run: |
test -n "${{ steps.reset.outputs.branch_name }}"
git fetch origin test/e2e-commit-push-reset-${{ github.run_id }}
git show origin/test/e2e-commit-push-reset-${{ github.run_id }}:e2e-reset-base.txt >/dev/null
if git show origin/test/e2e-commit-push-reset-${{ github.run_id }}:e2e-reset-legacy.txt >/dev/null 2>&1; then
echo "Expected legacy file to be removed after reset_target_branch=true"
exit 1
fi
- name: Cleanup - delete test branches
if: always()
run: |
git push origin --delete test/e2e-commit-push-reset-${{ github.run_id }} 2>/dev/null || true
git push origin --delete test/e2e-commit-push-base-${{ github.run_id }} 2>/dev/null || true
rebase-conflict-fails-when-strict:
name: Rebase conflict fails when fail_on_rebase_conflict=true
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Prepare conflicting branches
if: ${{ inputs.mode == 'ref' }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
base_branch="test/e2e-commit-push-conflict-base-${{ github.run_id }}"
target_branch="test/e2e-commit-push-conflict-target-${{ github.run_id }}"
git checkout -b "${base_branch}"
printf 'value=one\n' > e2e-rebase-conflict.txt
git add e2e-rebase-conflict.txt
git commit -m "[E2E] base commit"
git push origin "${base_branch}"
git checkout -b "${target_branch}" "${base_branch}"
printf 'value=target\n' > e2e-rebase-conflict.txt
git add e2e-rebase-conflict.txt
git commit -m "[E2E] target diverges"
git push origin "${target_branch}"
git checkout "${base_branch}"
printf 'value=base\n' > e2e-rebase-conflict.txt
git add e2e-rebase-conflict.txt
git commit -m "[E2E] base diverges"
git push origin "${base_branch}"
- name: Run action with strict rebase conflict handling
if: ${{ inputs.mode == 'ref' }}
id: strict
continue-on-error: true
uses: devops-infra/action-commit-push@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
target_branch: test/e2e-commit-push-conflict-target-${{ github.run_id }}
base_branch: test/e2e-commit-push-conflict-base-${{ github.run_id }}
fail_on_rebase_conflict: "true"
- name: Conflict via docker image (preview)
if: ${{ inputs.mode == 'image' }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
echo "Image mode placeholder for devopsinfra/action-commit-push:${{ inputs.image_tag }}"
echo "Use ref mode for authoritative validation until image-mode harness is finalized."
- name: Verify strict mode failure
if: ${{ inputs.mode == 'ref' }}
run: test "${{ steps.strict.outcome }}" = "failure"
- name: Cleanup - delete test branches
if: always()
run: |
git push origin --delete test/e2e-commit-push-conflict-target-${{ github.run_id }} 2>/dev/null || true
git push origin --delete test/e2e-commit-push-conflict-base-${{ github.run_id }} 2>/dev/null || true
amend-commit:
name: Amend previous commit with force-with-lease
needs: [preflight]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Create initial branch with commit
if: ${{ inputs.mode == 'ref' }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b test/e2e-commit-push-amend-${{ github.run_id }}
echo "v1" > e2e-amend-test.txt
git add e2e-amend-test.txt
git commit -m "E2E: initial commit for amend test"
git push origin test/e2e-commit-push-amend-${{ github.run_id }}
- name: Add more content to file
if: ${{ inputs.mode == 'ref' }}
run: echo "v2" >> e2e-amend-test.txt
- name: Amend commit keeping original message
if: ${{ inputs.mode == 'ref' }}
id: amend
uses: devops-infra/action-commit-push@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
amend: "true"
no_edit: "true"
force_with_lease: "true"
- name: Amend via docker image (preview)
if: ${{ inputs.mode == 'image' }}
run: |
if [ -z "${{ inputs.image_tag }}" ]; then
echo "image_tag is required when mode=image"
exit 1
fi
echo "Image mode placeholder for devopsinfra/action-commit-push:${{ inputs.image_tag }}"
echo "Use ref mode for authoritative validation until image-mode harness is finalized."
- name: Verify branch output
if: ${{ inputs.mode == 'ref' }}
run: |
echo "branch_name=${{ steps.amend.outputs.branch_name }}"
test -n "${{ steps.amend.outputs.branch_name }}"
- name: Cleanup - delete test branch
if: always()
run: git push origin --delete test/e2e-commit-push-amend-${{ github.run_id }} 2>/dev/null || true