validate: add shfmt

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2020-03-01 00:31:43 +09:00
parent 7af0344f9b
commit eb484fcb67
4 changed files with 35 additions and 0 deletions

View file

@ -200,6 +200,15 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/go/pkg/mod \
PREFIX=/build ./install.sh $INSTALL_BINARY_NAME PREFIX=/build ./install.sh $INSTALL_BINARY_NAME
FROM base AS shfmt
ENV INSTALL_BINARY_NAME=shfmt
ARG SHFMT_COMMIT
COPY hack/dockerfile/install/install.sh ./install.sh
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
PREFIX=/build ./install.sh $INSTALL_BINARY_NAME
FROM dev-base AS dockercli FROM dev-base AS dockercli
ENV INSTALL_BINARY_NAME=dockercli ENV INSTALL_BINARY_NAME=dockercli
ARG DOCKERCLI_CHANNEL ARG DOCKERCLI_CHANNEL
@ -304,6 +313,7 @@ COPY --from=criu /build/ /usr/local/
COPY --from=vndr /build/ /usr/local/bin/ COPY --from=vndr /build/ /usr/local/bin/
COPY --from=gotestsum /build/ /usr/local/bin/ COPY --from=gotestsum /build/ /usr/local/bin/
COPY --from=golangci_lint /build/ /usr/local/bin/ COPY --from=golangci_lint /build/ /usr/local/bin/
COPY --from=shfmt /build/ /usr/local/bin/
COPY --from=runc /build/ /usr/local/bin/ COPY --from=runc /build/ /usr/local/bin/
COPY --from=containerd /build/ /usr/local/bin/ COPY --from=containerd /build/ /usr/local/bin/
COPY --from=rootlesskit /build/ /usr/local/bin/ COPY --from=rootlesskit /build/ /usr/local/bin/

View file

@ -0,0 +1,11 @@
#!/bin/sh
: "${SHFMT_COMMIT:=01725bdd30658db1fe1b9e02173c3060061fe86f}" # v3.0.2
install_shfmt() {
echo "Install shfmt version $SHFMT_COMMIT"
git clone https://github.com/mvdan/sh.git "$GOPATH/src/github.com/mvdan/sh"
cd "$GOPATH/src/github.com/mvdan/sh" || exit 1
git checkout -q "$SHFMT_COMMIT"
GO111MODULE=on go build -buildmode=pie -v -o "${PREFIX}/shfmt" ./cmd/shfmt
}

View file

@ -14,3 +14,4 @@ export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "${SCRIPTDIR}"/changelog-date-descending . "${SCRIPTDIR}"/changelog-date-descending
. "${SCRIPTDIR}"/deprecate-integration-cli . "${SCRIPTDIR}"/deprecate-integration-cli
. "${SCRIPTDIR}"/golangci-lint . "${SCRIPTDIR}"/golangci-lint
. "${SCRIPTDIR}"/shfmt

13
hack/validate/shfmt Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e -o pipefail
shfmtflags="-bn -ci -sr"
# NOTE: `git grep '^#!'` may also pick up non-shell script files.
# Add exceptional files to `egrep -v` if any false-positive is detected.
if git grep --name-only '^#!' | egrep -v '(vendor|\.go|Jenkinsfile)' \
| xargs shfmt -d $shfmtflags; then
echo 'Congratulations! The shell scripts are properly formatted.'
else
echo "Please reformat the shell scripts with \`shfmt -w ${shfmtflags}\`."
exit 1
fi