Static checks #44
This file contains 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
# SPDX-FileCopyrightText: 2024 OGL authors | |
# | |
# SPDX-License-Identifier: GPL-3.0-or-later | |
name: Static checks | |
run-name: Static checks | |
on: | |
pull_request: | |
types: [opened, synchronize] | |
jobs: | |
build-compilation-db: | |
name: Build with IWYU | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Add clang repo | |
run: | | |
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main' | |
wget https://apt.llvm.org/llvm-snapshot.gpg.key | |
sudo apt-key add llvm-snapshot.gpg.key | |
- name: Install dependencies | |
run: | | |
sudo apt update | |
sudo apt install \ | |
ninja-build \ | |
iwyu \ | |
clang-16 \ | |
libomp-16-dev | |
- name: Create Compilation Database | |
run: | | |
cmake --preset ninja-cpuonly-release \ | |
-DCMAKE_CXX_COMPILER=clang++-16 \ | |
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON | |
cmake --build --preset ninja-cpuonly-release | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: build-artifact | |
path: build | |
clang-tidy-check: | |
name: Clang-tidy Check | |
runs-on: ubuntu-latest | |
needs: [build-compilation-db] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Add clang repo | |
run: | | |
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main' | |
wget https://apt.llvm.org/llvm-snapshot.gpg.key | |
sudo apt-key add llvm-snapshot.gpg.key | |
- name: Install dependencies | |
run: | | |
sudo apt update | |
sudo apt install \ | |
clang-tidy-16 \ | |
libomp-16-dev | |
- uses: actions/download-artifact@v4 | |
with: | |
name: build-artifact | |
path: build | |
- name: Run clang-tidy | |
run: | | |
# Create list of .cpp files belonging to this repository | |
git ls-files | grep -E "\.(cpp)" > pattern | |
# Create list of .cpp files that are in this repository and part of the | |
# compilation database | |
# also filters out " at the begin and end of the filename | |
jq ".[] | .file" build/ReleaseAll/compile_commands.json \ | |
| sed 's/^"\(.*\)"$/\1/' \ | |
| grep -F -f pattern - > files | |
# run clang-tidy on all specified files | |
clang-tidy-16 --fix --extra-arg=-w -p build/ReleaseAll $(cat files) | |
- name: Check for fixes | |
run: | | |
if [[ $(git ls-files -m | wc -l) -eq 0 ]]; then | |
exit 0 | |
fi | |
echo "There are fixes available from clang-tidy." | |
echo "Please use your local clang-tidy or apply the following patch:" | |
git diff -p | |
exit 1 | |
formatting-check: | |
name: Formatting check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run clang-format style check for C/C++/Protobuf programs. | |
uses: jidicula/[email protected] | |
with: | |
clang-format-version: '17' | |
check-path: '.' | |
fallback-style: 'Mozilla' # optional | |
- name: check for todo fixme note | |
run: | | |
NTODOS="$(grep -r 'TODO DONT MERGE' --exclude-dir=.github | wc -l)" | |
echo "Found $NTODOS TODO DONT MERGE notes" | |
! grep -q -r "TODO DONT MERGE" --exclude-dir=.github | |
typos-check: | |
name: Spell check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check for typos | |
uses: crate-ci/typos@master | |
check-spdx-headers: | |
name: License header check | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout to repository | |
uses: actions/checkout@v4 | |
- name: install reuse linter | |
run: | | |
pip3 install reuse | |
- name: Execute reuse linter | |
run: | | |
reuse lint | |
changelog: | |
name: Changelog check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: dangoslen/changelog-enforcer@v3 | |
with: | |
changeLogPath: CHANGELOG.md |