File tree 2 files changed +71
-0
lines changed
2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Code formatting
2
+
3
+ on :
4
+ pull_request :
5
+ branches : [ master, develop ]
6
+
7
+ jobs :
8
+ test-format :
9
+ runs-on : ubuntu-latest
10
+ steps :
11
+ - uses : actions/checkout@v3
12
+ with :
13
+ fetch-depth : 1000
14
+
15
+ - name : Configure git
16
+ run : |
17
+ git config --global user.email "-"
18
+ git config --global user.name "Autoformatter"
19
+ git fetch origin "$GITHUB_BASE_REF":"$GITHUB_BASE_REF" --depth=1000
20
+
21
+ - name : Install clang-format
22
+ run : |
23
+ sudo apt-get update
24
+ sudo apt-get -y install clang-format-12
25
+
26
+ - name : Check formatting
27
+ run : tests/test-format.sh "$GITHUB_BASE_REF"
28
+
29
+ - name : Upload patches
30
+ uses : actions/upload-artifact@v3
31
+ if : failure()
32
+ with :
33
+ name : Patches
34
+ path : ./*.patch
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+
3
+ set -e
4
+
5
+ [ -z " $1 " ] && exit
6
+
7
+ basebranch=$1
8
+
9
+ CHANGED_FILES=$( git diff --name-only " $basebranch " ...HEAD)
10
+
11
+ CHANGED=0
12
+
13
+ for file in $CHANGED_FILES
14
+ do
15
+ case " $file " in
16
+ * .cpp|* .h)
17
+ echo Checking " $file "
18
+ clang-format -i " $file "
19
+ if ! git diff --quiet " $basebranch " ...HEAD
20
+ then
21
+ printf " \033[31mError:\033[0m Formatting error in %s\n" " $file "
22
+ CHANGED=1
23
+ git add " $file "
24
+ git commit -q -m " Apply clang-format to $( basename " $file " ) "
25
+ printf " Creating patch "
26
+ git format-patch HEAD~
27
+ fi
28
+ esac
29
+ done
30
+
31
+ if [ $CHANGED = 1 ]
32
+ then
33
+ printf " \033[31mError:\033[0m Issues found. You may use the patches provided as artifacts to format the code."
34
+ exit 1
35
+ fi
36
+
37
+ exit 0
You can’t perform that action at this time.
0 commit comments