@@ -20,19 +20,31 @@ jobs:
2020 runs-on : ubuntu-24.04
2121 name : API Diff Check
2222 steps :
23- # Checkout PR code for static analysis only
23+ # Check if PR has conflicts. When conflicts exist, the merge commit becomes
24+ # frozen at an old state and apidiff cannot run correctly.
25+ # Note: mergeable can be true/false/null (when status is being computed)
26+ - name : Check for merge conflicts
27+ if : ${{ github.event.pull_request.mergeable != true }}
28+ run : |
29+ echo "::error::This PR has merge conflicts. Please resolve conflicts before running apidiff."
30+ exit 1
31+
32+ # Checkout PR merge commit to compare against base branch
33+ # This ensures we compare the actual merge result with the base branch,
34+ # avoiding false positives when PR is not rebased with latest main
2435 - name : Checkout
2536 uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2637 with :
27- ref : ${{ github.event.pull_request.head.sha }}
38+ ref : refs/pull/ ${{ github.event.pull_request.number }}/merge
2839
2940 - name : Set up Go
3041 uses : actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
3142 with :
3243 go-version-file : go.mod
3344 cache : false
3445
35- # Ensure the base commit exists locally when checkout uses depth=1 (default).
46+ # Ensure the base commit exists locally for go-apidiff to compare against.
47+ # Even though we checkout the merge commit, go-apidiff needs the base ref to exist.
3648 - name : Fetch base commit
3749 run : |
3850 BASE_REF="${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}"
@@ -129,4 +141,4 @@ jobs:
129141 } catch (error) {
130142 core.error(`Failed to request trivy-premium reviewers: ${error.message}`);
131143 throw error;
132- }
144+ }
0 commit comments