Permalink
Browse files

Add shfmt to the validate make target

We need to run on a directory since shell files might have no extension.
There are few shell files, so speed should not be an issue.

Fixes #1166.
  • Loading branch information...
1 parent cdb66f5 commit b9d13467b96689c4abfd462bb1bc3e6974625726 @mvdan mvdan committed Nov 17, 2016
Showing with 31 additions and 0 deletions.
  1. +9 −0 Dockerfile
  2. +1 −0 Makefile
  3. +21 −0 script/validate-shfmt
View
@@ -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} \
View
@@ -119,6 +119,7 @@ clean:
validate:
script/validate-gofmt
+ script/validate-shfmt
go vet ./...
ci: validate localtest
View
@@ -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

0 comments on commit b9d1346

Please sign in to comment.