Skip to content

Commit

Permalink
chore: add local shellcheck tools (#521)
Browse files Browse the repository at this point in the history
Signed-off-by: bitliu <bitliu@tencent.com>
  • Loading branch information
Xunzhuo authored Oct 13, 2022
1 parent 01a638c commit 0be1aef
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tools/make/golang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GO_VERSION = $(shell grep -oE "^go [[:digit:]]*\.[[:digit:]]*" go.mod | cut -d'
# Build the target binary in target platform.
# The pattern of build.% is `build.{Platform}.{Command}`.
# If we want to build envoy-gateway in linux amd64 platform,
# just execute make build.linux_amd64.envoy-gateway.
# just execute make go.build.linux_amd64.envoy-gateway.
.PHONY: go.build.%
go.build.%:
$(eval COMMAND := $(word 2,$(subst ., ,$*)))
Expand Down
7 changes: 4 additions & 3 deletions tools/make/lint.mk
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ lint.whitenoise: $(tools/whitenoise)
@echo Running WhiteNoise linter ...
$(tools/whitenoise)

# GitHub has shellcheck pre-installed

.PHONY: lint.shellcheck
lint: lint.shellcheck
lint.shellcheck:
lint-deps: $(tools/shellcheck)
lint.shellcheck: $(tools/shellcheck)
@echo Running Shellcheck linter ...
@shellcheck tools/hack/*.sh
$(tools/shellcheck) tools/hack/*.sh

.PHONY: gen-check
gen-check: generate manifests
Expand Down
20 changes: 20 additions & 0 deletions tools/make/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,23 @@ $(tools.bindir)/%.d/venv: $(tools.srcdir)/%/requirements.txt
$@/bin/pip3 install -r $< || (rm -rf $@; exit 1)
$(tools.bindir)/%: $(tools.bindir)/%.d/venv
ln -sf $*.d/venv/bin/$* $@

ifneq ($(GOOS),windows)
# Shellcheck
# ==========
#
tools/shellcheck = $(tools.bindir)/shellcheck
SHELLCHECK_VERSION=0.8.0
SHELLCHECK_ARCH=$(shell uname -m)
# shellcheck uses the same binary on Intel and Apple Silicon Mac.
ifeq ($(GOOS),darwin)
SHELLCHECK_ARCH=x86_64
endif
SHELLCHECK_TXZ = https://github.com/koalaman/shellcheck/releases/download/v$(SHELLCHECK_VERSION)/shellcheck-v$(SHELLCHECK_VERSION).$(GOOS).$(SHELLCHECK_ARCH).tar.xz
tools/bin/$(notdir $(SHELLCHECK_TXZ)):
mkdir -p $(@D)
curl -sfL $(SHELLCHECK_TXZ) -o $@
%/bin/shellcheck: %/bin/$(notdir $(SHELLCHECK_TXZ))
mkdir -p $(@D)
tar -C $(@D) -Jxmf $< --strip-components=1 shellcheck-v$(SHELLCHECK_VERSION)/shellcheck
endif

0 comments on commit 0be1aef

Please sign in to comment.