commit e4d4d815dcae1c6b10a375ed1bbbe29853009f16 Author: bot Date: Thu Nov 5 02:54:20 2026 +0000 初始版本:從 feather-vault 搬出 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1bd89cc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.gitea +test +*.md +go.mod +icon.* diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml new file mode 100644 index 0000000..8e32774 --- /dev/null +++ b/.gitea/workflows/ci.yaml @@ -0,0 +1,20 @@ +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 + - name: shellcheck + run: | + curl -fsSL https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.linux.x86_64.tar.xz | tar -xJ -C "$RUNNER_TEMP" --strip-components=1 + "$RUNNER_TEMP/shellcheck" -x -S warning ./*.sh + - uses: ./ + with: + command: echo ok && git --version && make --version | head -n 1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..531faad --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM ubuntu:24.04 +ENV DEBIAN_FRONTEND=noninteractive +# Chromium 的系統依賴與字型和 scripts/chromium-deps.sh 同一份清單;沒有字型 Chromium 會當掉 +RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \ + ca-certificates curl git make xz-utils python3 \ + libcups2t64 libxres1 libavahi-client3 libavahi-common3 libasound2t64 libatk1.0-0t64 libatk-bridge2.0-0t64 libatspi2.0-0t64 libcairo2 libdrm2 libgbm1 \ + libnspr4 libnss3 libpango-1.0-0 libxcomposite1 libxdamage1 libxfixes3 libxkbcommon0 libxrandr2 \ + libfontconfig1 libfreetype6 libfribidi0 libharfbuzz0b libpixman-1-0 libpng16-16t64 libthai0 \ + libxcb-render0 libxcb-shm0 libxi6 libxrender1 libdatrie1 libgraphite2-3 \ + fonts-dejavu-core fonts-wqy-microhei \ + && rm -rf /var/lib/apt/lists/* +# Go 與 Node 不放進映像檔:版本由 Gitea 的 Actions 變數 GO_VERSION、NODE_VERSION 指定,entrypoint.sh 依版本下載到快取(.ci-home/toolchains) +ENV GOFLAGS=-buildvcs=false +# 腳本打包進映像檔(action 在獨立的 repo,呼叫端的 workspace 裡沒有這些檔案);發佈新版時要換標籤,runner 才會重建映像檔 +COPY . /action +ENTRYPOINT ["/bin/bash", "/action/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..70ce8ce --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# ci-env + +在 Docker 容器裡執行一段 shell 指令:映像檔有 Chromium 的系統依賴與字型、git、make、python3;Go 與 Node 依環境變數 `GO_VERSION`、`NODE_VERSION` 下載到 workspace 的 `.ci-home` 快取(沒設的不裝)。 + +## 用法 + +版本由呼叫端的 Gitea Actions 變數決定(例如 `vars.ACTION_CI_ENV_VERSION`),不要用分支名稱:runner 依 ref 重用舊映像檔,改了腳本不會生效,所以每次改動都發新標籤。 + +```yaml +- uses: https://gitea.jsc.idv.tw/actions/ci-env@${{ vars.ACTION_CI_ENV_VERSION }} + with: + command: ... +``` + +## 輸入 + +|名稱|必填|預設|說明| +|---|---|---|---| +|`command`|是||要執行的 shell 指令(工作目錄是 workspace,已設好 GOPATH、PATH 等)| + +## 開發 + +`ci.yaml` 跑 shellcheck、、建置映像檔,並用 `uses: ./` 實際執行一次。 + +圖示:`icon.svg`(Gitea 儲存庫頭像用 `icon.png`)。 diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..ae4ad0f --- /dev/null +++ b/action.yml @@ -0,0 +1,11 @@ +name: ci-env +description: "在 Docker 容器裡執行一段 shell 指令:Chromium 的系統依賴與字型、git、make、python3,Go 與 Node 依環境變數 GO_VERSION、NODE_VERSION 下載到 workspace 的 .ci-home 快取(沒設的不裝)。要在 checkout 之後使用" +inputs: + command: + description: "要執行的 shell 指令(工作目錄是 workspace,已設好 GOPATH、PATH 等)" + required: true +runs: + using: docker + image: Dockerfile + args: + - ${{ inputs.command }} diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..480a52f --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# 用法:entrypoint.sh ;工作目錄是掛進來的 workspace。先設好工具鏈與快取環境,再用 bash 執行 command +set -euo pipefail +cmd=${1:?缺少 command} +cd "${GITHUB_WORKSPACE:-$PWD}" +. "$(dirname "${BASH_SOURCE[0]}")/toolchain.sh" +exec bash -euo pipefail -c "$cmd" diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..b2c4c4c Binary files /dev/null and b/icon.png differ diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..436d89b --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/toolchain.sh b/toolchain.sh new file mode 100644 index 0000000..f0571e6 --- /dev/null +++ b/toolchain.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# 工具鏈與快取環境:被 source(不單獨執行),呼叫端已 set -euo pipefail 並 cd 到 workspace。 +# 效果:HOME/GOPATH/GOCACHE 指到 workspace 的 .ci-home,GO_VERSION、NODE_VERSION 有設的就依版本下載到快取並加進 PATH(沒設的不裝)。 +# 快取(Go 模組、npm、rod 下載的 Chromium 等)放在 workspace,讓 workflow 的 actions/cache 存取 +export HOME="$PWD/.ci-home" GOPATH="$PWD/.ci-home/go" GOCACHE="$PWD/.ci-home/go-build" npm_config_cache="$PWD/.ci-home/npm" +mkdir -p "$HOME" +git config --global --add safe.directory "$PWD" +tc="$PWD/.ci-home/toolchains" +fetch_toolchain() { # <名稱> <網址> <解壓參數> <檢查的執行檔>;下載到暫存目錄再改名,中途失敗不留半套 + local dir="$tc/$1" tmp + [ -x "$dir/bin/$4" ] && return 0 + echo "下載 $1" + tmp=$(mktemp -d "$tc/.tmp.XXXXXX") + curl -fsSL "$2" | tar "$3" -C "$tmp" --strip-components=1 + rm -rf "$dir" && mv "$tmp" "$dir" +} +mkdir -p "$tc" +# Go 與 Node 的版本通常來自 Gitea 的 Actions 變數(workflow 的 env 傳進來),依版本裝在快取裡,換版本只要改變數 +if [ -n "${GO_VERSION:-}" ]; then + fetch_toolchain "go-$GO_VERSION" "https://go.dev/dl/go$GO_VERSION.linux-amd64.tar.gz" -xz go + export PATH="$tc/go-$GO_VERSION/bin:$PATH" + if [ -f go.mod ]; then + want=$(sed -n 's/^go //p' go.mod) + [ "$(go env GOVERSION)" = "go$want" ] || { echo "GO_VERSION($GO_VERSION)和 go.mod($want)不同,請更新變數" >&2; exit 1; } + fi +fi +if [ -n "${NODE_VERSION:-}" ]; then + fetch_toolchain "node-$NODE_VERSION" "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" -xJ node + export PATH="$tc/node-$NODE_VERSION/bin:$PATH" +fi