diff --git a/.github/workflows/cppcheck-differential.yaml b/.github/workflows/cppcheck-differential.yaml index 914abd7df86ea..6cd9ebc21454e 100644 --- a/.github/workflows/cppcheck-differential.yaml +++ b/.github/workflows/cppcheck-differential.yaml @@ -8,8 +8,14 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 + - name: Set PR fetch depth + run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}" + + - name: Checkout PR branch and all PR commits + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: ${{ env.PR_FETCH_DEPTH }} - name: Install dependencies run: | @@ -29,12 +35,16 @@ jobs: make -j $(nproc) sudo make install + - name: Fetch the base branch with enough history for a common merge-base commit + run: git fetch origin ${{ inputs.base-ref }} + shell: bash + - name: Get changed files id: changed-files run: | - git fetch origin ${{ github.base_ref }} --depth=1 - git diff --name-only FETCH_HEAD ${{ github.sha }} > changed_files.txt + git diff --name-only "origin/${{ inputs.base-ref }}"...HEAD > changed_files.txt cat changed_files.txt + shell: bash - name: Run Cppcheck on changed files continue-on-error: true