3434 pull-requests : read
3535 outputs :
3636 should_run : ${{ steps.default.outputs.should_run || steps.changed.outputs.any_modified }}
37+ base_sha : ${{ steps.comparison.outputs.base_sha }}
3738 steps :
3839 - id : default
3940 if : github.event_name != 'pull_request'
@@ -42,12 +43,27 @@ jobs:
4243 - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
4344 if : github.event_name == 'pull_request'
4445 with :
46+ ref : ${{ github.sha }}
47+ # Include both parents of the exact PR merge commit, even on reruns.
48+ fetch-depth : 2
4549 persist-credentials : false
4650
51+ - name : Resolve PR baseline
52+ id : comparison
53+ if : github.event_name == 'pull_request'
54+ run : |
55+ git rev-parse --verify HEAD^2 >/dev/null
56+ base_sha=$(git rev-parse --verify HEAD^1)
57+ echo "base_sha=$base_sha" >> "$GITHUB_OUTPUT"
58+ echo "Trivy comparison: $base_sha -> $(git rev-parse HEAD)"
59+
4760 - id : changed
4861 if : github.event_name == 'pull_request'
4962 uses : tj-actions/changed-files@aa08304bd477b800d468db44fe10f6c61f7f7b11 # v42.1.0
5063 with :
64+ base_sha : ${{ steps.comparison.outputs.base_sha }}
65+ sha : ${{ github.sha }}
66+ output_renamed_files_as_deleted_and_added : true
5167 # `any_modified` covers deletions, which `any_changed` omits, and a
5268 # failed diff has to fail the job: both otherwise report no relevant
5369 # change, and removing the scanner or a value fixture would skip the
7389 runs-on : ubuntu-latest
7490 timeout-minutes : 30
7591 env :
76- BASE_REF : ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || inputs.base_sha }}
92+ BASE_REF : ${{ needs.changes.outputs.base_sha || github.event.merge_group.base_sha || inputs.base_sha }}
7793 HEAD_REF : ${{ inputs.head_sha || github.sha }}
7894 defaults :
7995 run :
0 commit comments