commit e2cf1982c128e873590dea5b615340c58bd25376 Author: bot Date: Thu Nov 5 03:16:36 2026 +0000 初始版本 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..555e1b9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +.gitea +test +*.md +icon.* diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml new file mode 100644 index 0000000..5db7e3c --- /dev/null +++ b/.gitea/workflows/ci.yaml @@ -0,0 +1,16 @@ +name: ci +on: + push: + branches: [main] + pull_request: +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true +jobs: + test: + runs-on: docker-ubuntu + steps: + - uses: actions/checkout@v4 + - uses: ./ + with: + files: entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8218846 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:24.04 +ENV DEBIAN_FRONTEND=noninteractive +# shellcheck 固定 v0.10.0(從官方釋出檔下載,不用 apt 的舊版) +RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends ca-certificates curl xz-utils \ + && curl -fsSL https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.linux.x86_64.tar.xz | tar -xJ -C /usr/local/bin --strip-components=1 shellcheck-v0.10.0/shellcheck \ + && apt-get purge -y -qq curl xz-utils && apt-get autoremove -y -qq && rm -rf /var/lib/apt/lists/* +COPY . /action +ENTRYPOINT ["/bin/bash", "/action/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..38ce4a0 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# shellcheck + +用 shellcheck(v0.10.0)檢查 shell 腳本的 Docker action,映像檔已內建,不用每次下載。沒有符合的檔案就略過。 + +```yaml +- uses: https://gitea.jsc.idv.tw/actions/shellcheck@v0.0.1 + with: + files: "*.sh scripts/**/*.sh" + severity: warning +``` + +## 輸入 + +|名稱|預設|說明| +|---|---|---| +|`files`|`*.sh`|要檢查的檔案,空白分隔,可用萬用字元(支援 `**`)| +|`severity`|`warning`|回報的最低嚴重度:error、warning、info、style| + +圖示:`icon.svg`(頭像用 `icon.png`)。 diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..1316084 --- /dev/null +++ b/action.yml @@ -0,0 +1,15 @@ +name: shellcheck +description: "用 shellcheck 檢查 shell 腳本(Docker action,shellcheck v0.10.0)。沒有符合的檔案就略過。要在 checkout 之後使用" +inputs: + files: + description: "要檢查的檔案,空白分隔,可用萬用字元(相對於儲存庫根目錄,支援 **)" + default: "*.sh" + severity: + description: "回報的最低嚴重度:error、warning、info、style" + default: warning +runs: + using: docker + image: Dockerfile + args: + - ${{ inputs.files }} + - ${{ inputs.severity }} diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..d44c6e5 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# 用法:entrypoint.sh ;files 是空白分隔的路徑或萬用字元(相對於 workspace),沒有符合的檔案就略過 +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 +echo "shellcheck(嚴重度 ${2:-warning} 以上):${files[*]}" +exec shellcheck -x -S "${2:-warning}" "${files[@]}" diff --git a/shellcheck.png b/shellcheck.png new file mode 100644 index 0000000..2df77ed Binary files /dev/null and b/shellcheck.png differ diff --git a/shellcheck.svg b/shellcheck.svg new file mode 100644 index 0000000..3958a45 --- /dev/null +++ b/shellcheck.svg @@ -0,0 +1 @@ + \ No newline at end of file