ci: tidy and format checks
This commit is contained in:
parent
0c654104d5
commit
e5b4a231fc
3 changed files with 68 additions and 21 deletions
21
.github/actions/setup-compilers/action.yml
vendored
Normal file
21
.github/actions/setup-compilers/action.yml
vendored
Normal 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 }}
|
33
.github/workflows/cmake-multi-platform.yml
vendored
33
.github/workflows/cmake-multi-platform.yml
vendored
|
@ -7,11 +7,29 @@ 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 }}
|
||||
|
||||
strategy:
|
||||
|
||||
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-24.04]
|
||||
|
@ -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
|
||||
|
@ -66,4 +75,4 @@ jobs:
|
|||
working-directory: ${{ steps.strings.outputs.build-output-dir }}
|
||||
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
|
||||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
|
||||
run: ctest --build-config ${{ matrix.build_type }}
|
||||
run: ctest --build-config ${{ matrix.build_type }}
|
35
Makefile
35
Makefile
|
@ -1,17 +1,24 @@
|
|||
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
|
||||
CMAKE_GENERATOR ?= Ninja
|
||||
|
||||
ifdef CI
|
||||
CMAKE_GENERATOR ?= "Unix Makefiles"
|
||||
else
|
||||
CMAKE_GENERATOR ?= Ninja
|
||||
endif
|
||||
|
||||
CMAKE_FLAGS += -DCMAKE_CXX_COMPILER=$(CXX) \
|
||||
-DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
|
||||
-DENABLE_TESTS=1 \
|
||||
-DENABLE_EXAMPLES=1
|
||||
-DCMAKE_C_COMPILER=$(CC) \
|
||||
-DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
|
||||
-DENABLE_TESTS=1 \
|
||||
-DENABLE_EXAMPLES=1
|
||||
|
||||
# Only need to handle Ninja here.
|
||||
# Make will inherit the VERBOSE variable, and the -j, -l, and -n flags.
|
||||
|
@ -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,8 +55,8 @@ cmake:
|
|||
$(MAKE) build/.ran-cmake
|
||||
|
||||
format:
|
||||
clang-format -Werror -i \
|
||||
$(shell find include -name *.hpp) \
|
||||
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
|
Loading…
Reference in a new issue