Merge pull request #821 from mpusz/codata-complete-coverage #1120
This file contains hidden or 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
| # The MIT License (MIT) | |
| # | |
| # Copyright (c) 2018 Mateusz Pusz | |
| # | |
| # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| # of this software and associated documentation files (the "Software"), to deal | |
| # in the Software without restriction, including without limitation the rights | |
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| # copies of the Software, and to permit persons to whom the Software is | |
| # furnished to do so, subject to the following conditions: | |
| # | |
| # The above copyright notice and this permission notice shall be included in all | |
| # copies or substantial portions of the Software. | |
| # | |
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| # SOFTWARE. | |
| name: clang-tidy CI | |
| on: | |
| push: | |
| branches: | |
| - "**" | |
| paths: | |
| - "src/**" | |
| - "test/**" | |
| - "example/**" | |
| - "cmake/**" | |
| - "CMakeLists.txt" | |
| - "conanfile.py" | |
| - ".clang-tidy" | |
| - ".github/generate-job-matrix.py" | |
| - ".github/job_matrix.py" | |
| - ".github/workflows/ci-clang-tidy.yml" | |
| pull_request: | |
| branches: | |
| - "**" | |
| paths: | |
| - "src/**" | |
| - "test/**" | |
| - "example/**" | |
| - "cmake/**" | |
| - "CMakeLists.txt" | |
| - "conanfile.py" | |
| - ".clang-tidy" | |
| - ".github/generate-job-matrix.py" | |
| - ".github/job_matrix.py" | |
| - ".github/workflows/ci-clang-tidy.yml" | |
| workflow_dispatch: | |
| inputs: | |
| matrix-seed: | |
| description: The random seed for the subset of the full test-matrix to be run (set to '0' to select one at random) | |
| required: true | |
| type: number | |
| default: 0 | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| generate-matrix: | |
| name: "Generate build matrix for ${{ github.workflow }}" | |
| # A PR whose head branch lives in this repository is already covered by the `push` event above, | |
| # whose path filters match only the commits just pushed - unlike `pull_request`, which matches | |
| # them against the whole base...head diff and so re-runs everything for a docs-only push. Fork | |
| # PRs never fire `push` here, so they are what this event exists to serve. | |
| if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| seed: ${{ steps.set-matrix.outputs.seed }} | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: 3.x | |
| - id: set-matrix | |
| run: python .github/generate-job-matrix.py --preset clang-tidy --seed ${{ inputs.matrix-seed || 0 }} --debug combinations counts | |
| - name: Generate job summary | |
| if: always() | |
| env: | |
| MATRIX_JSON: ${{ steps.set-matrix.outputs.matrix }} | |
| MATRIX_SEED: ${{ steps.set-matrix.outputs.seed }} | |
| run: python .github/generate-matrix-summary.py >> $GITHUB_STEP_SUMMARY | |
| build: | |
| name: "${{ matrix.config-summary-str }}" | |
| runs-on: ${{ matrix.toolchain.os }} | |
| needs: generate-matrix | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: ${{fromJson(needs.generate-matrix.outputs.matrix)}} | |
| env: | |
| CC: ${{ matrix.toolchain.compiler.cc }} | |
| CXX: ${{ matrix.toolchain.compiler.cxx }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - run: echo "cache_id=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_ENV | |
| - name: Cache Conan data | |
| uses: actions/cache@v5 | |
| if: always() | |
| env: | |
| cache-name: cache-conan-data | |
| with: | |
| path: ~/.conan2/p | |
| key: clang-tidy-${{ matrix.toolchain.os }}-${{ matrix.formatting }}-${{ matrix.contracts }}-${{ matrix.toolchain.compiler.type }}-${{ matrix.toolchain.lib }}-${{ matrix.build_type }}-${{ matrix.toolchain.compiler.version }}-${{ matrix.std }}-${{ env.cache_id }} | |
| restore-keys: | | |
| clang-tidy-${{ matrix.toolchain.os }}-${{ matrix.formatting }}-${{ matrix.contracts }}-${{ matrix.toolchain.compiler.type }}-${{ matrix.toolchain.lib }}-${{ matrix.build_type }}-${{ matrix.toolchain.compiler.version }}-${{ matrix.std }}- | |
| clang-tidy-${{ matrix.toolchain.os }}-${{ matrix.formatting }}-${{ matrix.contracts }}-${{ matrix.toolchain.compiler.type }}-${{ matrix.toolchain.lib }}-${{ matrix.build_type }}-${{ matrix.toolchain.compiler.version }}- | |
| clang-tidy-${{ matrix.toolchain.os }}-${{ matrix.formatting }}-${{ matrix.contracts }}-${{ matrix.toolchain.compiler.type }}-${{ matrix.toolchain.lib }}-${{ matrix.build_type }}- | |
| clang-tidy-${{ matrix.toolchain.os }}-${{ matrix.formatting }}-${{ matrix.contracts }}-${{ matrix.toolchain.compiler.type }}-${{ matrix.toolchain.lib }}- | |
| clang-tidy-${{ matrix.toolchain.os }}-${{ matrix.formatting }}-${{ matrix.contracts }}-${{ matrix.toolchain.compiler.type }}- | |
| clang-tidy-${{ matrix.toolchain.os }}-${{ matrix.formatting }}-${{ matrix.contracts }}- | |
| clang-tidy-${{ matrix.toolchain.os }}-${{ matrix.formatting }}- | |
| clang-tidy-${{ matrix.toolchain.os }}- | |
| - uses: hendrikmuhs/ccache-action@v1.2.22 | |
| if: runner.os == 'Linux' | |
| with: | |
| key: ${{ matrix.toolchain.os }}-${{ matrix.formatting }}-${{ matrix.contracts }}-${{ matrix.toolchain.compiler.type }}-${{ matrix.toolchain.lib }}-${{ matrix.build_type }}-${{ matrix.toolchain.compiler.version }}-${{ matrix.std }} | |
| max-size: 50M | |
| - name: Install Clang | |
| if: matrix.toolchain.compiler.type == 'CLANG' | |
| shell: bash | |
| working-directory: ${{ env.HOME }} | |
| run: | | |
| wget https://apt.llvm.org/llvm.sh | |
| chmod +x llvm.sh | |
| sudo ./llvm.sh ${{ matrix.toolchain.compiler.version }} | |
| sudo apt install -y clang-tidy-${{ matrix.toolchain.compiler.version }} | |
| - name: Install Libc++ | |
| if: matrix.toolchain.compiler.type == 'CLANG' && matrix.toolchain.lib == 'libc++' | |
| shell: bash | |
| run: | | |
| sudo apt install -y libc++-${{ matrix.toolchain.compiler.version }}-dev libc++abi-${{ matrix.toolchain.compiler.version }}-dev libunwind-${{ matrix.toolchain.compiler.version }}-dev | |
| - name: Fix libc++ std.cppm path for CMake | |
| if: matrix.import_std == 'True' && matrix.toolchain.compiler.type == 'CLANG' | |
| shell: bash | |
| run: | | |
| sudo mkdir -p /lib/share | |
| sudo ln -sfn /usr/lib/llvm-${{ matrix.toolchain.compiler.version }}/share/libc++ /lib/share/libc++ | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: 3.x | |
| - name: Install Ninja | |
| shell: bash | |
| run: | | |
| pip install -U ninja | |
| - name: Install Conan | |
| shell: bash | |
| run: | | |
| pip install -U conan | |
| - name: Configure Conan | |
| shell: bash | |
| run: | | |
| conan profile detect --force | |
| conan profile show -pr default | |
| - name: Install Conan dependencies | |
| shell: bash | |
| run: | | |
| conan install . -b missing ${{ matrix.conan-settings }} \ | |
| -c tools.cmake.cmaketoolchain:generator="Ninja Multi-Config" \ | |
| -c user.mp-units.build:all=True -c user.mp-units.analyze:clang-tidy=True -c tools.build:skip_test=True \ | |
| ${{ matrix.conan-args }} | |
| - name: Print tool versions | |
| shell: bash | |
| run: | | |
| source build/generators/conanbuild.sh | |
| ${CXX} --version | |
| clang-tidy-${{ matrix.toolchain.compiler.version }} --version | |
| cmake --version 2>&1 || true | |
| ninja --version 2>&1 || true | |
| conan --version | |
| python3 --version | |
| - name: Run clang-tidy | |
| shell: bash | |
| run: | | |
| conan build . -b missing ${{ matrix.conan-settings }} \ | |
| -c tools.cmake.cmaketoolchain:generator="Ninja Multi-Config" \ | |
| -c user.mp-units.build:all=True -c user.mp-units.analyze:clang-tidy=True -c tools.build:skip_test=True \ | |
| ${{ matrix.conan-args }} 2>&1 | tee /tmp/clang-tidy.log | |
| exit ${PIPESTATUS[0]} | |
| - name: Emit clang-tidy annotations | |
| if: failure() | |
| shell: bash | |
| run: | | |
| python3 - << 'EOF' | |
| import re, pathlib, sys | |
| workspace = "${{ github.workspace }}/" | |
| pattern = re.compile(r'^(.+):(\d+):(\d+): (warning|error): (.+?) \[(.+)\]$') | |
| seen = set() | |
| for line in pathlib.Path("/tmp/clang-tidy.log").read_text().splitlines(): | |
| m = pattern.match(line) | |
| if not m: | |
| continue | |
| file, lineno, col, level, msg, check = m.groups() | |
| key = (file, lineno, col, check) | |
| if key in seen: | |
| continue | |
| seen.add(key) | |
| rel = file.removeprefix(workspace) | |
| print(f"::{level} file={rel},line={lineno},col={col},title=clang-tidy ({check})::{msg}") | |
| EOF | |
| - name: Clean Conan cache before backup | |
| shell: bash | |
| run: | | |
| conan remove *#~latest --confirm | |
| conan remove *:*#~latest --confirm | |
| conan cache clean "*" -s -b -d | |
| - name: Generate clang-tidy summary | |
| if: failure() | |
| shell: bash | |
| env: | |
| CONAN_SETTINGS: ${{ matrix.conan-settings }} | |
| CONAN_ARGS: ${{ matrix.conan-args }} | |
| run: | | |
| echo "## ⚠️ Clang-Tidy Issues: ${{ matrix.config-summary-str }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Local repro** (in the provided '.devcontainer' or GitHub CodeSpaces environment):" >> $GITHUB_STEP_SUMMARY | |
| echo '```sh' >> $GITHUB_STEP_SUMMARY | |
| echo "conan build . -b missing ${CONAN_SETTINGS} -c user.mp-units.build:all=True -c user.mp-units.analyze:clang-tidy=True -c tools.build:skip_test=True ${CONAN_ARGS}" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY |