CI: Fail build if code is wrongly formatted

Cette révision appartient à :
Henry Case 2018-06-26 09:32:47 +01:00 révisé par Henry Dorsett Case
Parent b6af4dd343
révision 91d6db578b
5 fichiers modifiés avec 54 ajouts et 1 suppressions

Voir le fichier

@ -15,6 +15,9 @@ env:
matrix:
fast_finish: true
before_install:
- make -f _dev/Makefile fmtcheck
install:
- sudo pip install docker

Voir le fichier

@ -61,7 +61,8 @@ There are number of things that need to be setup before running tests. Most impo
```
git clone https://github.com/cloudflare/tls-tris.git
cd tls-tris; make -f _dev/Makefile build-all
cd tls-tris; cp _dev/utils/pre-commit .git/hooks/
make -f _dev/Makefile build-all
```
### Testing

Voir le fichier

@ -112,5 +112,7 @@ clean:
clean-all: clean
rm -rf $(BUILD_DIR)
fmtcheck:
$(DEV_DIR)/utils/fmtcheck.sh
.PHONY: $(BUILD_DIR) clean build build-test test test-unit test-bogo test-compat

20
_dev/utils/fmtcheck.sh Fichier exécutable
Voir le fichier

@ -0,0 +1,20 @@
#!/bin/sh
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
gofiles=$(find . -iname "*.go" ! -path "*/_dev/*")
#[ -z "$gofiles" ] && exit 0
unformatted=$(gofmt -l $gofiles)
[ -z "$unformatted" ] && exit 0
# Some files are not gofmt'd. Print message and fail.
echo >&2 "Go files must be formatted with gofmt. Please run:"
for fn in $unformatted; do
echo >&2 " gofmt -w $PWD/$fn"
done
exit 1

27
_dev/utils/pre-commit Fichier exécutable
Voir le fichier

@ -0,0 +1,27 @@
#!/bin/sh
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# git gofmt pre-commit hook
#
# To use, store as .git/hooks/pre-commit inside your repository and make sure
# it has execute permissions.
#
# This script does not handle file names that contain spaces.
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$')
[ -z "$gofiles" ] && exit 0
unformatted=$(gofmt -l $gofiles)
[ -z "$unformatted" ] && exit 0
# Some files are not gofmt'd. Print message and fail.
echo >&2 "Go files must be formatted with gofmt. Please run:"
for fn in $unformatted; do
echo >&2 " gofmt -w $PWD/$fn"
done
exit 1