調整:ci/cd 一致化(action-ci 自動偵測、action-cd)、版本計算抽到 next-version
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
name: cd
|
name: cd
|
||||||
# 只在「任何分支 → main」的 PR 合併時發版:用 release-go 的 next-version 算下一版,沒有跳過就在 PR 來源分支的最新提交(pull_request.head.sha)上打標籤並推送。
|
# 只在「任何分支 → main」的 PR 合併時發版:action-cd 用 next-version 算下一版,沒有跳過就在 PR 來源分支的最新提交(pull_request.head.sha)上打標籤並推送。
|
||||||
# branches 寫死 main,來源分支不限;PR 沒合併就關閉時,tag 工作在工作層級跳過。直接推送 main 不發版。
|
# branches 寫死 main,來源分支不限;PR 沒合併就關閉時,tag 工作在工作層級跳過。直接推送 main 不發版。
|
||||||
# 版本只遞增 patch、每位最大 9,沒有標籤時從 v0.0.1 開始。只動文件、圖示、測試、.gitea/、go.mod 時不發版(這些不會進映像檔,也不影響使用者)。
|
# 版本只遞增 patch、每位最大 9,沒有標籤時從 v0.0.1 開始。只動文件、圖示、測試、.gitea/、go.mod 時不發版(這些不會進映像檔,也不影響使用者)。
|
||||||
# 呼叫端用標籤引用這個 action(版本取自 Gitea 變數),所以發版後要到呼叫端把 ACTION_<名稱>_VERSION 改成新標籤才會生效。
|
# 呼叫端用標籤引用這個 action(版本取自 Gitea 變數),所以發版後要到呼叫端把 ACTION_<名稱>_VERSION 改成新標籤才會生效。
|
||||||
@@ -17,29 +17,6 @@ jobs:
|
|||||||
if: ${{ github.event.pull_request.merged == true }}
|
if: ${{ github.event.pull_request.merged == true }}
|
||||||
runs-on: docker-ubuntu
|
runs-on: docker-ubuntu
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: https://gitea.jsc.idv.tw/actions/action-cd@${{ vars.ACTION_ACTION_CD_VERSION }}
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
|
||||||
token: ${{ secrets.TOKEN || github.token }}
|
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"
|
|
||||||
|
|||||||
@@ -10,7 +10,4 @@ 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: https://gitea.jsc.idv.tw/actions/action-ci@${{ vars.ACTION_ACTION_CI_VERSION }}
|
||||||
with:
|
|
||||||
go_test: true
|
|
||||||
|
|||||||
@@ -26,43 +26,9 @@
|
|||||||
|`gitea_url`||`${{ github.server_url }}`|Gitea 網址,預設是目前的 Gitea(github.server_url)|
|
|`gitea_url`||`${{ github.server_url }}`|Gitea 網址,預設是目前的 Gitea(github.server_url)|
|
||||||
|`gitea_repo`||`${{ github.repository }}`|Gitea 儲存庫 <擁有者>/<名稱>,預設是目前的儲存庫(github.repository)|
|
|`gitea_repo`||`${{ github.repository }}`|Gitea 儲存庫 <擁有者>/<名稱>,預設是目前的儲存庫(github.repository)|
|
||||||
|
|
||||||
## 開發
|
## 開發與發版
|
||||||
|
|
||||||
`ci.yaml` 用共用的 [action-ci](https://gitea.jsc.idv.tw/actions/action-ci) 跑 shellcheck、Go 黑箱測試。
|
- CI(`ci.yaml`):用 [action-ci](https://gitea.jsc.idv.tw/actions/action-ci) 跑 shellcheck、Go 黑箱測試。
|
||||||
|
- 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` 不發版。
|
||||||
圖示:`icon.svg`(Gitea 儲存庫頭像用 `icon.png`)。
|
- 呼叫端要把 Gitea 變數 `ACTION_DEPLOY_GO_VERSION` 改成新標籤才會採用。
|
||||||
|
- 圖示:`icon.svg`(儲存庫頭像用 `icon.png`)。
|
||||||
## 在沒有 git 的主機上使用
|
|
||||||
|
|
||||||
主機沒有 git 時不能 `uses`(取得 action 需要 git clone),改用 curl 抓腳本再執行:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
runs-on: <部署主機的 runner 標籤>
|
|
||||||
steps:
|
|
||||||
- env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.TOKEN || github.token }}
|
|
||||||
GO_VERSION: ${{ vars.GO_VERSION }}
|
|
||||||
DEPLOY_NAME: myapp
|
|
||||||
RAW_URL: ${{ github.server_url }}/api/v1/repos/actions/deploy-go/raw
|
|
||||||
REF: ${{ vars.ACTION_DEPLOY_GO_VERSION }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
dir=$(mktemp -d); trap 'rm -rf "$dir"' EXIT
|
|
||||||
for f in common.sh check-env.sh install-binary.sh activate.sh run.sh; do
|
|
||||||
curl -fsSL -H "Authorization: token $GITEA_TOKEN" -o "$dir/$f" "$RAW_URL/$f?ref=$REF"
|
|
||||||
done
|
|
||||||
bash "$dir/run.sh" "<版本>"
|
|
||||||
```
|
|
||||||
|
|
||||||
## 對應用程式的要求
|
|
||||||
|
|
||||||
- Go 模組路徑是「Gitea 主機/擁有者/名稱」,主程式在 `cmd/<名稱>`(可用 `DEPLOY_PACKAGE` 改)。
|
|
||||||
- `<執行檔> version` 輸出的第二個欄位是版本(不含 `v`),例如 `myapp 1.2.3 (commit abc1234)`。
|
|
||||||
- 服務不存在時用 `<執行檔> install-service --addr <位址> --data <資料目錄>` 安裝並啟動。
|
|
||||||
- 健康檢查(預設 `http://127.0.0.1:8080/api/health`,可用 `DEPLOY_HEALTH_URL` 改)回 JSON,`status` 是 `ok` 且 `version` 等於目標版本。
|
|
||||||
|
|
||||||
其他環境變數見 `common.sh` 開頭。
|
|
||||||
|
|
||||||
## 發版
|
|
||||||
|
|
||||||
只在「任何分支 → `main`」的 PR 合併時,`cd.yaml` 用 [release-go](https://gitea.jsc.idv.tw/actions/release-go) 算下一個版本,在 PR 來源分支的最新提交上打標籤(只遞增 patch,每位最大 9);只動文件、圖示、測試、`.gitea/`、`go.mod` 時不發版。直接推送 `main` 不發版。呼叫端要把 Gitea 變數 `ACTION_DEPLOY_GO_VERSION` 改成新標籤才會採用。
|
|
||||||
|
|||||||
Reference in New Issue
Block a user