Skip to content

Commit c88d3c7

Browse files
MurmeleLinuxDevon
authored andcommitted
add format script
1 parent 676da12 commit c88d3c7

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

.github/workflows/tests.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@ jobs:
4141
cd build
4242
ctest --output-on-failure
4343
44+
format:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v3
48+
- name: Test format
49+
run: |
50+
./scripts/fmt.sh
51+
git diff --exit-code
52+

scripts/cl-fmt.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Variable that will hold the name of the clang-format command
4+
FMT=""
5+
6+
FOLDERS=("src" "test")
7+
8+
# Some distros just call it clang-format. Others (e.g. Ubuntu) are insistent
9+
# that the version number be part of the command. We prefer clang-format if
10+
# that's present, otherwise we check clang-format-13
11+
for clangfmt in clang-format{,-13}; do
12+
if which "$clangfmt" &>/dev/null; then
13+
FMT="$clangfmt"
14+
break
15+
fi
16+
done
17+
18+
# Check if we found a working clang-format
19+
if [ -z "$FMT" ]; then
20+
echo "failed to find clang-format. Please install clang-format version 13 or above"
21+
exit 1
22+
fi
23+
24+
function format() {
25+
# ignore getRSS.h file
26+
for f in $(find $@ -name '*.h' ! -iname 'getRSS.h' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp'); do
27+
echo "format ${f}";
28+
${FMT} -i ${f};
29+
done
30+
31+
echo "~~~ $@ Done ~~~";
32+
}
33+
34+
# Check all of the arguments first to make sure they're all directories
35+
for dir in ${FOLDERS[@]}; do
36+
if [ ! -d "${dir}" ]; then
37+
echo "${dir} is not a directory";
38+
else
39+
format ${dir};
40+
fi
41+
done

0 commit comments

Comments
 (0)