diff options
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" |