summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build.yml5
-rwxr-xr-xscripts/clang-format-diff.sh24
-rw-r--r--src/prebuilt/.clang-format2
3 files changed, 30 insertions, 1 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 00804dcc..464c943a 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -18,8 +18,11 @@ jobs:
python-version: '3.x'
- uses: actions/checkout@v1
- name: install tools
- run: pip3 install flake8==3.7.8
+ run: |
+ pip3 install flake8==3.7.8
+ sudo apt-get install clang-format
- run: flake8
+ - run: ./scripts/clang-format-diff.sh
build:
name: build
runs-on: ${{ matrix.os }}
diff --git a/scripts/clang-format-diff.sh b/scripts/clang-format-diff.sh
new file mode 100755
index 00000000..01a813f2
--- /dev/null
+++ b/scripts/clang-format-diff.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+set -o errexit
+set -o pipefail
+
+if [ -n "$1" ]; then
+ BRANCH="$1"
+elif [ -n "$GITHUB_BASE_REF" ]; then
+ BRANCH="origin/$GITHUB_BASE_REF"
+else
+ BRANCH="@{upstream}"
+fi
+
+MERGE_BASE=$(git merge-base $BRANCH HEAD)
+FORMAT_MSG=$(git clang-format $MERGE_BASE -q --diff -- src/)
+if [ -n "$FORMAT_MSG" -a "$FORMAT_MSG" != "no modified files to format" ]
+then
+ echo "Please run git clang-format before committing, or apply this diff:"
+ echo
+ # Run git clang-format again, this time without capruting stdout. This way
+ # clang-format format the message nicely and add color.
+ git clang-format $MERGE_BASE -q --diff -- src/
+ exit 1
+fi
diff --git a/src/prebuilt/.clang-format b/src/prebuilt/.clang-format
new file mode 100644
index 00000000..9d159247
--- /dev/null
+++ b/src/prebuilt/.clang-format
@@ -0,0 +1,2 @@
+DisableFormat: true
+SortIncludes: false