CI: Fail build if code is wrongly formatted
Este cometimento está contido em:
ascendente
b6af4dd343
cometimento
91d6db578b
@ -15,6 +15,9 @@ env:
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
before_install:
|
||||
- make -f _dev/Makefile fmtcheck
|
||||
|
||||
install:
|
||||
- sudo pip install docker
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
Ficheiro executável
20
_dev/utils/fmtcheck.sh
Ficheiro executável
@ -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
Ficheiro executável
27
_dev/utils/pre-commit
Ficheiro executável
@ -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
|
||||
|
Carregando…
Criar uma nova questão referindo esta
Bloquear um utilizador