Files
2026-11-05 04:44:33 +00:00

23 lines
1.2 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 用法:entrypoint.sh <files> <severity> <version>
# files 是空白分隔的路徑或萬用字元(相對於 workspace),沒有符合的檔案就略過(也不下載);version 是 shellcheck 的版本(例如 v0.10.0),依版本下載。
set -euo pipefail
cd "${GITHUB_WORKSPACE:-$PWD}"
shopt -s nullglob globstar
# shellcheck disable=SC2206 # 依空白拆開,並由 shell 展開萬用字元(不符合的萬用字元展開成空)
files=(${1:-*.sh})
if [ ${#files[@]} -eq 0 ]; then
echo "沒有符合「${1:-*.sh}」的檔案,略過 shellcheck"
exit 0
fi
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[@]}"