Static checks #179
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 | |
defaults: | |
run: | |
shell: bash -o pipefail -i {0} | |
on: | |
pull_request: | |
types: [opened, synchronize] | |
env: | |
USER: user | |
BUILD_TYPE: Release | |
OMPI_ALLOW_RUN_AS_ROOT: 1 | |
OMPI_ALLOW_RUN_AS_ROOT_CONFIRM: 1 | |
jobs: | |
build-compilation-db: | |
name: Build with IWYU | |
runs-on: ubuntu-latest | |
container: greole/ofbase | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: | | |
apt update | |
apt install -y \ | |
ninja-build \ | |
libomp-dev \ | |
iwyu | |
- name: Create Compilation Database | |
run: | | |
source /root/OpenFOAM/openfoam/etc/bashrc | |
cmake --preset ninja-cpuonly-release \ | |
-DCMAKE_CXX_COMPILER=clang++ \ | |
-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 | |
container: greole/ofbase | |
needs: [build-compilation-db] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: | | |
apt update | |
apt install -y \ | |
clang-tidy \ | |
jq | |
- uses: actions/download-artifact@v4 | |
with: | |
name: build-artifact | |
path: build | |
- name: Run clang-tidy | |
run: | | |
git config --global --add safe.directory /__w/OGL/OGL | |
# Create list of all source files belonging to this repository | |
git ls-files | grep -E "\.(C)" > 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/ReleaseCPUOnly/compile_commands.json \ | |
| sed 's/^"\(.*\)"$/\1/' \ | |
| grep -F -f pattern - > files | |
# run clang-tidy on all specified files | |
clang-tidy --fix --extra-arg=-w -p build/ReleaseCPUOnly $(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/clang-format-action@v4.11.0 | |
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 |