From a571ebc2780dc97cc9208ca14a8b80a6ae5b88ca Mon Sep 17 00:00:00 2001 From: TheRedDaemon <66257843+TheRedDaemon@users.noreply.github.com> Date: Thu, 15 Jan 2026 21:47:55 +0100 Subject: [PATCH] [PROJECT] cpp-linter action runs for all files, but linst only if relevant changed --- .github/workflows/cpp-linter.yml | 35 +++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 2f6a275..1f3e51e 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -5,10 +5,8 @@ on: pull_request: branches: [main] types: [opened, reopened, synchronize, ready_for_review] - paths: ['**.c', '**.cpp', '**.h', '**.hpp', '**.cxx', '**.hxx', '**.cc', '**.hh', '**CMakeLists.txt', 'meson.build', '**.cmake'] push: branches: [main] - paths: ['**.c', '**.cpp', '**.h', '**.hpp', '**.cxx', '**.hxx', '**.cc', '**.hh', '**CMakeLists.txt', 'meson.build', '**.cmake'] jobs: cpp-linter: @@ -20,10 +18,31 @@ jobs: steps: - uses: actions/checkout@v5 + # Detect if any relevant files changed + - name: Detect relevant files + id: filter + uses: dorny/paths-filter@v3 + with: + filters: | + cpp: + - '**/*.c' + - '**/*.cpp' + - '**/*.h' + - '**/*.hpp' + - '**/*.cxx' + - '**/*.hxx' + - '**/*.cc' + - '**/*.hh' + - '**/CMakeLists.txt' + - 'meson.build' + - '**/*.cmake' + # ... optionally setup build env to create a compilation database - - uses: cpp-linter/cpp-linter-action@v2 + - name: Run cpp-linter id: linter + uses: cpp-linter/cpp-linter-action@v2 + if: steps.filter.outputs.cpp == 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -38,6 +57,12 @@ jobs: # disable file annotations, the thread comment should be the response file-annotations: false - - name: Fail fast?! - if: steps.linter.outputs.checks-failed > 0 + # Fail the job only if the linter ran and found issues + - name: Fail fast if linter failed + if: steps.filter.outputs.cpp == 'true' && steps.linter.outputs.checks-failed > 0 run: exit 1 + + # Optional: print a message if no relevant files changed + - name: Skip message + if: steps.filter.outputs.cpp != 'true' + run: echo "No relevant C/C++/CMake files changed — cpp-linter skipped"