Skip to content

Commit eb484fc

Browse files
committed
validate: add shfmt
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
1 parent 7af0344 commit eb484fc

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
200200
--mount=type=cache,target=/go/pkg/mod \
201201
PREFIX=/build ./install.sh $INSTALL_BINARY_NAME
202202

203+
FROM base AS shfmt
204+
ENV INSTALL_BINARY_NAME=shfmt
205+
ARG SHFMT_COMMIT
206+
COPY hack/dockerfile/install/install.sh ./install.sh
207+
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
208+
RUN --mount=type=cache,target=/root/.cache/go-build \
209+
--mount=type=cache,target=/go/pkg/mod \
210+
PREFIX=/build ./install.sh $INSTALL_BINARY_NAME
211+
203212
FROM dev-base AS dockercli
204213
ENV INSTALL_BINARY_NAME=dockercli
205214
ARG DOCKERCLI_CHANNEL
@@ -304,6 +313,7 @@ COPY --from=criu /build/ /usr/local/
304313
COPY --from=vndr /build/ /usr/local/bin/
305314
COPY --from=gotestsum /build/ /usr/local/bin/
306315
COPY --from=golangci_lint /build/ /usr/local/bin/
316+
COPY --from=shfmt /build/ /usr/local/bin/
307317
COPY --from=runc /build/ /usr/local/bin/
308318
COPY --from=containerd /build/ /usr/local/bin/
309319
COPY --from=rootlesskit /build/ /usr/local/bin/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
: "${SHFMT_COMMIT:=01725bdd30658db1fe1b9e02173c3060061fe86f}" # v3.0.2
4+
5+
install_shfmt() {
6+
echo "Install shfmt version $SHFMT_COMMIT"
7+
git clone https://github.com/mvdan/sh.git "$GOPATH/src/github.com/mvdan/sh"
8+
cd "$GOPATH/src/github.com/mvdan/sh" || exit 1
9+
git checkout -q "$SHFMT_COMMIT"
10+
GO111MODULE=on go build -buildmode=pie -v -o "${PREFIX}/shfmt" ./cmd/shfmt
11+
}

hack/validate/default

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1414
. "${SCRIPTDIR}"/changelog-date-descending
1515
. "${SCRIPTDIR}"/deprecate-integration-cli
1616
. "${SCRIPTDIR}"/golangci-lint
17+
. "${SCRIPTDIR}"/shfmt

hack/validate/shfmt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
set -e -o pipefail
3+
4+
shfmtflags="-bn -ci -sr"
5+
# NOTE: `git grep '^#!'` may also pick up non-shell script files.
6+
# Add exceptional files to `egrep -v` if any false-positive is detected.
7+
if git grep --name-only '^#!' | egrep -v '(vendor|\.go|Jenkinsfile)' \
8+
| xargs shfmt -d $shfmtflags; then
9+
echo 'Congratulations! The shell scripts are properly formatted.'
10+
else
11+
echo "Please reformat the shell scripts with \`shfmt -w ${shfmtflags}\`."
12+
exit 1
13+
fi

0 commit comments

Comments
 (0)