File tree Expand file tree Collapse file tree 4 files changed +126
-3
lines changed
Expand file tree Collapse file tree 4 files changed +126
-3
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,5 @@ ci-mod: mod
5151 ./scripts/git-check-dirty
5252
5353.PHONY : ci-sh
54- ci-sh : shfmt
55- @./scripts/sh-checks
54+ ci-sh : shfmt shellcheck
5655 @./scripts/git-check-dirty
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ set -e
4+ # set -u
5+ set -o pipefail
6+
7+ # should be called from root dir.
8+
9+ find ./ \
10+ -type f \
11+ -not -path ' ./.git/*' \
12+ -not -path ' ./vendor/*' \
13+ \( -name ' *.bash' -o -name ' *.sh' -o -executable \) \
14+ -print0 | while IFS= read -r -d ' ' file; do
15+ if file " ${file} " | grep -qE ' shell script|POSIX shell script|Bourne-Again shell script|bash script|a sh script' ; then
16+ echo " ${* } ${file} "
17+ " ${@ } " " ${file} "
18+ fi
19+ done
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ set -e
4+ # set -u
5+ set -o pipefail
6+
7+ get_protoc_latest_version () {
8+ JS_BODY=$( curl --silent --fail --location " https://api.github.com/repos/koalaman/shellcheck/releases/latest" )
9+ echo " ${JS_BODY} " | jq ' .tag_name' --raw-output
10+ }
11+
12+ package_os () {
13+ case " $( uname) " in
14+ " Darwin" )
15+ echo " darwin"
16+ ;;
17+ " Linux" )
18+ echo " linux"
19+ ;;
20+ esac
21+ }
22+
23+ package_arch () {
24+ local arch
25+ arch=" $( uname -m | tr ' [:upper:]' ' [:lower:]' ) "
26+ case " ${arch} " in
27+ " x86_64" )
28+ echo " x86_64"
29+ ;;
30+ " aarch64" )
31+ echo " aarch64"
32+ ;;
33+ " arm64" )
34+ echo " aarch64"
35+ ;;
36+ esac
37+ }
38+
39+ VERSION=" "
40+ DESTINATION_DIR=" "
41+
42+ UNKNOWN_ARGS=()
43+ while (( $# )) ; do
44+ case " ${1} " in
45+ -v | --version)
46+ VERSION=" ${2} "
47+ shift 2
48+ ;;
49+ -d | --destination)
50+ DESTINATION_DIR=" ${2} "
51+ shift 2
52+ ;;
53+ * )
54+ UNKNOWN_ARGS+=(" ${1} " )
55+ shift
56+ ;;
57+ esac
58+ done
59+
60+ if [[ ${VERSION} == " " ]]; then
61+ VERSION=" $( get_protoc_latest_version) "
62+ fi
63+
64+ if [[ ${DESTINATION_DIR} == " " ]]; then
65+ echo " missing destination argument"
66+ exit 1
67+ fi
68+
69+ # uninstall previous version
70+ rm -rf " ${DESTINATION_DIR} " /bin/shellcheck
71+
72+ DL_URL=" https://github.com/koalaman/shellcheck/releases/download/${VERSION} /shellcheck-${VERSION} .$( package_os) .$( package_arch) .tar.xz"
73+
74+ curl \
75+ --silent \
76+ --fail \
77+ --location \
78+ " ${DL_URL} " \
79+ -o " ${DESTINATION_DIR} /shellcheck.tar.xz"
80+
81+ tar \
82+ --extract \
83+ --xz \
84+ --file=" ${DESTINATION_DIR} /shellcheck.tar.xz" \
85+ --strip-components=1 \
86+ --directory=" ${DESTINATION_DIR} /bin"
87+
88+ rm -f " ${DESTINATION_DIR} /shellcheck.tar.xz"
89+ rm -f " ${DESTINATION_DIR} /bin/LICENSE.txt"
90+ rm -f " ${DESTINATION_DIR} /bin/README.txt"
91+
92+ # to update all dates in order for make file to get it as new (check stat "${DESTINATION_DIR}/bin/shellcheck")
93+ touch " ${DESTINATION_DIR} /bin/shellcheck"
Original file line number Diff line number Diff line change @@ -178,4 +178,16 @@ $(TOOLS_BIN)/shfmt: $(TOOLS_DB)/shfmt.$(SHFMT_VER).$(GO_VER).ver
178178
179179.PHONY : shfmt
180180shfmt : $(TOOLS_BIN ) /shfmt
181- # # <shfmt>
181+ @./scripts/foreach-script $(TOOLS_BIN ) /shfmt --simplify --language-dialect auto --case-indent --indent 2 --write
182+ # # </shfmt>
183+
184+ # # <shellcheck>
185+ # https://github.com/koalaman/shellcheck/releases
186+ SHELLCHECK_VER := v0.10.0
187+ $(TOOLS_BIN ) /shellcheck : $(TOOLS_DB ) /shellcheck.$(SHELLCHECK_VER ) .ver | $(TOOLS_BIN )
188+ @./scripts/install-shellcheck --version $(SHELLCHECK_VER ) --destination $(TOOLS_DIR )
189+
190+ .PHONY : shellcheck
191+ shellcheck : $(TOOLS_BIN ) /shellcheck
192+ @./scripts/foreach-script $(TOOLS_BIN ) /shellcheck --external-sources --format=tty --severity=info
193+ # # </shellcheck>
You can’t perform that action at this time.
0 commit comments