@@ -398,3 +398,76 @@ jobs:
398
398
run : |
399
399
PATH=$PATH:$GITHUB_WORKSPACE/bin
400
400
yarn test:xs
401
+
402
+ linear-history :
403
+ runs-on : ubuntu-latest
404
+ if : >-
405
+ github.event_name == 'pull_request' &&
406
+ github.event.pull_request.draft == false &&
407
+ github.event.pull_request.base.ref == 'master' &&
408
+ !contains(github.event.pull_request.labels.*.name, 'bypass:linear-history')
409
+ steps :
410
+ - uses : actions/checkout@v4
411
+ with :
412
+ fetch-depth : 0
413
+ - shell : bash
414
+ env :
415
+ HEAD_SHA : ${{ github.event.pull_request.head.sha }}
416
+ HEAD_LABEL : ${{ github.event.pull_request.head.label }}
417
+ BASE_SHA : ${{ github.event.pull_request.base.sha }}
418
+ BASE_LABEL : ${{ github.event.pull_request.base.label }}
419
+ run : |
420
+ merge_commits=$(git rev-list --merges "$BASE_SHA".."$HEAD_SHA")
421
+
422
+ if [ -n "$merge_commits" ]; then
423
+ echo "Error: merge commits found in $BASE_LABEL..$HEAD_LABEL"
424
+
425
+ for merge_commit in $merge_commits; do
426
+ echo "$merge_commit"
427
+ done
428
+
429
+ exit 1
430
+ fi
431
+
432
+ fixup_commits=
433
+ for commit in $(git rev-list $BASE_SHA..$HEAD_SHA); do
434
+ case $(git show --pretty=format:%s -s $commit) in fixup\!*|squash\!*|amend\!*)
435
+ fixup_commits="$fixup_commits\n$commit"
436
+ ;;
437
+ esac
438
+ done
439
+
440
+ if [ -n "$fixup_commits" ]; then
441
+ echo "Error: fixup/squash/amend commits found in $BASE_LABEL..$HEAD_LABEL"
442
+ echo -e "$fixup_commits"
443
+ exit 1
444
+ fi
445
+
446
+ no-fixup-commits :
447
+ runs-on : ubuntu-latest
448
+ if : >-
449
+ github.event_name == 'pull_request' &&
450
+ github.event.pull_request.draft == false &&
451
+ github.event.pull_request.base.ref == 'master' &&
452
+ !contains(github.event.pull_request.labels.*.name, 'bypass:linear-history')
453
+
454
+ env :
455
+ HEAD_SHA : ${{ github.event.pull_request.head.sha }}
456
+ BASE_SHA : ${{ github.event.pull_request.base.sha }}
457
+
458
+ steps :
459
+ - name : Checkout code
460
+ uses : actions/checkout@v4
461
+ with :
462
+ fetch-depth : 0
463
+ - name : Check for fixup commits
464
+ id : fixup-commits
465
+ run : |
466
+ if ! git merge-base --is-ancestor "$BASE_SHA" "$HEAD_SHA"; then
467
+ echo "PR is not up to date with target branch, skipping fixup commit check"
468
+ elif [[ $(git rev-list "$BASE_SHA".."$HEAD_SHA" --grep="^\(fixup\|amend\|squash\)! " | wc -l) -eq 0 ]]; then
469
+ echo "No fixup/amend/squash commits found in commit history"
470
+ else
471
+ echo "fixup/amend/squash commits found in commit history"
472
+ exit 1
473
+ fi
0 commit comments