Skip to content

Commit ee5b5f8

Browse files
Add lint ci job
1 parent f5dd861 commit ee5b5f8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ on:
1616
required: true
1717

1818
jobs:
19+
lint:
20+
runs-on: ubuntu-20.04
21+
steps:
22+
- uses: actions/checkout@v2
23+
- run: sudo apt-get install clang-format
24+
- run: ./scripts/clang-format-diff.sh
25+
1926
build-builder-image:
2027
strategy:
2128
fail-fast: false

scripts/clang-format-diff.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
if [ -n "$1" ]; then
6+
BASE_BRANCH="$1"
7+
elif [ -n "$GITHUB_EVENT_BEFORE" ] && [ "push" = "$GITHUB_EVENT_NAME" ]; then
8+
BASE_BRANCH="$GITHUB_EVENT_BEFORE"
9+
elif [ -n "$GITHUB_BASE_REF" ]; then
10+
BASE_BRANCH="origin/$GITHUB_BASE_REF"
11+
else
12+
BASE_BRANCH="@{upstream}"
13+
fi
14+
15+
MERGE_BASE=$(git merge-base $BASE_BRANCH HEAD)
16+
17+
git diff -U0 --no-color $MERGE_BASE -- '*.c' '*.h' | clang-format-diff -i -p1
18+
exit $?

0 commit comments

Comments
 (0)