ci: tidy and format checks

This commit is contained in:
Daniil Zhukov 2024-07-07 00:55:25 +02:00 committed by sha512sum
parent 0c654104d5
commit e5b4a231fc
3 changed files with 68 additions and 21 deletions

View file

@ -0,0 +1,21 @@
name: "Setup compilers"
description: "Setup compilers and build tools"
inputs:
clang:
required: false
default: "18"
gcc:
required: false
default: "14"
runs:
using: "composite"
steps:
- shell: bash
run: |
sudo apt update
sudo add-apt-repository universe multiverse
sudo apt update
sudo apt install gcc-${{ inputs.gcc }} g++-${{ inputs.gcc }}
wget https://apt.llvm.org/llvm.sh
chmod u+x llvm.sh
sudo ./llvm.sh ${{ inputs.clang }}

View file

@ -7,6 +7,24 @@ on:
branches: [ "main" ]
jobs:
tidy:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Setup compilers
uses: ./.github/actions/setup-compilers
- name: Run clang tidy
run: make tidy CI=1
format:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Setup compilers
uses: ./.github/actions/setup-compilers
- name: Run clang format
run: make format CI=1
build:
runs-on: ${{ matrix.os }}
@ -35,16 +53,7 @@ jobs:
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Setup compilers
id: compilers
shell: bash
run: |
sudo apt update
sudo add-apt-repository universe multiverse
sudo apt update
sudo apt install gcc-14 g++-14
wget https://apt.llvm.org/llvm.sh
chmod u+x llvm.sh
sudo ./llvm.sh 18
uses: ./.github/actions/setup-compilers
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type

View file

@ -1,13 +1,20 @@
MAKEFILE_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
TESTS_BIN = $(MAKEFILE_DIR)/build/cserver_tests
CC = clang
CXX = clang++
CMAKE_CMD ?= cmake
CMAKE_BUILD_TYPE ?= Debug
ifdef CI
CMAKE_GENERATOR ?= "Unix Makefiles"
else
CMAKE_GENERATOR ?= Ninja
endif
CMAKE_FLAGS += -DCMAKE_CXX_COMPILER=$(CXX) \
-DCMAKE_C_COMPILER=$(CC) \
-DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
-DENABLE_TESTS=1 \
@ -28,6 +35,12 @@ else
BUILD_TOOL = $(MAKE)
endif
ifdef CI
FORMAT_FLAGS = -n --Werror
else
FORMAT_FLAGS = -i
endif
all: $(TESTS_BIN)
build/.ran-cmake:
@ -42,7 +55,7 @@ cmake:
$(MAKE) build/.ran-cmake
format:
clang-format -Werror -i \
clang-format $(FORMAT_FLAGS) \
$(shell find include -name *.hpp) \
$(shell find examples -name *.cpp) \
$(shell find tests -name *.cpp)
@ -53,11 +66,15 @@ clean:
distclean:
rm -rf build
# Test
test: $(TESTS_BIN)
$(TESTS_BIN)
tidy: build/.ran-cmake
clang-tidy -p build \
$(shell find include -name *.hpp) \
$(shell find examples -name *.cpp) \
$(shell find tests -name *.cpp)
FORCE: ;
.PHONY: all cmake test format clean distclean