diff --git a/config/jobs/presubmits.yaml b/config/jobs/presubmits.yaml index da95518..aae4ae4 100644 --- a/config/jobs/presubmits.yaml +++ b/config/jobs/presubmits.yaml @@ -35,3 +35,14 @@ presubmits: - image: quay.io/peridot/ci:v0.3.16 command: - hack/non_manual_build.sh + + - name: pull-peridot-gofmt-check + branches: + - main + always_run: true + decorate: true + spec: + containers: + - image: quay.io/peridot/ci:v0.3.16 + command: + - hack/gofmt_check.sh diff --git a/hack/gofmt_check.sh b/hack/gofmt_check.sh new file mode 100755 index 0000000..545b3a9 --- /dev/null +++ b/hack/gofmt_check.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -o errexit + +bazel build --config=ci @go_sdk//... + +GO_BIN="$(bazel info output_base)/external/go_sdk/bin/go" + +if [[ -n $($GO_BIN fmt -n $(go list ./... | grep -v /vendor/) | sed 's/ -w//') ]]; then + echo "Go files must be formatted with gofmt. Please run:" + echo " go fmt $(go list ./... | grep -v /vendor/)" + exit 1 +fi + +