8 Commits
Author SHA1 Message Date
admin 81178aa5c1 Merge pull request '調整:ci 只在 PR 觸發(拿掉 push: main)' (#3) from chore/ci-pr-only into main
Reviewed-on: #3
2026-11-05 04:55:20 +00:00
bot c7878bb440 調整:ci 只在 PR 觸發(拿掉 push: main,和羽藏一致)
cd / tag (pull_request) Successful in 6s
ci / test (pull_request) Successful in 22s
2026-11-05 04:53:12 +00:00
admin 919817adec Merge pull request '調整:第三方 action 與工具的版本也從 Gitea 變數取得' (#2) from chore/third-party-versions into main
ci / test (push) Successful in 4s
Reviewed-on: #2
2026-11-05 04:51:09 +00:00
bot 2cac19095b 調整:第三方 action 與工具的版本也從 Gitea 變數取得
ci / test (pull_request) Successful in 4s
cd / tag (pull_request) Successful in 3s
2026-11-05 04:44:27 +00:00
admin 63ad33f2dc Merge pull request '調整:ci/cd 一致化,版本計算抽到 next-version' (#1) from chore/unify-ci-cd into main
ci / test (push) Successful in 3s
Reviewed-on: #1
2026-11-05 04:28:09 +00:00
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
4 changed files with 46 additions and 60 deletions
+7 -30
View File
@@ -1,12 +1,12 @@
name: cd
# main 的 ci 通過後:用 release-go 的 next-version 算下一版,沒有跳過就在剛通過 ci 的提交上打標籤並推送。
# 只在「任何分支 → 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 只看 main:ci 在 push main 時跑,成功才觸發;失敗或取消不發版。
# 沒有手動觸發:發版失敗時重跑這個 workflow 的 run。
on:
workflow_run:
workflows: [ci]
types: [completed]
pull_request:
types: [closed]
branches: [main]
# 排隊、不取消:連續推送依序發版,版本不重複
concurrency:
@@ -14,32 +14,9 @@ concurrency:
cancel-in-progress: false
jobs:
tag:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }}
if: ${{ github.event.pull_request.merged == true }}
runs-on: docker-ubuntu
steps:
- uses: actions/checkout@v4
- uses: https://gitea.jsc.idv.tw/actions/action-cd@${{ vars.ACTION_ACTION_CD_VERSION }}
with:
fetch-depth: 0
ref: ${{ github.event.workflow_run.head_sha }}
token: ${{ secrets.TOKEN || github.token }}
- id: ver
uses: https://gitea.jsc.idv.tw/actions/release-go@${{ vars.ACTION_RELEASE_GO_VERSION }}
with:
task: next-version
channel: release
go_registry: false
docs_pattern: '^\.gitea/|^icon\.|^test/|^go\.mod$|\.md$'
token: ${{ secrets.TOKEN || github.token }}
- name: 只動文件等檔案,不發版
if: ${{ steps.ver.outputs.skip == 'true' }}
run: echo "不發版"
- name: 打標籤並推送 ${{ steps.ver.outputs.version }}
if: ${{ steps.ver.outputs.skip != 'true' }}
env:
VERSION: ${{ steps.ver.outputs.version }}
TOKEN: ${{ secrets.TOKEN || github.token }}
run: |
set -euo pipefail
git tag "$VERSION" HEAD
git push "${GITHUB_SERVER_URL%%://*}://oauth2:${TOKEN}@${GITHUB_SERVER_URL#*://}/${GITHUB_REPOSITORY}.git" "refs/tags/$VERSION"
echo "已推送標籤 $VERSION"
+4 -5
View File
@@ -1,7 +1,5 @@
name: ci
on:
push:
branches: [main]
pull_request:
concurrency:
group: ci-${{ github.ref }}
@@ -10,6 +8,7 @@ jobs:
test:
runs-on: docker-ubuntu
steps:
- uses: actions/checkout@v4
- name: shellcheck(含 docker-check.sh)
uses: ./
- uses: actions/checkout@${{ vars.ACTION_CHECKOUT_VERSION }}
- uses: ./
with:
checkout: false
+17 -14
View File
@@ -1,32 +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@${{ vars.ACTION_ACTION_CI_VERSION }}
with:
go_test: true
docker_build: true
```
## 輸入
|名稱|預設|說明|
|---|---|---|
|`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,映像檔標籤是 `action-test:<sha>`(唯一,不會撞到 runner 上的舊映像檔)|
|`docker_run_args`||建置後實際執行容器的 entrypoint 參數(每行一個),空=不執行|
|`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`||容器輸出必須包含的字串,空=只檢查結束碼|
不要對 Docker action 用 `uses: ./` 自測:這台 runner 會依名稱重用舊映像檔,可能跑到別的專案的映像檔。內部用的 `shellcheck`、`ci-env` 版本取自呼叫端 repo 的 Gitea 變數 `ACTION_SHELLCHECK_VERSION`、`ACTION_CI_ENV_VERSION`(不寫死在 `action.yml`),所以呼叫端要先設好這兩個變數。
不要對 Docker action 用 `uses: ./` 自測:這台 runner 會依名稱重用舊映像檔,可能跑到別的專案的映像檔。
圖示:`icon.svg`(頭像用 `icon.png`)。
內部用的版本都取自呼叫端 repo 的 Gitea 變數(不寫死在 `action.yml`),所以呼叫端要先設好:`ACTION_CHECKOUT_VERSION`、`ACTION_SHELLCHECK_VERSION`、`ACTION_CI_ENV_VERSION`,以及 shellcheck 工具本身的 `TOOL_SHELLCHECK_VERSION`(例如 `v0.10.0`)。
## 發版
## 開發與發版
`main` 的 `ci` 通過後,`cd.yaml` 用 [release-go](https://gitea.jsc.idv.tw/actions/release-go) 算下一個版本並打標籤(只遞增 patch,每位最大 9);只動文件、圖示、測試、`.gitea/`、`go.mod` 時不發版。呼叫端要把 Gitea 變數 `ACTION_ACTION_CI_VERSION` 改成新標籤才會採用。
- 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`)。
+18 -11
View File
@@ -1,20 +1,17 @@
name: action-ci
description: "action repo 的共用 CI:shellcheck → Go 腳本測試(在 ci-env 容器裡,Go 版本取 go.mod)→ 建置映像檔。內部用的 shellcheck、ci-env 版本取自呼叫端的 Gitea 變數 ACTION_SHELLCHECK_VERSION、ACTION_CI_ENV_VERSION。要在 checkout 之後使用,各步驟用輸入開關"
description: "action repo 的共用 CI:checkout → shellcheck → Go 腳本測試(有 go.mod 與 test/ 才跑,在 ci-env 容器裡,Go 版本取 go.mod)→ 建置映像檔(有 Dockerfile 才跑,可選擇實際執行並檢查輸出)。自動偵測,各 repo 的 ci.yaml 不必設開關。版本都取自呼叫端的 Gitea 變數:ACTION_CHECKOUT_VERSION、ACTION_SHELLCHECK_VERSION、ACTION_CI_ENV_VERSION、TOOL_SHELLCHECK_VERSION(shellcheck 本身)"
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 建得起來(映像檔標籤唯一,不會撞到 runner 上的舊映像檔)"
default: "false"
docker_run_args:
description: "docker_build 之後實際執行容器的參數(entrypoint 的參數,每行一個);空=不執行"
description: "docker build 之後實際執行容器的參數(entrypoint 的參數,每行一個);空=只建置不執行"
default: ""
docker_run_options:
description: "執行容器的 docker create 選項(每行一個,例如 --env=INPUT_TASK=resolve-channel)"
@@ -25,19 +22,29 @@ inputs:
runs:
using: composite
steps:
- name: checkout
if: ${{ inputs.checkout == 'true' }}
uses: actions/checkout@${{ vars.ACTION_CHECKOUT_VERSION }}
- 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@${{ vars.ACTION_SHELLCHECK_VERSION }}
with:
files: ${{ inputs.shellcheck_files }}
version: ${{ vars.TOOL_SHELLCHECK_VERSION }}
- name: Go 測試
if: ${{ inputs.go_test == 'true' }}
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
env:
RUN_ARGS: ${{ inputs.docker_run_args }}