Skip to content

Commit

Permalink
chore(ci): fix failure condition when modified files are empty
Browse files Browse the repository at this point in the history
Signed-off-by: Kotaro Yoshimoto <pythagora.yoshimoto@gmail.com>
  • Loading branch information
HansRobo authored Jun 26, 2024
1 parent 641796b commit 43fb48e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/cppcheck-differential.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,20 @@ jobs:
run: git fetch origin ${{ github.base_ref }}
shell: bash

- name: Get changed files
id: changed-files
- name: Get modified files
id: get-modified-files
run: |
git diff --name-only "origin/${{ github.base_ref }}"...HEAD > changed_files.txt
cat changed_files.txt
echo "changed_files=$(git diff --name-only "origin/${{ github.base_ref }}"...HEAD | grep -E '\.(cpp|hpp)$' | tr '\n' ' ' || true)" >> $GITHUB_OUTPUT
shell: bash

- name: Run Cppcheck on changed files
continue-on-error: true
id: cppcheck
run: |
files=$(cat changed_files.txt | grep -E '\.(cpp|hpp)$' || true)
if [ -n "$files" ]; then
echo "Running Cppcheck on changed files: $files"
cppcheck --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --suppressions-list=.cppcheck_suppressions $files 2> cppcheck-report.txt
echo "Running Cppcheck on changed files: ${{ steps.get-modified-files.outputs.changed_files }}"
cppcheck --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --suppressions-list=.cppcheck_suppressions ${{ steps.get-modified-files.outputs.changed_files }} 2> cppcheck-report.txt
else
echo "No C++ files changed."
touch cppcheck-report.txt
Expand All @@ -63,5 +62,5 @@ jobs:
path: cppcheck-report.txt

- name: Fail the job if Cppcheck failed
if: steps.cppcheck.outcome == 'failure'
if: ${{ steps.get-modified-files.outputs.changed_files != '' && steps.cppcheck.outcome == 'failure' }}
run: exit 1

0 comments on commit 43fb48e

Please sign in to comment.