commit 87ec8ee1b8eff065ad9a47974e8bc17950a16d11 Author: bot Date: Thu Nov 5 04:12:39 2026 +0000 初始版本 diff --git a/.gitea/workflows/cd.yaml b/.gitea/workflows/cd.yaml new file mode 100644 index 0000000..56e42cd --- /dev/null +++ b/.gitea/workflows/cd.yaml @@ -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 }} diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml new file mode 100644 index 0000000..6950cda --- /dev/null +++ b/.gitea/workflows/ci.yaml @@ -0,0 +1,13 @@ +name: ci +on: + push: + branches: [main] + pull_request: +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true +jobs: + test: + runs-on: docker-ubuntu + steps: + - uses: https://gitea.jsc.idv.tw/actions/action-ci@${{ vars.ACTION_ACTION_CI_VERSION }} diff --git a/README.md b/README.md new file mode 100644 index 0000000..f80ee07 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# action-cd + +action repo 的共用 CD: + +1. checkout PR 來源分支的最新提交(`pull_request.head.sha`),完整歷史 +2. 用 [next-version](https://gitea.jsc.idv.tw/actions/next-version) 算下一個版本(只看 git 標籤) +3. 沒有跳過就在該提交上打標籤並推送;只動文件、圖示、測試、`.gitea/`、`go.mod` 時跳過 + +典型的 `cd.yaml`(觸發條件由呼叫端決定,這裡是「任何分支 → main」的 PR 合併時): + +```yaml +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 }} +``` + +## 輸入 + +|名稱|預設|說明| +|---|---|---| +|`token`||推送標籤用的權杖(需要 `write:repository`);空=用內建 `github.token`| +|`docs_pattern`|`^\.gitea/\|^icon\.\|^test/\|^go\.mod$\|\.md$`|只動這些檔案就不發版的 egrep 規則| + +## 輸出 + +|名稱|說明| +|---|---| +|`version`|這次發的版本(跳過時是下一版的預覽,沒有實際推送)| +|`skip`|`true`=只動文件等檔案,沒有發版| + +內部用的 `next-version` 版本取自呼叫端 repo 的 Gitea 變數 `ACTION_NEXT_VERSION_VERSION`,所以呼叫端要先設好。呼叫端用標籤引用 action(版本取自 Gitea 變數),發版後要把 `ACTION_<名稱>_VERSION` 改成新標籤才會採用。 + +## 開發與發版 + +- CI(`ci.yaml`):用 [action-ci](https://gitea.jsc.idv.tw/actions/action-ci)(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_CD_VERSION` 改成新標籤才會採用。 +- 圖示:`icon.svg`(儲存庫頭像用 `icon.png`)。 diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..b22392c --- /dev/null +++ b/action.yml @@ -0,0 +1,44 @@ +name: action-cd +description: "action repo 的共用 CD:checkout(PR 來源最新提交)→ next-version 算下一版 → 沒有跳過就打標籤並推送。只動文件、圖示、測試、.gitea/、go.mod 時跳過。內部用的 next-version 版本取自呼叫端的 Gitea 變數 ACTION_NEXT_VERSION_VERSION" +inputs: + token: + description: "推送標籤用的權杖(需要 write:repository);空=用內建 github.token" + default: "" + docs_pattern: + description: "只動這些檔案就不發版的 egrep 規則" + default: '^\.gitea/|^icon\.|^test/|^go\.mod$|\.md$' +outputs: + version: + description: "這次發的版本(跳過時是下一版的預覽,沒有實際推送)" + value: ${{ steps.ver.outputs.version }} + skip: + description: "true=只動文件等檔案,沒有發版" + value: ${{ steps.ver.outputs.skip }} +runs: + using: composite + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} + token: ${{ inputs.token || github.token }} + - id: ver + uses: https://gitea.jsc.idv.tw/actions/next-version@${{ vars.ACTION_NEXT_VERSION_VERSION }} + with: + channel: release + docs_pattern: ${{ inputs.docs_pattern }} + - name: 只動文件等檔案,不發版 + if: ${{ steps.ver.outputs.skip == 'true' }} + shell: bash + run: echo "不發版" + - name: 打標籤並推送 + if: ${{ steps.ver.outputs.skip != 'true' }} + shell: bash + env: + VERSION: ${{ steps.ver.outputs.version }} + TOKEN: ${{ inputs.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" diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..6627962 Binary files /dev/null and b/icon.png differ diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..29b5f76 --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file