janitor

janitor
git clone https://git.prime8.dev/janitor.git
Log | Files | Refs | README | LICENSE

iwyu.yaml (4395B)


      1 name: iwyu
      2 
      3 on:
      4   push:
      5     branches:
      6       - master
      7       - iwyu-2
      8   pull_request:
      9     branches:
     10       - master
     11 
     12   workflow_dispatch:
     13 
     14 concurrency:
     15   group: iwyu-${{ github.ref }}
     16   cancel-in-progress: true
     17 
     18 # References
     19 # https://github.com/official-stockfish/Stockfish/blob/master/.github/workflows/iwyu.yml
     20 # https://github.com/acts-project/acts/actions/runs/8588671882/workflow
     21 # https://github.com/acts-project/acts/tree/main/CI/iwyu
     22 
     23 jobs:
     24   iwyu:
     25     if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa'
     26     permissions:
     27       contents: write  # for stefanzweifel/git-auto-commit-action to push code in repo
     28     name: Include what you use
     29     runs-on: ${{ matrix.os }}
     30     strategy:
     31       fail-fast: false
     32       matrix:
     33         os: [ubuntu-latest]
     34 
     35     steps:
     36       - uses: actions/checkout@v4
     37         with:
     38           fetch-depth: 0
     39 
     40       - name: Download required linux packages
     41         shell: bash
     42         run: |
     43           echo "GITHUB_WORKSPACE: $GITHUB_WORKSPACE"
     44           sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main'
     45           wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
     46           sudo apt update
     47           sudo apt install -y libclang-17-dev clang-17 libc++-17-dev
     48 
     49       - name: Display llvm
     50         shell: bash
     51         run: |
     52           ls -lh /usr/lib/*llvm*
     53 
     54           ls -lh /usr/bin/*clang*
     55 
     56       - name: cache-iwyu
     57         id: cache-iwyu
     58         uses: actions/cache@v4
     59         with:
     60           path: /tmp/iwyu-install
     61           key: iwyu-install-2024-04-13
     62 
     63       - name: Get IWYU source
     64         if: steps.cache-iwyu.outputs.cache-hit != 'true'
     65         uses: actions/checkout@v4
     66         with:
     67           repository: include-what-you-use/include-what-you-use
     68           ref: clang_17
     69           path: iwyu
     70 
     71       - name: Build IWYU
     72         if: steps.cache-iwyu.outputs.cache-hit != 'true'
     73         shell: bash
     74         run: |
     75           mkdir iwyu-build iwyu-install
     76           cmake -B iwyu-build -S iwyu -DCMAKE_PREFIX_PATH=/usr/lib/llvm-17 -DCMAKE_INSTALL_PREFIX=/tmp/iwyu-install
     77           cmake --build iwyu-build --target install
     78 
     79           ls -lh /tmp/iwyu-install
     80           tree /tmp/iwyu-install
     81 
     82           /tmp/iwyu-install/bin/include-what-you-use --version
     83 
     84       - name: setup path
     85         shell: bash
     86         run: |
     87           echo "/tmp/iwyu-install/bin"  >> "$GITHUB_PATH"
     88 
     89       - name: display include what you use version
     90         shell: bash
     91         run: |
     92           include-what-you-use --version
     93           which include-what-you-use
     94 
     95           include-what-you-use --help
     96 
     97       - uses: actions/upload-artifact@v4
     98         with:
     99           name: iwyu-install
    100           path: /tmpiwyu-install/*
    101 
    102       - name: Check
    103         shell: bash
    104         run: |
    105           mkdir build
    106           cd build
    107 
    108           cmake \
    109             -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
    110             ..
    111 
    112       - name: Run iwyu_tool.py
    113         shell: bash
    114         run: |
    115           python3 /tmp/iwyu-install/bin/iwyu_tool.py -p build/ -j2 | tee iwyu-output.txt
    116 
    117       - name: Filter IWYU output
    118         shell: bash
    119         run: |
    120           python3 .github/scripts/filter.py .github/scripts/filter.yaml iwyu-output.txt iwyu-filtered.txt
    121 
    122       - name: Show IWYU output
    123         shell: bash
    124         run: |
    125           cat iwyu-output.txt
    126 
    127       - name: Show filtered IWYU output
    128         shell: bash
    129         run: |
    130           cat iwyu-filtered.txt
    131 
    132       - name: Upload IWYU output
    133         uses: actions/upload-artifact@v4
    134         with:
    135           name: iwyu
    136           path: |
    137             iwyu-output.txt
    138             iwyu-filtered.txt
    139 
    140       - name: Apply iwyu
    141         shell: bash
    142         run: |
    143           git status
    144           python3 /tmp/iwyu-install/bin/fix_includes.py < iwyu-filtered.txt
    145 
    146           rm -rf iwyu*
    147 
    148       - name: Show diff
    149         shell: bash
    150         run: |
    151           git status
    152 
    153           git diff
    154           git diff > a.diff
    155           # Download a.diff
    156           # Run
    157           #   git apply a.diff
    158 
    159       - name: Upload IWYU output
    160         uses: actions/upload-artifact@v4
    161         with:
    162           name: diff
    163           path: |
    164             a.diff
    165 
    166       # https://github.com/stefanzweifel/git-auto-commit-action
    167       - uses: stefanzweifel/git-auto-commit-action@v5
    168         if: false
    169         with:
    170           file_pattern: '*.h *.cc'
    171           commit_message: "apply iwyu changes"