@@ -0,0 +1,6 @@
|
|||||||
|
.git
|
||||||
|
.gitea
|
||||||
|
test
|
||||||
|
*.md
|
||||||
|
go.mod
|
||||||
|
icon.*
|
||||||
@@ -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
|
||||||
+16
@@ -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"]
|
||||||
@@ -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`)。
|
||||||
+11
@@ -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 }}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# 用法:entrypoint.sh <command>;工作目錄是掛進來的 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"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512"><rect width="512" height="512" rx="104" fill="#0d9488"/><rect fill="none" stroke="#fff" stroke-width="28" stroke-linecap="round" stroke-linejoin="round" x="90" y="116" width="332" height="280" rx="36"/><path fill="none" stroke="#fff" stroke-width="28" stroke-linecap="round" stroke-linejoin="round" d="M150 210l56 46-56 46M240 312h110"/></svg>
|
||||||
|
After Width: | Height: | Size: 430 B |
@@ -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
|
||||||
Reference in New Issue
Block a user