Skip to content

Commit

Permalink
ci: bump shfmt to 3.5.1, simplify CI setup
Browse files Browse the repository at this point in the history
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 -f to get the list of all
   shell files, and supply the list as an argument to shfmt.

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.

Unfortunately, we can't use shfmt -f together with Docker (unless we run
not one but two containers, that is), so let's use git ls-files and a
couple of greps to find out all shell files.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Jun 1, 2022
1 parent bd71878 commit 52d5a3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,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/[email protected]
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

Expand Down
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,14 @@ shellcheck:
man/*.sh script/*
# TODO: add shellcheck for more sh files (contrib/completions/bash/runc).

shfmt localshfmt: SH_SRC=$(shell git ls-files | grep -v ^vendor/ | grep -E '(.sh|.bash|.bats|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 $(SH_SRC)

localshfmt:
shfmt -d -w $(SH_SRC)

vendor:
$(GO) mod tidy
Expand All @@ -184,5 +187,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-dependencies

0 comments on commit 52d5a3a

Please sign in to comment.