8 Commits
Author SHA1 Message Date
bot 4c73271bbc 調整:ci/cd 一致化(action-ci 自動偵測、action-cd)、版本計算抽到 next-version
cd / tag (pull_request) Successful in 5s
ci / test (pull_request) Successful in 7s
2026-11-05 04:12:39 +00:00
bot f8496e2c46 調整:cd 改成任何分支 → main 的 PR 合併時觸發
ci / test (push) Successful in 6s
2026-11-05 03:57:42 +00:00
bot fb93e93004 調整:cd 觸發條件參考羽藏,只在 dev → main 的 PR 合併時發版
ci / test (push) Successful in 7s
2026-11-05 03:53:31 +00:00
bot 08ac8c51be 調整:cd.yaml 不查 Go 套件庫(go_registry: false)
ci / test (push) Successful in 20s
2026-11-05 03:30:56 +00:00
bot 34ba9df440 新增:cd.yaml,main 的 ci 通過後用 release-go 算版本並打標籤 2026-11-05 03:30:07 +00:00
bot 071b3ed2ff 調整:所有版本號改成從 Gitea 變數取得 2026-11-05 03:24:36 +00:00
bot a3d1acce41 調整:ci.yaml 改用共用的 action-ci 與 shellcheck
ci / test (push) Successful in 4s
2026-11-05 03:17:10 +00:00
bot 88844d74f7 修正:icon.png 底部被截掉
ci / test (push) Successful in 7s
2026-11-05 03:11:12 +00:00
5 changed files with 79 additions and 28 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 }}
+6 -4
View File
@@ -10,9 +10,11 @@ jobs:
test: test:
runs-on: docker-ubuntu runs-on: docker-ubuntu
steps: steps:
- uses: actions/checkout@v4 - uses: https://gitea.jsc.idv.tw/actions/action-ci@${{ vars.ACTION_ACTION_CI_VERSION }}
- uses: ./ - name: 自測
uses: ./
with: with:
cache_key: ci-run-selftest-${{ github.sha }} checkout: false
cache_restore_keys: ci-run-selftest- cache_files: README.md
cache_prefix: ci-run-selftest-
command: echo ok command: echo ok
+18 -14
View File
@@ -1,29 +1,33 @@
# ci-run # ci-run
組合 `ci-cache` 與 `ci-env`:先還原快取,再在容器裡執行指令。 組合 `ci-cache` 與 `ci-env`,跑一個 CI 工作:checkout → 還原快取 → 在容器裡執行指令。快取 key 由 `cache_files` 的內容雜湊決定(不用在每個工作重複 `hashFiles(...)`)。
## 用法
版本由呼叫端的 Gitea Actions 變數決定(例如 `vars.ACTION_CI_RUN_VERSION`),不要用分支名稱:runner 依 ref 重用舊映像檔,改了腳本不會生效,所以每次改動都發新標籤。
```yaml ```yaml
- uses: https://gitea.jsc.idv.tw/actions/ci-run@${{ vars.ACTION_CI_RUN_VERSION }} steps:
- uses: https://gitea.jsc.idv.tw/actions/ci-run@${{ vars.ACTION_CI_RUN_VERSION }}
with: with:
command: ... cache_files: go.sum web/package-lock.json
cache_key: ... command: bash scripts/ci.sh vet
``` ```
## 輸入 ## 輸入
|名稱|必填|預設|說明| |名稱|必填|預設|說明|
|---|---|---|---| |---|---|---|---|
|`command`|是||要在 ci-env 容器裡執行的 shell 指令| |`command`|是||要在 `ci-env` 容器裡執行的 shell 指令|
|`cache_key`|是||快取 key,例如 ci-home-${{ hashFiles('go.sum', 'web/package-lock.json') }}| |`cache_files`||`go.sum`|決定快取 key 的檔案(空白分隔),內容變了才換快取;不存在的檔案略過|
|`cache_restore_keys`|||找不到完全相同的 key 時,依序嘗試的前綴(每行一個)| |`cache_key`|||直接指定快取 key,有值就不用 `cache_files` 算|
|`cache_prefix`||`ci-home-`|快取 key 的前綴,找不到完全相同的 key 時也用它還原最近的快取|
|`checkout`||`true`|先 checkout;`false`=呼叫端已經 checkout|
|`name`||`ci`|執行指令的步驟名稱| |`name`||`ci`|執行指令的步驟名稱|
## 開發 ## 內部引用的版本
`ci.yaml` 跑 ,並用 `uses: ./` 實際執行一次。 `ci-cache`、`ci-env` 的版本取自呼叫端 repo 的 Gitea 變數 `ACTION_CI_CACHE_VERSION`、`ACTION_CI_ENV_VERSION`,不寫死在 `action.yml`,所以呼叫端要先設好這兩個變數。需要工具鏈時,呼叫端的工作流要有 `env: GO_VERSION`、`NODE_VERSION`。
圖示:`icon.svg`(Gitea 儲存庫頭像用 `icon.png`)。 ## 開發與發版
- CI(`ci.yaml`):用 [action-ci](https://gitea.jsc.idv.tw/actions/action-ci),並用 `uses: ./` 實際執行一次。
- 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_CI_RUN_VERSION` 改成新標籤才會採用。
- 圖示:`icon.svg`(儲存庫頭像用 `icon.png`)。
+32 -9
View File
@@ -1,26 +1,49 @@
name: ci-run name: ci-run
description: "跑一個 CI 工作:還原快取(ci-cache)→ 在 ci-env 容器裡執行指令。要在 checkout 之後使用,需要工具鏈時呼叫的工作流要有 env: GO_VERSION、NODE_VERSION" description: "跑一個 CI 工作:checkout → 還原快取(ci-cache,key 由 cache_files 的內容雜湊決定)→ 在 ci-env 容器裡執行指令。內部用的 ci-cache、ci-env 版本取自呼叫端的 Gitea 變數 ACTION_CI_CACHE_VERSION、ACTION_CI_ENV_VERSION。需要工具鏈時呼叫的工作流要有 env: GO_VERSION、NODE_VERSION"
inputs: inputs:
command: command:
description: "要在 ci-env 容器裡執行的 shell 指令" description: "要在 ci-env 容器裡執行的 shell 指令"
required: true required: true
cache_files:
description: "決定快取 key 的檔案(空白分隔,例如 go.sum web/package-lock.json);內容變了才換快取。不存在的檔案略過"
default: go.sum
cache_key: cache_key:
description: "快取 key,例如 ci-home-${{ hashFiles('go.sum', 'web/package-lock.json') }}" description: "直接指定快取 key(有值就不用 cache_files 算)"
required: true
cache_restore_keys:
description: "找不到完全相同的 key 時,依序嘗試的前綴(每行一個)"
default: "" default: ""
cache_prefix:
description: "快取 key 的前綴,找不到完全相同的 key 時也用它還原最近的快取"
default: ci-home-
checkout:
description: "true=先 checkout;false=呼叫端已經 checkout"
default: "true"
name: name:
description: "執行指令的步驟名稱" description: "執行指令的步驟名稱"
default: ci default: ci
runs: runs:
using: composite using: composite
steps: steps:
- uses: https://gitea.jsc.idv.tw/actions/ci-cache@v0.0.1 - name: checkout
if: ${{ inputs.checkout == 'true' }}
uses: actions/checkout@v4
- name: 算快取 key
id: key
shell: bash
env:
FILES: ${{ inputs.cache_files }}
KEY: ${{ inputs.cache_key }}
PREFIX: ${{ inputs.cache_prefix }}
run: |
if [ -z "$KEY" ]; then
# shellcheck disable=SC2086 # 依空白拆成檔案清單
KEY="$PREFIX$( (for f in $FILES; do [ ! -f "$f" ] || cat "$f"; done) | sha256sum | cut -c1-40)"
fi
echo "key=$KEY" >> "$GITHUB_OUTPUT"
echo "快取 key:$KEY"
- uses: https://gitea.jsc.idv.tw/actions/ci-cache@${{ vars.ACTION_CI_CACHE_VERSION }}
with: with:
key: ${{ inputs.cache_key }} key: ${{ steps.key.outputs.key }}
restore_keys: ${{ inputs.cache_restore_keys }} restore_keys: ${{ inputs.cache_prefix }}
- name: ${{ inputs.name }} - name: ${{ inputs.name }}
uses: https://gitea.jsc.idv.tw/actions/ci-env@v0.0.1 uses: https://gitea.jsc.idv.tw/actions/ci-env@${{ vars.ACTION_CI_ENV_VERSION }}
with: with:
command: ${{ inputs.command }} command: ${{ inputs.command }}
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 23 KiB