From fea64fecd6c25e81a7c7830d8fd7c5a58f2ed21d Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Sun, 16 Feb 2025 13:29:58 +0100 Subject: [PATCH 1/2] Add style check to workflow --- .github/workflows/test.yaml | 12 ++++++++++++ test/Makefile | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5a4e180cfa..7c12f3c814 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -3,6 +3,18 @@ name: test on: [push, pull_request] jobs: + style-check: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + continue-on-error: true + steps: + - name: checkout + uses: actions/checkout@v4 + - name: run style check + run: | + clang-format --version + cd test && make style_check + ubuntu: runs-on: ubuntu-latest if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name diff --git a/test/Makefile b/test/Makefile index 152f9098ef..3dc77f073a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -28,6 +28,11 @@ TEST_ARGS = gtest/gtest-all.cc gtest/gtest_main.cc $(OPENSSL_SUPPORT) $(ZLIB_SUP # OSS-Fuzz will define its own value for LIB_FUZZING_ENGINE. LIB_FUZZING_ENGINE ?= standalone_fuzz_target_runner.o +CLANG_FORMAT = clang-format +REALPATH = $(shell which grealpath 2>/dev/null || which realpath 2>/dev/null) +STYLE_CHECK_FILES = $(filter-out httplib.h httplib.cc, \ + $(wildcard fuzzing/*.h fuzzing/*.cc *.h *.cc ../httplib.h)) + all : test test_split ./test @@ -45,6 +50,28 @@ test_split : test.cc ../httplib.h httplib.cc Makefile cert.pem check_abi: @./check-shared-library-abi-compatibility.sh +.PHONY: style_check +style_check: $(STYLE_CHECK_FILES) + @for file in $(STYLE_CHECK_FILES); do \ + $(CLANG_FORMAT) $$file > $$file.formatted; \ + if ! diff -u $$file $$file.formatted; then \ + file2=$$($(REALPATH) --relative-to=.. $$file); \ + printf "\n%*s\n" 80 | tr ' ' '#'; \ + printf "##%*s##\n" 76; \ + printf "## %-70s ##\n" "$$file2 not properly formatted. Please run clang-format."; \ + printf "##%*s##\n" 76; \ + printf "%*s\n\n" 80 | tr ' ' '#'; \ + failed=1; \ + fi; \ + rm -f $$file.formatted; \ + done; \ + if [ -n "$$failed" ]; then \ + echo "Style check failed for one or more files. See above for details."; \ + false; \ + else \ + echo "All files are properly formatted."; \ + fi + test_proxy : test_proxy.cc ../httplib.h Makefile cert.pem $(CXX) -o $@ -I.. $(CXXFLAGS) test_proxy.cc $(TEST_ARGS) From f7bb3bacd9e2ba6062ad8c3ad66859592e0b79a6 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 17 Feb 2025 05:41:50 +0100 Subject: [PATCH 2/2] Add example files to style check --- test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Makefile b/test/Makefile index 3dc77f073a..348bfa2bb8 100644 --- a/test/Makefile +++ b/test/Makefile @@ -31,7 +31,7 @@ LIB_FUZZING_ENGINE ?= standalone_fuzz_target_runner.o CLANG_FORMAT = clang-format REALPATH = $(shell which grealpath 2>/dev/null || which realpath 2>/dev/null) STYLE_CHECK_FILES = $(filter-out httplib.h httplib.cc, \ - $(wildcard fuzzing/*.h fuzzing/*.cc *.h *.cc ../httplib.h)) + $(wildcard example/*.h example/*.cc fuzzing/*.h fuzzing/*.cc *.h *.cc ../httplib.h)) all : test test_split ./test