diff options
author | Bernd Schubert <bernd@bsbernd.com> | 2025-01-29 10:46:18 +0100 |
---|---|---|
committer | Bernd Schubert <bernd@bsbernd.com> | 2025-01-29 11:11:04 +0100 |
commit | 64de51de4909eb7b68e982ab9922eb24dda4899e (patch) | |
tree | 817f6fa4982dbbb1649ac4613432d36f3bc6b873 /.github | |
parent | ba7beb21f63e91e22e877017ec6b359b5f8ece00 (diff) | |
download | libfuse-64de51de4909eb7b68e982ab9922eb24dda4899e.tar.gz |
github actions: Add an include-what-you-need check
Probably lots of issues right now, so let's fix it step by step
by only checking modified files - new PRs should fix their
modified files.
Signed-off-by: Bernd Schubert <bernd@bsbernd.com>
Diffstat (limited to '.github')
-rw-r--r-- | .github/workflows/iwyi-check.yml | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/.github/workflows/iwyi-check.yml b/.github/workflows/iwyi-check.yml new file mode 100644 index 0000000..3751f35 --- /dev/null +++ b/.github/workflows/iwyi-check.yml @@ -0,0 +1,51 @@ +# check for uneeded header includes of modified files +# False positives can be avoided with +# #include "some_include.h" // IWYU pragma: keep + +name: IWYU Check + +on: + pull_request: + branches: [ main ] + paths: + - '**.cpp' + - '**.hpp' + - '**.c' + - '**.h' + +jobs: + iwyu-check: + name: Include What You Use Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 + + - name: Install IWYU + run: | + sudo apt-get update + sudo apt-get install -y iwyu + + - name: Get changed files + id: changed-files + run: | + git fetch origin ${{ github.base_ref }} + base_commit=$(git merge-base FETCH_HEAD ${{ github.event.pull_request.head.sha }}) + changed_files=$(git diff --name-only $base_commit HEAD | grep -E '\.(cpp|hpp|c|h)$' || true) + echo "files=$changed_files" >> $GITHUB_OUTPUT + + - name: Run IWYU checks on changed files + if: steps.changed-files.outputs.files != '' + run: | + echo "${{ steps.changed-files.outputs.files }}" | while read -r file; do + if [ -f "$file" ]; then + echo "Checking $file..." + iwyu -Xiwyu --mapping_file=iwyu.imp "$file" 2>&1 || true + fi + done | tee iwyu_output.txt + if grep -q "should add these lines:" iwyu_output.txt || \ + grep -q "should remove these lines:" iwyu_output.txt; then + echo "IWYU checks failed. Please fix the includes in the affected files." + exit 1 + fi |