diff --git a/Dockerfile b/Dockerfile index 2350cf1e8..c3a23a4f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,6 +36,15 @@ RUN mkdir -p /usr/src/criu \ && cd /usr/src/criu \ && make install-criu +# install shfmt +RUN mkdir -p /go/src/github.com/mvdan \ + && cd /go/src/github.com/mvdan \ + && git clone https://github.com/mvdan/sh \ + && cd sh \ + && git checkout -f v0.4.0 \ + && go install ./cmd/shfmt \ + && rm -rf /go/src/github.com/mvdan + # setup a playground for us to spawn containers in ENV ROOTFS /busybox RUN mkdir -p ${ROOTFS} \ diff --git a/Makefile b/Makefile index 779be9255..c728fd58d 100644 --- a/Makefile +++ b/Makefile @@ -119,6 +119,7 @@ clean: validate: script/validate-gofmt + script/validate-shfmt go vet ./... ci: validate localtest diff --git a/script/validate-shfmt b/script/validate-shfmt new file mode 100755 index 000000000..84930399d --- /dev/null +++ b/script/validate-shfmt @@ -0,0 +1,21 @@ +#!/bin/bash + +badFiles=() +while read f; do + badFiles+=("$f") +done < <(shfmt -l . | grep -v Godeps/) + +if [ ${#badFiles[@]} -eq 0 ]; then + echo 'Congratulations! All shell source files are properly formatted.' +else + { + echo "These files are not properly shfmt'd:" + for f in "${badFiles[@]}"; do + echo " - $f" + done + echo + echo 'Please reformat the above files using "shfmt -w" and commit the result.' + echo + } >&2 + false +fi