diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2020-05-01 11:18:32 +0100 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2020-05-13 11:00:02 +0100 |
commit | d62e2a2cd4054be65b0f05cebefaced648ecf4eb (patch) | |
tree | 6b359690535513efa7f4d17e6694ef3b38a82874 /containers | |
parent | bce7800dee4dec7dbd3a14318e81e977afb5f66a (diff) | |
download | libvirt-ci-d62e2a2cd4054be65b0f05cebefaced648ecf4eb.zip libvirt-ci-d62e2a2cd4054be65b0f05cebefaced648ecf4eb.tar.gz libvirt-ci-d62e2a2cd4054be65b0f05cebefaced648ecf4eb.tar.bz2 |
containers: add a standard container for running go fmt
The "go fmt" code style checking tool is something we wish to run on all
Go code, so it is useful to have a common container that can be used by
all relevant projects.
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'containers')
-rw-r--r-- | containers/go-fmt/Dockerfile | 9 | ||||
-rw-r--r-- | containers/go-fmt/README.rst | 20 | ||||
-rwxr-xr-x | containers/go-fmt/go-fmt.sh | 24 |
3 files changed, 53 insertions, 0 deletions
diff --git a/containers/go-fmt/Dockerfile b/containers/go-fmt/Dockerfile new file mode 100644 index 0000000..9079fea --- /dev/null +++ b/containers/go-fmt/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:1.14 + +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt-get update && \ + apt-get install --no-install-recommends -y \ + diffstat && \ + apt-get autoclean -y + +COPY go-fmt.sh /go-fmt diff --git a/containers/go-fmt/README.rst b/containers/go-fmt/README.rst new file mode 100644 index 0000000..0af6998 --- /dev/null +++ b/containers/go-fmt/README.rst @@ -0,0 +1,20 @@ +============================================= +Container for running go fmt code style check +============================================= + +This container provides a simple way to invoke ``go fmt`` to validate code +style across a Golang codebase. It should be integrated into a CI by adding +the following snippet to ``.gitlab-ci.yml`` + +:: + + go-fmt: + stage: prebuild + image: registry.gitlab.com/libvirt/libvirt-ci/go-fmt:master + script: + - /go-fmt + artifacts: + paths: + - go-fmt.patch + expire_in: 1 week + when: on_failure diff --git a/containers/go-fmt/go-fmt.sh b/containers/go-fmt/go-fmt.sh new file mode 100755 index 0000000..daa372c --- /dev/null +++ b/containers/go-fmt/go-fmt.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +GOFMT=$(go env GOROOT)/bin/gofmt + +find -name '*.go' | xargs $GOFMT -d -e > go-fmt.patch + +if test -s go-fmt.patch +then + echo + echo "❌ ERROR: some files failed go fmt code style check" + echo + diffstat go-fmt.patch + echo + echo "See the go-fmt patch artifact for full details of mistakes." + echo + echo "For guidance on how to configure Emacs or Vim to automatically" + echo "run go fmt when saving files read" + echo + echo " https://blog.golang.org/gofmt" + echo + exit 1 +fi + +echo "✔ OK: all files passed go fmt code style check" |