From abd6addeb23b9b087326cacedd547f7ea45b4a9c Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 23 Mar 2022 11:31:48 -0700 Subject: [PATCH] ci: bump shfmt to 3.5.1, simplify CI setup 1. Bump shfmt to v3.5.1. Release notes: https://github.com/mvdan/sh/releases 2. Since shfmt v3.5.0, specifying -l bash (or -l bats) is no longer necessary. Therefore, we can use shfmt to find all the files. Add .editorconfig to ignore vendor subdirectory. 3. Use shfmt docker image, so that we don't have to install anything explicitly. This greatly simplifies the shfmt CI job. Add localshfmt target so developers can still use a local shfmt binary when necessary. Signed-off-by: Kir Kolyshkin (cherry picked from commit 56edc41ca6a438a0638f4ddc1a2aa55fd0f78297) Signed-off-by: Kir Kolyshkin --- .editorconfig | 8 ++++++++ .github/workflows/validate.yml | 16 ---------------- Makefile | 12 +++++++----- 3 files changed, 15 insertions(+), 21 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..3bde04225 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +# This file is used by shfmt. See https://EditorConfig.org + +# This is a top-most EditorConfig file. +root = true + +# Ignore the entire "vendor" directory. +[vendor/**] +ignore = true diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index f297deb8b..938b0f80e 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -77,22 +77,6 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - - name: vars - run: | - echo "VERSION=3.3.1" >> $GITHUB_ENV - echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - - name: cache go mod and $GOCACHE - uses: actions/cache@v2 - with: - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: ${{ runner.os }}-shfmt-${{ env.VERSION }} - restore-keys: ${{ runner.os }}-shfmt- - - name: install shfmt - run: | - command -v shfmt || \ - (cd ~ && GO111MODULE=on time go get mvdan.cc/sh/v3/cmd/shfmt@v$VERSION) - name: shfmt run: make shfmt diff --git a/Makefile b/Makefile index cee7a6905..ec243fefd 100644 --- a/Makefile +++ b/Makefile @@ -137,10 +137,12 @@ shellcheck: # TODO: add shellcheck for more sh files (contrib/completions/bash/runc). shfmt: - shfmt -ln bats -d -w tests/integration/*.bats - shfmt -ln bash -d -w man/*.sh script/* \ - tests/*.sh tests/integration/*.bash tests/fuzzing/*.sh \ - contrib/completions/bash/runc contrib/cmd/seccompagent/*.sh + $(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_RUN_FLAGS) \ + --rm -v $(CURDIR):/src -w /src \ + mvdan/shfmt:v3.5.1 -d -w . + +localshfmt: + shfmt -d -w . vendor: $(GO) mod tidy @@ -162,5 +164,5 @@ verify-dependencies: vendor localrelease dbuild lint man runcimage \ test localtest unittest localunittest integration localintegration \ rootlessintegration localrootlessintegration shell install install-bash \ - install-man clean cfmt shfmt shellcheck \ + install-man clean cfmt shfmt localshfmt shellcheck \ vendor verify-changelog verify-dependencies