diff --git a/README.md b/README.md index 653961f..64a03c8 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# deploy +# deploy-go 三個步驟:檢查環境 → `go install` 指定版本 → 安裝與啟動服務;健康檢查沒通過就換回上一版。composite action,要在目標主機的 runner 上執行。 ## 用法 -版本由呼叫端的 Gitea Actions 變數決定(例如 `vars.ACTION_DEPLOY_VERSION`),不要用分支名稱:runner 依 ref 重用舊映像檔,改了腳本不會生效,所以每次改動都發新標籤。 +版本由呼叫端的 Gitea Actions 變數決定(例如 `vars.ACTION_DEPLOY_GO_VERSION`),不要用分支名稱:runner 依 ref 重用舊映像檔,改了腳本不會生效,所以每次改動都發新標籤。 ```yaml -- uses: https://gitea.jsc.idv.tw/actions/deploy@${{ vars.ACTION_DEPLOY_VERSION }} +- uses: https://gitea.jsc.idv.tw/actions/deploy-go@${{ vars.ACTION_DEPLOY_GO_VERSION }} with: version: ... go_version: ... @@ -43,8 +43,8 @@ steps: GITEA_TOKEN: ${{ secrets.TOKEN || github.token }} GO_VERSION: ${{ vars.GO_VERSION }} DEPLOY_NAME: myapp - RAW_URL: ${{ github.server_url }}/api/v1/repos/actions/deploy/raw - REF: ${{ vars.ACTION_DEPLOY_VERSION }} + 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 diff --git a/action.yml b/action.yml index 225efe1..8224a2f 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: deploy +name: deploy-go description: "把 Go 應用程式的指定版本部署到這台主機(composite action,三個步驟:檢查環境 → go install 指定版本 → 安裝與啟動服務,失敗換回上一版)。要在目標主機的 runner 上執行,且主機要有 git 才能 uses;沒有 git 的主機改用 curl 抓本 repo 的 run.sh 再執行(見 README)。版本一定要明確傳入,不會拿 @latest" inputs: version: diff --git a/activate.sh b/activate.sh index a820186..c39c33d 100755 --- a/activate.sh +++ b/activate.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # 部署步驟 3:安裝與啟動服務。備份上一版 → 把 install-binary 放好的 <執行檔>.new 改名換上 → 重啟(服務不存在就 install-service)→ # 輪詢 GET /api/health,status 要是 ok 且 version 等於指定版本 → 失敗就換回上一版、重啟,並以非 0 結束。資料庫遷移只往前,不回滾。 -# .gitea/actions/deploy/activate.sh <版本,例如 v0.4.9> +# activate.sh <版本,例如 v0.4.9> set -euo pipefail . "$(dirname "$0")/common.sh" version=${1:?用法:activate.sh <版本,例如 v0.4.9>} diff --git a/check-env.sh b/check-env.sh index 474743c..ba22237 100755 --- a/check-env.sh +++ b/check-env.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # 部署步驟 1:檢查環境,工具與 Go 版本缺少或不足就安裝(curl、tar、systemctl、Go)。 -# .gitea/actions/deploy/check-env.sh +# check-env.sh # 需要 GO_VERSION;其他環境變數見 common.sh。 set -euo pipefail . "$(dirname "$0")/common.sh" diff --git a/go.mod b/go.mod index 2ea5b40..3095078 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module gitea.jsc.idv.tw/actions/deploy +module gitea.jsc.idv.tw/actions/deploy-go go 1.27.1 diff --git a/install-binary.sh b/install-binary.sh index 3513f37..f1d3f2c 100755 --- a/install-binary.sh +++ b/install-binary.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # 部署步驟 2:用 go install 裝指定的版本(確切版本,不用 @latest),驗證執行檔回報的版本相同,放到 <執行檔>.new 等待 activate。 -# .gitea/actions/deploy/install-binary.sh <版本,例如 v0.4.9 或 v0.5.0-dev.2> +# install-binary.sh <版本,例如 v0.4.9 或 v0.5.0-dev.2> # 不碰正在執行的執行檔與服務,失敗時什麼都沒改。 set -euo pipefail . "$(dirname "$0")/common.sh" diff --git a/run.sh b/run.sh index 40f7afb..c99e3b5 100755 --- a/run.sh +++ b/run.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # 依序執行部署的三個步驟:check-env → install-binary → activate。版本是必填的確切版本,不會去拿 @latest。 -# .gitea/actions/deploy/run.sh <版本,例如 v0.4.9 或 v0.5.0-dev.2> +# run.sh <版本,例如 v0.4.9 或 v0.5.0-dev.2> # 每個步驟都能單獨執行(見各檔案開頭),環境變數見 common.sh。CD 在沒有 git 的主機上用 curl 抓這個目錄的檔案再執行。 set -euo pipefail dir=$(cd "$(dirname "$0")" && pwd) diff --git a/test/deploy_host_test.go b/test/deploy_host_test.go index 9830f40..48ebc98 100644 --- a/test/deploy_host_test.go +++ b/test/deploy_host_test.go @@ -1,4 +1,4 @@ -// .gitea/actions/deploy/ 部署腳本的黑箱測試:假的 go、systemctl、sudo 與真的 HTTP 健康端點,檢查換版與回滾。 +// 部署腳本的黑箱測試:假的 go、systemctl、sudo 與真的 HTTP 健康端點,檢查換版與回滾。 package test import (