Skip to content

Commit 3c85646

Browse files
committed
Add workflow to check formatting
1 parent 87ca792 commit 3c85646

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

.github/workflows/clang-format.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "Coding Standards"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "v*.*"
7+
- "master"
8+
push:
9+
branches:
10+
- "v*.*"
11+
- "master"
12+
13+
jobs:
14+
coding-standards:
15+
name: "Coding Standards"
16+
runs-on: "ubuntu-20.04"
17+
18+
strategy:
19+
matrix:
20+
php-version:
21+
- "7.4"
22+
23+
steps:
24+
- name: "Checkout"
25+
uses: "actions/checkout@v2"
26+
with:
27+
submodules: true
28+
29+
- name: "Install PHP"
30+
uses: "shivammathur/setup-php@v2"
31+
with:
32+
php-version: "${{ matrix.php-version }}"
33+
extensions: ":mongodb"
34+
tools: "phpize"
35+
36+
- name: "Configure driver"
37+
run: .github/workflows/configure.sh
38+
39+
- name: "Run clang-format"
40+
run: "make format-check"

Makefile.frag

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: coverage test-clean package package.xml format format-changed
1+
.PHONY: coverage test-clean package package.xml format format-changed format-check
22

33
DATE=`date +%Y-%m-%d--%H-%M-%S`
44
MONGODB_VERSION=$(shell php -n -dextension=modules/mongodb.so -r 'echo MONGODB_VERSION;')
@@ -70,6 +70,9 @@ format:
7070
format-changed:
7171
$(top_srcdir)/scripts/clang-format.sh changed
7272

73+
format-check:
74+
$(top_srcdir)/scripts/clang-format.sh check
75+
7376
distcheck: package test-virtual
7477

7578
test-virtual: package

scripts/clang-format.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#!/bin/sh
22

3-
if test x"$1" = x; then
3+
CLANG_ARGS="-Werror"
4+
5+
if test x"$1" = xchanged; then
6+
FILES1=`git ls-files | grep -v "src/contrib" | grep '\.[ch]$'`
7+
FILES2=`git ls-files --others --exclude-standard | grep -v "src/contrib" | grep '\.[ch]$'`
8+
FILES="$FILES1 $FILES2"
9+
else
410
FILES1=`git ls-files | grep -v "src/contrib" | grep '\.[ch]$'`
511
FILES2=`git ls-files --others --exclude-standard | grep -v "src/contrib" | grep '\.[ch]$'`
612
FILES="$FILES1 $FILES2"
713
fi
8-
if test x"$1" = xchanged; then
9-
FILES1=`git diff --name-only | grep -v "src/contrib" | grep '\.[ch]$'`
10-
FILES2=`git diff --cached --name-only | grep -v "src/contrib" | grep '\.[ch]$'`
11-
FILES3=`git ls-files --others --exclude-standard | grep '\.[ch]$'`
12-
FILES="$FILES1 $FILES2 $FILES3"
14+
15+
if test x"$1" = xcheck; then
16+
CLANG_ARGS="$CLANG_ARGS -n"
1317
fi
1418

1519
# Find clang-format, we prefer -6.0, but also allow binaries without -suffix as
@@ -33,7 +37,16 @@ if [ $VERSION_MAJOR -lt 6 ]; then
3337
exit
3438
fi
3539

40+
FAILURE=""
41+
3642
# Run formatter
3743
for i in $FILES; do
38-
$CLANG_FORMAT -i $i
44+
$CLANG_FORMAT $CLANG_ARGS -i $i
45+
[ $? -eq 0 ] || FAILURE="yes"
3946
done
47+
48+
if [ -z "$FAILURE" ]; then
49+
exit 0
50+
fi
51+
52+
exit 1

0 commit comments

Comments
 (0)