Skip to content

Commit

Permalink
Use shfmt to format shell programs
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Nov 11, 2023
1 parent fa639ab commit b416ad3
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 25 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- main
- dev/golangci-lint
name: Lint
jobs:
golangci-lint:
Expand All @@ -23,3 +22,10 @@ jobs:
with:
version: v1.54.2
args: --timeout=5m ./...
shfmt:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run shfmt
run: make shfmt
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ include hack/make/dep_gosec.mk
include hack/make/dep_gotestsum.mk
include hack/make/dep_migrate.mk
include hack/make/dep_mockgen.mk
include hack/make/dep_shfmt.mk
include hack/make/dep_tparse.mk

define NEWLINE
Expand Down Expand Up @@ -119,6 +120,20 @@ gen-ent: $(ENT)
--feature sql/versioned-migration \
--target=./internal/storage/persistence/ent/db

shfmt: SHELL_PROGRAMS := $(shell find $(CURDIR)/hack -name *.sh)
shfmt: $(SHFMT) # @HELP Run shfmt to format shell programs in the hack directory.
shfmt \
--list \
--write \
--diff \
--simplify \
--language-dialect=posix \
--indent=0 \
--case-indent \
--space-redirects \
--func-next-line \
$(SHELL_PROGRAMS)

gosec: # @HELP Run gosec security scanner.
gosec: $(GOSEC)
gosec \
Expand Down
2 changes: 1 addition & 1 deletion hack/build_dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ GIT_HASH="$git_hash"
VERSION_PATH="$version_path"

if [ "$1" = "shellvars" ]; then
cat <<EOF
cat << EOF
VERSION_MINOR="$MINOR"
VERSION_SHORT="$SHORT"
VERSION_LONG="$LONG"
Expand Down
15 changes: 9 additions & 6 deletions hack/build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eu
TARGET=${1:-}
if [ -z "$TARGET" ]; then
echo "Service name must be supplied, e.g.:"
echo "\t $ `basename "$0"` enduro"
echo "\t $ $(basename "$0") enduro"
exit 1
fi
case "$TARGET" in
Expand All @@ -19,14 +19,14 @@ case "$TARGET" in
TARGET="enduro-a3m-worker"
FOLDER="."
;;
"enduro-dashboard")
"enduro-dashboard")
IMAGE_NAME="enduro-dashboard"
TARGET="enduro-dashboard"
FOLDER="dashboard"
;;
*)
echo "Accepted values: enduro, enduro-a3m-worker, enduro-dashboard.";
exit 1;
echo "Accepted values: enduro, enduro-a3m-worker, enduro-dashboard."
exit 1
;;
esac

Expand All @@ -38,7 +38,10 @@ IMAGE_NAME="${TILT_EXPECTED_REF:-$DEFAULT_IMAGE_NAME}"
BUILD_OPTS="${BUILD_OPTS:-}"

GO_VERSION=$(cat .go-version)
test -n "$GO_VERSION" || { echo "Error: .go-version is empty."; exit 1; }
test -n "$GO_VERSION" || {
echo "Error: .go-version is empty."
exit 1
}

env DOCKER_BUILDKIT=1 docker build \
-t "$IMAGE_NAME" \
Expand All @@ -50,4 +53,4 @@ env DOCKER_BUILDKIT=1 docker build \
--build-arg="VERSION_SHORT=$VERSION_SHORT" \
--build-arg="VERSION_GIT_HASH=$VERSION_GIT_HASH" \
$BUILD_OPTS \
$FOLDER
$FOLDER
20 changes: 9 additions & 11 deletions hack/coverpkgs.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

set -o errexit
set -o pipefail
set -o nounset
set -eu

curdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
curdir=$(cd "$(dirname "$0")" && pwd)

cd ${curdir}/..

Expand All @@ -17,9 +15,9 @@ cd ${curdir}/..
# $ go tool cover -func=html
#

go list ./... \
| grep -v "/artefactual-sdps/enduro/hack" \
| grep -v "/artefactual-sdps/enduro/internal/api/gen" \
| grep -v "/artefactual-sdps/enduro/internal/api/design" \
| grep -v "/fake" \
| paste -sd","
go list ./... |
grep -v "/artefactual-sdps/enduro/hack" |
grep -v "/artefactual-sdps/enduro/internal/api/gen" |
grep -v "/artefactual-sdps/enduro/internal/api/design" |
grep -v "/fake" |
paste -sd","
9 changes: 3 additions & 6 deletions hack/genpkgs/load.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

set -o errexit
set -o pipefail
set -o nounset
set -o xtrace
set -eux

__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__dir=$(cd "$(dirname "$0")" && pwd)

go run ${__dir}/main.go > ${__dir}/data.csv

Expand Down
18 changes: 18 additions & 0 deletions hack/make/dep_shfmt.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$(call _assert_var,MAKEDIR)
$(call _conditional_include,$(MAKEDIR)/base.mk)
$(call _assert_var,UNAME_OS2)
$(call _assert_var,UNAME_ARCH2)
$(call _assert_var,CACHE_VERSIONS)
$(call _assert_var,CACHE_BIN)

SHFMT_VERSION ?= 3.7.0

SHFMT := $(CACHE_VERSIONS)/shfmt/$(SHFMT_VERSION)
$(SHFMT):
rm -f $(CACHE_BIN)/shfmt
mkdir -p $(CACHE_BIN)
curl -sSL https://github.com/mvdan/sh/releases/download/v$(SHFMT_VERSION)/shfmt_v$(SHFMT_VERSION)_$(UNAME_OS2)_$(UNAME_ARCH2) > $(CACHE_BIN)/shfmt
chmod +x $(CACHE_BIN)/shfmt
rm -rf $(dir $(SHFMT))
mkdir -p $(dir $(SHFMT))
touch $(SHFMT)

0 comments on commit b416ad3

Please sign in to comment.