chore(ci): fix failure condition when modified files are empty #317
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: cppcheck-differential | |
on: | |
pull_request: | |
jobs: | |
cppcheck-differential: | |
runs-on: ubuntu-latest | |
steps: | |
- 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: | | |
sudo apt-get update | |
sudo apt-get install -y git | |
# cppcheck from apt does not yet support --check-level args, and thus install from snap | |
- name: Install Cppcheck from snap | |
run: | | |
sudo snap install cppcheck | |
- name: Fetch the base branch with enough history for a common merge-base commit | |
run: git fetch origin ${{ github.base_ref }} | |
shell: bash | |
- name: Get changed files (existing files only) | |
id: get-changed-files | |
run: | | |
echo "changed-files=$(git diff --name-only "origin/${{ github.base_ref }}"...HEAD | grep -E '\.(cpp|hpp)$' | while read -r file; do [ -e "$file" ] && echo -n "$file "; done)" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Run Cppcheck on changed files | |
if: ${{ steps.get-changed-files.outputs.changed-files != '' }} | |
continue-on-error: true | |
id: cppcheck | |
run: | | |
echo "Running Cppcheck on changed files: ${{ steps.get-changed-files.outputs.changed-files }}" | |
cppcheck --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --suppressions-list=.cppcheck_suppressions ${{ steps.get-changed-files.outputs.changed-files }} 2> cppcheck-report.txt | |
shell: bash | |
- name: Show cppcheck-report result | |
if: ${{ steps.get-changed-files.outputs.changed-files != '' }} | |
run: | | |
cat cppcheck-report.txt | |
- name: Upload Cppcheck report | |
if: ${{ steps.get-changed-files.outputs.changed-files != '' }} | |
uses: actions/upload-artifact@v2 | |
with: | |
name: cppcheck-report | |
path: cppcheck-report.txt | |
- name: Fail the job if Cppcheck failed | |
if: ${{ steps.get-changed-files.outputs.changed-files != '' && steps.cppcheck.outcome == 'failure' }} | |
run: exit 1 |