|
| 1 | +name: Fail on Malformed Commits in PR Branch |
| 2 | + |
| 3 | +# brazenly copied from ArduPilot's test_branch_conventions.yml |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + types: [opened, synchronize, reopened] |
| 8 | + |
| 9 | +jobs: |
| 10 | + check-merge-commits: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Harden the runner (Audit all outbound calls) |
| 15 | + uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2 |
| 16 | + with: |
| 17 | + egress-policy: audit |
| 18 | + |
| 19 | + - name: Checkout PR branch |
| 20 | + uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 21 | + with: |
| 22 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 23 | + ref: ${{ github.event.pull_request.head.ref }} |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Fetch base branch |
| 27 | + run: | |
| 28 | + git remote -v |
| 29 | + git remote add upstream ${{ github.event.pull_request.base.repo.clone_url }} |
| 30 | + git fetch upstream ${{ github.base_ref }} |
| 31 | + git show upstream/${{ github.base_ref }} |
| 32 | +
|
| 33 | + - name: Check for merge commits in PR branch |
| 34 | + run: | |
| 35 | + # Find merge-base between base branch and (rebased) PR branch |
| 36 | + echo "Merge target is origin/${{ github.base_ref }}" |
| 37 | + echo "github.event.pull_request.base.ref=${{ github.event.pull_request.base.ref }} " |
| 38 | +
|
| 39 | + # Look for merge commits in PR branch only |
| 40 | + MERGE_COMMITS=$(git log upstream/${{ github.base_ref }}..HEAD --merges --oneline) |
| 41 | + echo "Merge commits:" |
| 42 | + echo "$MERGE_COMMITS" |
| 43 | +
|
| 44 | + if [[ -n "$MERGE_COMMITS" ]]; then |
| 45 | + echo "❌ Merge commits detected in the PR branch (not allowed):" |
| 46 | + echo "Please see https://github.com/ArduPilot/MethodicConfigurator/blob/master/CONTRIBUTING.md" |
| 47 | + exit 1 |
| 48 | + else |
| 49 | + echo "✅ No merge commits found in the PR branch." |
| 50 | + fi |
| 51 | +
|
| 52 | + # Look for fixup! commits in PR branch only |
| 53 | + COMMITS=$(git log upstream/${{ github.base_ref }}..HEAD --oneline) |
| 54 | + echo "Commits:" |
| 55 | + echo "$COMMITS" |
| 56 | +
|
| 57 | + if [[ "$COMMITS" == *"fixup!"* ]]; then |
| 58 | + echo "❌ fixup commits detected in the PR branch (not allowed):" |
| 59 | + echo "$COMMITS" |
| 60 | + echo "Please see https://github.com/ArduPilot/MethodicConfigurator/blob/master/CONTRIBUTING.md" |
| 61 | + exit 1 |
| 62 | + else |
| 63 | + echo "✅ No fixup commits found in the PR branch." |
| 64 | + fi |
0 commit comments