Skip to content

Commit 574f5ce

Browse files
Add style check to workflow (#2062)
* Add style check to workflow * Add example files to style check
1 parent 2996cec commit 574f5ce

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

.github/workflows/test.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ env:
2424
GTEST_FILTER: ${{ github.event.inputs.gtest_filter || '*' }}
2525

2626
jobs:
27+
style-check:
28+
runs-on: ubuntu-latest
29+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
30+
continue-on-error: true
31+
steps:
32+
- name: checkout
33+
uses: actions/checkout@v4
34+
- name: run style check
35+
run: |
36+
clang-format --version
37+
cd test && make style_check
38+
2739
ubuntu:
2840
runs-on: ubuntu-latest
2941
if: >

test/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ TEST_ARGS = gtest/gtest-all.cc gtest/gtest_main.cc $(OPENSSL_SUPPORT) $(ZLIB_SUP
2828
# OSS-Fuzz will define its own value for LIB_FUZZING_ENGINE.
2929
LIB_FUZZING_ENGINE ?= standalone_fuzz_target_runner.o
3030

31+
CLANG_FORMAT = clang-format
32+
REALPATH = $(shell which grealpath 2>/dev/null || which realpath 2>/dev/null)
33+
STYLE_CHECK_FILES = $(filter-out httplib.h httplib.cc, \
34+
$(wildcard example/*.h example/*.cc fuzzing/*.h fuzzing/*.cc *.h *.cc ../httplib.h))
35+
3136
all : test test_split
3237
./test
3338

@@ -45,6 +50,28 @@ test_split : test.cc ../httplib.h httplib.cc Makefile cert.pem
4550
check_abi:
4651
@./check-shared-library-abi-compatibility.sh
4752

53+
.PHONY: style_check
54+
style_check: $(STYLE_CHECK_FILES)
55+
@for file in $(STYLE_CHECK_FILES); do \
56+
$(CLANG_FORMAT) $$file > $$file.formatted; \
57+
if ! diff -u $$file $$file.formatted; then \
58+
file2=$$($(REALPATH) --relative-to=.. $$file); \
59+
printf "\n%*s\n" 80 | tr ' ' '#'; \
60+
printf "##%*s##\n" 76; \
61+
printf "## %-70s ##\n" "$$file2 not properly formatted. Please run clang-format."; \
62+
printf "##%*s##\n" 76; \
63+
printf "%*s\n\n" 80 | tr ' ' '#'; \
64+
failed=1; \
65+
fi; \
66+
rm -f $$file.formatted; \
67+
done; \
68+
if [ -n "$$failed" ]; then \
69+
echo "Style check failed for one or more files. See above for details."; \
70+
false; \
71+
else \
72+
echo "All files are properly formatted."; \
73+
fi
74+
4875
test_proxy : test_proxy.cc ../httplib.h Makefile cert.pem
4976
$(CXX) -o $@ -I.. $(CXXFLAGS) test_proxy.cc $(TEST_ARGS)
5077

0 commit comments

Comments
 (0)