This commit is contained in:
+12
-3
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# 用法:entrypoint.sh <files> <severity>;files 是空白分隔的路徑或萬用字元(相對於 workspace),沒有符合的檔案就略過
|
||||
# 用法:entrypoint.sh <files> <severity> <version>
|
||||
# files 是空白分隔的路徑或萬用字元(相對於 workspace),沒有符合的檔案就略過(也不下載);version 是 shellcheck 的版本(例如 v0.10.0),依版本下載。
|
||||
set -euo pipefail
|
||||
cd "${GITHUB_WORKSPACE:-$PWD}"
|
||||
shopt -s nullglob globstar
|
||||
@@ -9,5 +10,13 @@ if [ ${#files[@]} -eq 0 ]; then
|
||||
echo "沒有符合「${1:-*.sh}」的檔案,略過 shellcheck"
|
||||
exit 0
|
||||
fi
|
||||
echo "shellcheck(嚴重度 ${2:-warning} 以上):${files[*]}"
|
||||
exec shellcheck -x -S "${2:-warning}" "${files[@]}"
|
||||
ver=${3:?缺少 shellcheck 版本:請用 Gitea 變數指定(例如 TOOL_SHELLCHECK_VERSION=v0.10.0)}
|
||||
dir=${SHELLCHECK_DIR:-/tmp/shellcheck-$ver}
|
||||
if [ ! -x "$dir/shellcheck" ]; then
|
||||
echo "下載 shellcheck $ver"
|
||||
mkdir -p "$dir"
|
||||
curl -fsSL "https://github.com/koalaman/shellcheck/releases/download/$ver/shellcheck-$ver.linux.x86_64.tar.xz" | tar -xJ -C "$dir" --strip-components=1 "shellcheck-$ver/shellcheck" \
|
||||
|| { echo "下載 shellcheck $ver 失敗(版本不存在或連不上 GitHub)" >&2; rm -rf "$dir"; exit 1; }
|
||||
fi
|
||||
echo "shellcheck $ver(嚴重度 ${2:-warning} 以上):${files[*]}"
|
||||
exec "$dir/shellcheck" -x -S "${2:-warning}" "${files[@]}"
|
||||
|
||||
Reference in New Issue
Block a user