Skip to content

Commit fdee015

Browse files
committed
add clang format config, GHA job
1 parent feaa893 commit fdee015

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

.clang-format

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
BasedOnStyle: Google
3+
IndentWidth: 4
4+
Language: Cpp
5+
AllowShortBlocksOnASingleLine: false
6+
AllowShortCaseLabelsOnASingleLine: false
7+
AllowShortFunctionsOnASingleLine: Inline
8+
AllowShortIfStatementsOnASingleLine: false
9+
AllowShortLoopsOnASingleLine: false
10+
PointerAlignment: Left
11+
ColumnLimit: 80

.github/check_format.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
#
3+
# check that all code complies w/ the clang-format specification
4+
#
5+
# if all is well, returns w/o errors and does not print anything.
6+
# otherwise, return an error and print offending changes
7+
8+
set -e # abort on error
9+
10+
11+
if [ $# -ne 1 ]; then
12+
echo "wrong number of arguments"
13+
echo ""
14+
echo "usage: check_format <DIR>"
15+
exit 1
16+
fi
17+
18+
_binary=${CLANG_FORMAT_BINARY:-clang-format}
19+
20+
$_binary --version
21+
22+
cd $1
23+
find . \( -iname '*.cpp' -or -iname '*.hpp' -or -iname '*.ipp' -or -iname '*.cu' -or -iname '*.cuh' -or -iname '*.hip' -or -iname '*.sycl' \) \
24+
-and -not -path "./*build*/*" \
25+
-and -not -path "./thirdparty/*" \
26+
| xargs $_binary -i -style=file
27+
28+
29+
if ! [ -z $CI ] || ! [ -z $GITHUB_ACTIONS ]; then
30+
mkdir changed
31+
for f in $(git diff --name-only); do
32+
cp --parents $f changed
33+
done
34+
fi
35+
36+
echo "clang-format done"
37+
38+
set +e
39+
git diff --exit-code --stat
40+
result=$?
41+
42+
if [ "$result" -eq "128" ]; then
43+
echo "Format was successfully applied"
44+
echo "Could not create summary of affected files"
45+
echo "Are you in a submodule?"
46+
47+
fi
48+
49+
exit $result

.github/workflows/checks.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Checks
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches:
7+
- main
8+
9+
jobs:
10+
format:
11+
runs-on: ubuntu-latest
12+
container: ghcr.io/acts-project/format10:v11
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Check
16+
run: .github/check_format.sh .
17+
- uses: actions/upload-artifact@v1
18+
if: failure()
19+
with:
20+
name: changed
21+
path: changed

0 commit comments

Comments
 (0)