9 Commits
Author SHA1 Message Date
bot 0289933c72 調整:ci/cd 一致化(action-ci 自動偵測、action-cd)、版本計算抽到 next-version
ci / test (pull_request) Successful in 8s
cd / tag (pull_request) Successful in 4s
2026-11-05 04:12:39 +00:00
bot a39fa3332f 調整:cd 改成任何分支 → main 的 PR 合併時觸發
ci / test (push) Successful in 6s
2026-11-05 03:57:32 +00:00
bot 5f48d105bb 調整:cd 觸發條件參考羽藏,只在 dev → main 的 PR 合併時發版
ci / test (push) Successful in 4s
2026-11-05 03:53:28 +00:00
bot 14e631cca6 調整:cd.yaml 不查 Go 套件庫(go_registry: false)
ci / test (push) Successful in 4s
2026-11-05 03:30:56 +00:00
bot 6207e24fb0 新增:cd.yaml,main 的 ci 通過後用 release-go 算版本並打標籤 2026-11-05 03:30:07 +00:00
bot 031de65d55 修正:清單輸入濾掉空行,避免 docker create 把空字串當成映像檔名稱 2026-11-05 03:28:45 +00:00
bot 2176296991 調整:所有版本號改成從 Gitea 變數取得 2026-11-05 03:24:34 +00:00
bot c97f8b16aa 新增:docker_build 用唯一標籤建置,可實際執行並檢查輸出
ci / test (push) Successful in 5s
2026-11-05 03:20:03 +00:00
bot 6a1819e2a1 修正:圖示檔名改成 icon.*
ci / test (push) Successful in 22s
2026-11-05 03:16:57 +00:00
7 changed files with 102 additions and 27 deletions
+22
View File
@@ -0,0 +1,22 @@
name: cd
# 只在「任何分支 → main」的 PR 合併時發版:action-cd 用 next-version 算下一版,沒有跳過就在 PR 來源分支的最新提交(pull_request.head.sha)上打標籤並推送。
# branches 寫死 main,來源分支不限;PR 沒合併就關閉時,tag 工作在工作層級跳過。直接推送 main 不發版。
# 版本只遞增 patch、每位最大 9,沒有標籤時從 v0.0.1 開始。只動文件、圖示、測試、.gitea/、go.mod 時不發版(這些不會進映像檔,也不影響使用者)。
# 呼叫端用標籤引用這個 action(版本取自 Gitea 變數),所以發版後要到呼叫端把 ACTION_<名稱>_VERSION 改成新標籤才會生效。
# 沒有手動觸發:發版失敗時重跑這個 workflow 的 run。
on:
pull_request:
types: [closed]
branches: [main]
# 排隊、不取消:連續推送依序發版,版本不重複
concurrency:
group: cd
cancel-in-progress: false
jobs:
tag:
if: ${{ github.event.pull_request.merged == true }}
runs-on: docker-ubuntu
steps:
- uses: https://gitea.jsc.idv.tw/actions/action-cd@${{ vars.ACTION_ACTION_CD_VERSION }}
with:
token: ${{ secrets.TOKEN || github.token }}
+3 -2
View File
@@ -11,5 +11,6 @@ jobs:
runs-on: docker-ubuntu
steps:
- uses: actions/checkout@v4
- name: 預設輸入(沒有腳本、不跑測試)
uses: ./
- uses: ./
with:
checkout: false
+22 -12
View File
@@ -1,25 +1,35 @@
# action-ci
action repo 的共用 CI:先 `shellcheck`,再(可選)在 `ci-env` 容器裡跑 Go 腳本測試(`GO_VERSION=go.mod`,用 go.mod 的版本),最後(可選)`docker build` 檢查映像檔。
action repo 的共用 CI,自動偵測、不必設開關:
1. checkout(可關)
2. `shellcheck`(沒有符合的檔案就略過)
3. Go 腳本測試:有 `go.mod` 與 `test/` 才跑,在 `ci-env` 容器裡執行,`GO_VERSION=go.mod`(用 go.mod 的版本)
4. 建置映像檔:有 `Dockerfile` 才跑,映像檔標籤是 `action-test:<sha>`(唯一,不會撞到 runner 上的舊映像檔);有設 `docker_run_args` 時再實際執行一次並檢查輸出
```yaml
steps:
- uses: actions/checkout@v4
- uses: https://gitea.jsc.idv.tw/actions/action-ci@v0.0.1
with:
go_test: true
docker_build: true
- uses: https://gitea.jsc.idv.tw/actions/action-ci@${{ vars.ACTION_ACTION_CI_VERSION }}
```
## 輸入
|名稱|預設|說明|
|---|---|---|
|`shellcheck_files`|`*.sh`|shellcheck 要檢查的檔案(空白分隔、可用萬用字元),沒有符合的就略過|
|`go_test`|`false`|`true`=跑 Go 測試|
|`go_test_command`|`go vet ./... && go test ./test/`|Go 測試的指令|
|`docker_build`|`false`|`true`=`docker build` 檢查 Dockerfile|
|`checkout`|`true`|先 checkout;`false`=呼叫端已經 checkout(例如要用 `uses: ./` 測自己)|
|`shellcheck_files`|`*.sh`|shellcheck 要檢查的檔案(空白分隔、可用萬用字元)|
|`go_test_command`|`go vet ./... && go test ./test/`|有 `go.mod` 與 `test/` 時執行的指令|
|`docker_run_args`||建置後實際執行容器的 entrypoint 參數(每行一個),空=只建置不執行|
|`docker_run_options`||執行容器的 `docker create` 選項(每行一個,例如 `--env=INPUT_TASK=x`)|
|`docker_run_expect`||容器輸出必須包含的字串,空=只檢查結束碼|
內部引用的 `shellcheck`、`ci-env` 版本寫死在 `action.yml`,升級要先發它們再發 `action-ci`。
不要對 Docker action 用 `uses: ./` 自測:這台 runner 會依名稱重用舊映像檔,可能跑到別的專案的映像檔。
圖示:`icon.svg`(頭像用 `icon.png`)。
內部用的 `shellcheck`、`ci-env` 版本取自呼叫端 repo 的 Gitea 變數 `ACTION_SHELLCHECK_VERSION`、`ACTION_CI_ENV_VERSION`(不寫死在 `action.yml`),所以呼叫端要先設好這兩個變數。
## 開發與發版
- CI(`ci.yaml`):用自己(`uses: ./`)檢查 shellcheck。
- CD(`cd.yaml`):「任何分支 → `main`」的 PR 合併時,用 [action-cd](https://gitea.jsc.idv.tw/actions/action-cd) 算下一個版本([next-version](https://gitea.jsc.idv.tw/actions/next-version),只遞增 patch、每位最大 9)並在 PR 來源最新提交上打標籤;只動文件、圖示、測試、`.gitea/`、`go.mod` 時不發版。直接推送 `main` 不發版。
- 呼叫端要把 Gitea 變數 `ACTION_ACTION_CI_VERSION` 改成新標籤才會採用。
- 圖示:`icon.svg`(儲存庫頭像用 `icon.png`)。
+32 -13
View File
@@ -1,33 +1,52 @@
name: action-ci
description: "action repo 的共用 CI:shellcheck → Go 腳本測試(在 ci-env 容器裡,Go 版本取 go.mod)→ 建置映像檔。要在 checkout 之後使用,各步驟用輸入開關"
description: "action repo 的共用 CI:checkout → shellcheck → Go 腳本測試(有 go.mod 與 test/ 才跑,在 ci-env 容器裡,Go 版本取 go.mod)→ 建置映像檔(有 Dockerfile 才跑,可選擇實際執行並檢查輸出)。自動偵測,各 repo 的 ci.yaml 不必設開關。內部用的 shellcheck、ci-env 版本取自呼叫端的 Gitea 變數 ACTION_SHELLCHECK_VERSION、ACTION_CI_ENV_VERSION"
inputs:
checkout:
description: "true=先 checkout;false=呼叫端已經 checkout(例如要用 uses: ./ 測自己)"
default: "true"
shellcheck_files:
description: "shellcheck 要檢查的檔案(空白分隔,可用萬用字元);沒有符合的檔案就略過"
default: "*.sh"
go_test:
description: "true=跑 Go 測試"
default: "false"
go_test_command:
description: "go_test 為 true 時執行的指令"
description: "有 go.mod 與 test/ 時執行的指令"
default: "go vet ./... && go test ./test/"
docker_build:
description: "true=用 docker build 檢查 Dockerfile 建得起來"
default: "false"
docker_run_args:
description: "docker build 之後實際執行容器的參數(entrypoint 的參數,每行一個);空=只建置不執行"
default: ""
docker_run_options:
description: "執行容器的 docker create 選項(每行一個,例如 --env=INPUT_TASK=resolve-channel)"
default: ""
docker_run_expect:
description: "容器輸出必須包含的字串;空=只檢查結束碼"
default: ""
runs:
using: composite
steps:
- name: checkout
if: ${{ inputs.checkout == 'true' }}
uses: actions/checkout@v4
- name: 偵測
id: detect
shell: bash
run: |
[ -f go.mod ] && [ -d test ] && echo "go=true" >> "$GITHUB_OUTPUT" || echo "go=false" >> "$GITHUB_OUTPUT"
[ -f Dockerfile ] && echo "docker=true" >> "$GITHUB_OUTPUT" || echo "docker=false" >> "$GITHUB_OUTPUT"
- name: shellcheck
uses: https://gitea.jsc.idv.tw/actions/shellcheck@v0.0.1
uses: https://gitea.jsc.idv.tw/actions/shellcheck@${{ vars.ACTION_SHELLCHECK_VERSION }}
with:
files: ${{ inputs.shellcheck_files }}
- name: Go 測試
if: ${{ inputs.go_test == 'true' }}
uses: https://gitea.jsc.idv.tw/actions/ci-env@v0.0.2
if: ${{ steps.detect.outputs.go == 'true' }}
uses: https://gitea.jsc.idv.tw/actions/ci-env@${{ vars.ACTION_CI_ENV_VERSION }}
env:
GO_VERSION: go.mod
with:
command: ${{ inputs.go_test_command }}
- name: 建置映像檔
if: ${{ inputs.docker_build == 'true' }}
if: ${{ steps.detect.outputs.docker == 'true' }}
shell: bash
run: docker build -t "action-test:$GITHUB_SHA" .
env:
RUN_ARGS: ${{ inputs.docker_run_args }}
RUN_OPTIONS: ${{ inputs.docker_run_options }}
RUN_EXPECT: ${{ inputs.docker_run_expect }}
run: bash "${{ github.action_path }}/docker-check.sh"
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# 建置映像檔(唯一標籤 action-test:<sha>,避免 runner 重用同名舊映像檔),可選擇實際執行一次並檢查輸出。
# 環境變數:RUN_OPTIONS、RUN_ARGS(各是「每行一個參數」的清單,空=不執行)、RUN_EXPECT(輸出必須包含的字串)。
# 用 docker create + docker cp 把 workspace 放進容器:job 本身可能也在容器裡,用 -v 掛載的路徑會對不上主機。
set -euo pipefail
image="action-test:${GITHUB_SHA:-local}"
docker build -t "$image" .
[ -n "${RUN_ARGS:-}" ] || exit 0
# 清單是「每行一個」,濾掉空行(多行 YAML 值結尾的換行會產生空字串,docker 會把它當成映像檔名稱)
mapfile -t opts < <(printf '%s\n' "${RUN_OPTIONS:-}" | sed '/^[[:space:]]*$/d')
mapfile -t args < <(printf '%s\n' "$RUN_ARGS" | sed '/^[[:space:]]*$/d')
id=$(docker create -w /w -e GITHUB_WORKSPACE=/w "${opts[@]}" "$image" "${args[@]}")
trap 'docker rm -f "$id" >/dev/null 2>&1 || true' EXIT
docker cp "$PWD/." "$id:/w"
out=$(mktemp)
rc=0
docker start -a "$id" >"$out" 2>&1 || rc=$?
cat "$out"
[ "$rc" -eq 0 ] || { echo "容器以 $rc 結束" >&2; exit 1; }
if [ -n "${RUN_EXPECT:-}" ] && ! grep -qF -- "$RUN_EXPECT" "$out"; then
echo "輸出沒有包含「$RUN_EXPECT」" >&2
exit 1
fi
View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 685 B

After

Width:  |  Height:  |  Size: 685 B