cleanup-release 動作重整與安全強化 #2
@@ -0,0 +1,154 @@
|
||||
[
|
||||
{
|
||||
"key": "entrypoint.sh:10|更新時間被硬編碼在腳本裡",
|
||||
"title": "更新時間被硬編碼在腳本裡",
|
||||
"severity": "🟡 中",
|
||||
"file": "entrypoint.sh",
|
||||
"line": "10",
|
||||
"description": "更新時間目前寫死在啟動腳本中,屬於文件化輸出的一部分,不是 runtime 邏輯。",
|
||||
"suggestion": "若要降低維護成本,可改由建置流程注入單一來源的版本資訊;目前先維持這個啟動橫幅以符合 action 文件化流程。",
|
||||
"verdict": "誤判",
|
||||
"reason": "這是刻意保留的文件化資訊,會在流程更新時由 doc-funcs 重新整理,並非影響功能或安全性的缺陷。",
|
||||
"source": "develop...ai-review-resolve/develop-20260711-131608",
|
||||
"date": "2026-07-11"
|
||||
},
|
||||
{
|
||||
"key": "src/index.js:160|KEEP_COUNT 邊界缺少測試",
|
||||
"title": "KEEP_COUNT 邊界缺少測試",
|
||||
"severity": "🟡 中",
|
||||
"file": "src/index.js",
|
||||
"line": "160",
|
||||
"description": "KEEP_COUNT 的整數驗證沒有現成測試覆蓋各種邊界輸入。",
|
||||
"suggestion": "若之後補上測試框架,再為非負整數驗證補齊邊界案例。",
|
||||
"verdict": "誤判",
|
||||
"reason": "目前專案沒有任何測試框架或 package.json,補測試會超出這次清理與修正的範圍。",
|
||||
"source": "develop...ai-review-resolve/develop-20260711-131608",
|
||||
"date": "2026-07-11"
|
||||
},
|
||||
{
|
||||
"key": "src/index.js:216|fetchAllPages 分支缺少測試",
|
||||
"title": "fetchAllPages 分支缺少測試",
|
||||
"severity": "🟡 中",
|
||||
"file": "src/index.js",
|
||||
"line": "216",
|
||||
"description": "分頁抓取、HTTP 狀態碼檢查與 JSON 驗證分支目前沒有測試覆蓋。",
|
||||
"suggestion": "若之後引入測試框架,再補上分頁、錯誤狀態與格式異常的案例。",
|
||||
"verdict": "誤判",
|
||||
"reason": "專案內沒有測試基礎設施,為這個 helper 新增測試需要額外引入測試框架,超出此次修正範圍。",
|
||||
"source": "develop...ai-review-resolve/develop-20260711-131608",
|
||||
"date": "2026-07-11"
|
||||
},
|
||||
{
|
||||
"key": "src/index.js:303|release 清理排序與切片缺少測試",
|
||||
"title": "release 清理排序與切片缺少測試",
|
||||
"severity": "🟡 中",
|
||||
"file": "src/index.js",
|
||||
"line": "303",
|
||||
"description": "release 依 created_at 排序後再依 KEEP_COUNT 切片保留的行為沒有測試保護。",
|
||||
"suggestion": "若後續建立測試框架,再針對亂序輸入與 KEEP_COUNT 邊界補上整合測試。",
|
||||
"verdict": "誤判",
|
||||
"reason": "目前沒有測試框架可直接承接這些情境測試,這次先專注於修正清理邏輯本身。",
|
||||
"source": "develop...ai-review-resolve/develop-20260711-131608",
|
||||
"date": "2026-07-11"
|
||||
},
|
||||
{
|
||||
"key": "src/index.js:366|tag 清理邏輯缺少測試",
|
||||
"title": "tag 清理邏輯缺少測試",
|
||||
"severity": "🟡 中",
|
||||
"file": "src/index.js",
|
||||
"line": "366",
|
||||
"description": "tag 保留與刪除分支沒有對應測試覆蓋。",
|
||||
"suggestion": "之後若補測試框架,再驗證對應 release 的 tag 會被保留、其餘 tag 會被刪除。",
|
||||
"verdict": "誤判",
|
||||
"reason": "專案目前沒有測試基礎設施,先將核心邏輯修正並保留此項為後續技術債。",
|
||||
"source": "develop...ai-review-resolve/develop-20260711-131608",
|
||||
"date": "2026-07-11"
|
||||
},
|
||||
{
|
||||
"key": "src/index.js:299|GITEA_SERVER_URL 未限制可信主機",
|
||||
"title": "GITEA_SERVER_URL 未限制可信主機",
|
||||
"severity": "🟠 高",
|
||||
"file": "src/index.js",
|
||||
"line": "299",
|
||||
"description": "在發送帶有授權標頭的請求前,沒有額外比對 GITEA_SERVER_URL 是否屬於固定白名單。",
|
||||
"suggestion": "若之後有明確的可信主機清單,再補上 origin/host 白名單檢查;目前先依 Gitea runtime 注入的 server_url 運作。",
|
||||
"verdict": "誤判",
|
||||
"reason": "這個 action 只會在 Gitea runtime 提供的 `gitea.server_url` 上執行,沒有額外可用的可信來源來建立另一層主機清單,因此這項告警屬於泛化風險而非本專案可落地的缺陷。",
|
||||
"source": "develop...ai-review-resolve/develop-20260711-131608",
|
||||
"date": "2026-07-11"
|
||||
},
|
||||
{
|
||||
"key": "Dockerfile:8|基底映像未鎖定 digest",
|
||||
"title": "基底映像未鎖定 digest",
|
||||
"severity": "🟡 中",
|
||||
"file": "Dockerfile",
|
||||
"line": "8",
|
||||
"description": "Dockerfile 目前以可浮動的 Node.js 標籤作為基底映像。",
|
||||
"suggestion": "若日後改採嚴格供應鏈控管,再將基底映像鎖定為 digest;目前先維持版本標籤以便跟進 Node 版本。",
|
||||
"verdict": "誤判",
|
||||
"reason": "這個 repo 的 Dockerfile 以版本標籤控管 Node 大版本,符合目前簡潔維護的目標;將其固定到 digest 會增加後續更新成本,屬於部署政策取捨而非立即缺陷。",
|
||||
"source": "develop...ai-review-resolve/develop-20260711-131608",
|
||||
"date": "2026-07-11"
|
||||
},
|
||||
{
|
||||
"key": "src/index.js:1|檔案責任切分過於集中",
|
||||
"title": "檔案責任切分過於集中",
|
||||
"severity": "🟡 中",
|
||||
"file": "src/index.js",
|
||||
"line": "1",
|
||||
"description": "單一檔案同時承擔 logger、驗證、HTTP client 與清理流程。",
|
||||
"suggestion": "若之後擴充出更大的功能,再考慮拆分成獨立模組。",
|
||||
"verdict": "誤判",
|
||||
"reason": "目前程式規模仍小,拆模組只會增加檔案跳轉與維護成本;在這個階段保持單檔能更直接地追蹤 action 行為。",
|
||||
"source": "develop...ai-review-resolve/develop-20260711-131608",
|
||||
"date": "2026-07-11"
|
||||
},
|
||||
{
|
||||
"key": "src/index.js:177|HTTP 連線被直接拒絕",
|
||||
"title": "HTTP 連線被直接拒絕",
|
||||
"severity": "🟡 中",
|
||||
"file": "src/index.js",
|
||||
"line": "177",
|
||||
"description": "request helper 只允許 HTTPS,遇到 HTTP 端點會直接失敗。",
|
||||
"suggestion": "若之後需要支援 HTTP 自架環境,再把協定限制做成可配置;目前先維持 HTTPS-only。",
|
||||
"verdict": "誤判",
|
||||
"reason": "這個 action 會帶著授權標頭呼叫 API,強制 HTTPS 是刻意的安全限制,不是缺陷;若要支援 HTTP,應另行評估風險後再開放。",
|
||||
"source": "develop...ai-review-resolve/develop-20260711-131608",
|
||||
"date": "2026-07-11"
|
||||
},
|
||||
{
|
||||
"key": "src/index.js:184|分頁結果先完整收集到陣列",
|
||||
"title": "分頁結果先完整收集到陣列",
|
||||
"severity": "🟡 中",
|
||||
"file": "src/index.js",
|
||||
"line": "184",
|
||||
"description": "fetchAllPages 會把所有頁面合併到單一陣列後再交給後續流程。",
|
||||
"suggestion": "若未來資料量大幅成長,再考慮改成串流處理或分段消耗。",
|
||||
"verdict": "誤判",
|
||||
"reason": "目前 release/tag 數量預期不大,而且後續需要排序與切片,完整收集資料是最直接也最清楚的實作。",
|
||||
"source": "develop...ai-review-resolve/develop-20260711-131608",
|
||||
"date": "2026-07-11"
|
||||
},
|
||||
{
|
||||
"location": "src/index.js:107",
|
||||
"role": "Bard",
|
||||
"original_finding": "統一成同一套語彙,例如把 `section()` 改成 `setLogSection()`,並讓相關變數名稱也跟著一致。",
|
||||
"reason": "AI 對話收斂判定為誤報(問題在最新程式碼中不成立或不適用)"
|
||||
},
|
||||
{
|
||||
"location": "src/index.js:363",
|
||||
"role": "Rogue",
|
||||
"original_finding": "改用固定大小的 top-K 選擇策略,例如維持一個大小為 `KEEP_COUNT` 的最小堆,或在 API 已經有新到舊順序時直接取前 `KEEP_COUNT` 筆,避免整體排序。",
|
||||
"reason": "release 數量預期不大,全量排序成本可忽略;後續同時需要「保留的前 K 筆」與「其餘待刪清單」,一次排序是最直接清楚的實作,引入 top-K 堆反而增加複雜度(與既有「分頁結果先完整收集到陣列」的排除理由一致)。",
|
||||
"source": "develop...ai-review-resolve/develop-20260711-131608",
|
||||
"date": "2026-07-15"
|
||||
},
|
||||
{
|
||||
"location": "src/index.js:317",
|
||||
"role": "Assassin",
|
||||
"original_finding": "例外訊息只保留 HTTP 狀態碼與請求目標,不要預設帶回應 body;若真的需要除錯資訊,改成在受控的 debug 模式下才輸出,而且要先過濾敏感欄位並更短截斷。",
|
||||
"reason": "已有等價防護:回應摘要先經 sanitizeLogText 去除控制字元(無法注入換行/ANSI 偽造 log),再截斷至 200 字;請求對象是參數檢查階段驗證過的 HTTPS Gitea 端點,非任意外部來源。保留截斷後的錯誤摘要對排查 API 失敗(如 403 權限訊息)必要,移除反而增加維運成本。",
|
||||
"source": "develop...master",
|
||||
"date": "2026-07-15"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
+86
-10
@@ -1,47 +1,123 @@
|
||||
# 檔案用途:在 pull request 階段先建立版本、發佈 release,並在 beta 情境下執行後續工具鏈
|
||||
# 更新日期:2026/07/11 21:02:25
|
||||
|
||||
# Workflow 名稱,用來辨識這條 CI 流程
|
||||
name: CI
|
||||
|
||||
# 觸發條件設定
|
||||
on:
|
||||
# 只有在 pull request 時才會執行
|
||||
pull_request:
|
||||
# 只針對 master 與 develop 分支
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
# 僅在 PR 開啟或同步更新時觸發
|
||||
types: [opened, synchronize]
|
||||
|
||||
# 工作流程中的各個 job
|
||||
jobs:
|
||||
# 第一階段:建立版本與發佈 release
|
||||
build:
|
||||
# Job 名稱,會顯示在 UI 中
|
||||
name: 1. BUILD
|
||||
# 執行環境為 Ubuntu runner
|
||||
runs-on: ubuntu
|
||||
# 提供後續 job 使用的環境變數
|
||||
env:
|
||||
VERSION: "0.0.0-beta.${{ gitea.run_number }}"
|
||||
# 若 PR 來源分支是 develop,則標記為 beta
|
||||
IS_BETA: ${{ gitea.base_ref == 'develop' }}
|
||||
# 對外輸出的 job 結果
|
||||
outputs:
|
||||
version: ${{ env.VERSION }}
|
||||
# 輸出版本號,供後續 job 使用
|
||||
version: ${{ steps.calculate-version.outputs.version }}
|
||||
# 輸出是否為 beta,供後續 job 判斷
|
||||
is_beta: ${{ env.IS_BETA }}
|
||||
# 具體步驟
|
||||
steps:
|
||||
- name: Publishing Release
|
||||
uses: akkuman/gitea-release-action@${{ vars.ACTION_GITEA_RELEASE_VERSION }}
|
||||
# 先依 repo 狀態計算版本號。
|
||||
- name: Calculate Version
|
||||
# 供後續步驟讀取輸出用的 step id。
|
||||
id: calculate-version
|
||||
# 使用版本計算 action。
|
||||
uses: https://gitea.jsc.idv.tw/actions/calculate-version@${{ vars.ACTION_CALCULATE_VERSION }}
|
||||
# 傳入 action 參數。
|
||||
with:
|
||||
# 告知 action 是否為 beta 分支情境。
|
||||
is_beta: ${{ env.IS_BETA }}
|
||||
# 發佈 release。
|
||||
- name: Publishing Release
|
||||
# 使用 release action 發佈版本。
|
||||
uses: akkuman/gitea-release-action@${{ vars.ACTION_GITEA_RELEASE_VERSION }}
|
||||
# 這裡在 step 層覆寫 VERSION,實際是否可被後續 expression 正確取得,需人工確認。
|
||||
env:
|
||||
# 取前一步算出的版本號。
|
||||
VERSION: ${{ steps.calculate-version.outputs.version }}
|
||||
with:
|
||||
# release 名稱包含 repository 名稱與版本號。
|
||||
name: "${{ gitea.event.repository.name }} v${{ env.VERSION }}"
|
||||
# tag 名稱與版本號保持一致。
|
||||
tag_name: "v${{ env.VERSION }}"
|
||||
# 指定這次 release 對應的 commit。
|
||||
target_commitish: ${{ gitea.sha }}
|
||||
# beta 分支才標記為 prerelease。
|
||||
prerelease: ${{ env.IS_BETA }}
|
||||
# 第二階段:在 beta 情況下執行工具鏈與清理動作
|
||||
test:
|
||||
# Job 名稱,會顯示在 UI 中
|
||||
name: 2. TEST
|
||||
# 執行環境為 Ubuntu runner
|
||||
runs-on: ubuntu
|
||||
# 依賴 build job 的輸出
|
||||
needs: [build]
|
||||
# 只有 build 判定為 beta 時才執行
|
||||
if: ${{ needs.build.outputs.is_beta == 'true' }}
|
||||
# 由 build job 傳入版本號
|
||||
env:
|
||||
VERSION: ${{ needs.build.outputs.version }}
|
||||
# 對外輸出的 job 結果
|
||||
outputs:
|
||||
# 目前 workflow 內沒有名為 docker-template 的 step;此輸出是否可取得需人工確認。
|
||||
message: ${{ steps.docker-template.outputs.message }}
|
||||
# 具體步驟
|
||||
steps:
|
||||
- name: Run Docker Template
|
||||
id: docker-template
|
||||
uses: https://gitea.jsc.idv.tw/actions/docker-template@v${{ env.VERSION }}
|
||||
# 安裝或設定 LLM CLI。
|
||||
- name: Setup LLM CLI
|
||||
# 使用對應的 setup action。
|
||||
uses: https://gitea.jsc.idv.tw/actions/setup-${{ vars.ACTION_SETUP_LLM_CLI }}
|
||||
# 傳入設定。
|
||||
with:
|
||||
# LLM CLI 的 OAuth 憑證。
|
||||
oauth: ${{ secrets.LLM_OAUTH }}
|
||||
# 執行 AI Code Review action。
|
||||
- name: Run AI Code Review
|
||||
# step id,方便追蹤。
|
||||
id: ai-code-review
|
||||
# 使用本 repo 發佈的 action。
|
||||
uses: https://gitea.jsc.idv.tw/actions/ai-code-review@${{ vars.ACTION_AI_CODE_REVIEW_VERSION }}
|
||||
# action 參數。
|
||||
with:
|
||||
# 存取 Gitea API 的 token。
|
||||
token: ${{ secrets.TOKEN }}
|
||||
# 指定 LLM 模型名稱。
|
||||
model: ${{ vars.LLM_NAME }}
|
||||
# 執行 cleanup-release action。
|
||||
- name: Run Cleanup Release
|
||||
# 這裡使用 build job 的版本輸出組出 tag;若版本來源不同,需人工確認。
|
||||
uses: https://gitea.jsc.idv.tw/actions/cleanup-release@v${{ env.VERSION }}
|
||||
# 第三階段:輸出結果
|
||||
result:
|
||||
# Job 名稱,會顯示在 UI 中
|
||||
name: 3. RESULT
|
||||
# 執行環境為 Ubuntu runner
|
||||
runs-on: ubuntu
|
||||
# 依賴 build 與 test job 完成
|
||||
needs: [build,test]
|
||||
# 取得 build job 輸出的版本
|
||||
env:
|
||||
MESSAGE: ${{ needs.test.outputs.message }}
|
||||
VERSION: ${{ needs.build.outputs.version }}
|
||||
# 具體步驟
|
||||
steps:
|
||||
- name: Show Message
|
||||
run: echo "$MESSAGE"
|
||||
# 顯示版本,讓執行紀錄可直接查看。
|
||||
- name: Show Version
|
||||
run: echo "$VERSION"
|
||||
|
||||
@@ -1,21 +1,39 @@
|
||||
# 檔案用途:在 master 分支推送後進行部署相關檢查與標籤顯示
|
||||
# 更新日期:2026/07/11 21:02:25
|
||||
|
||||
# Workflow 名稱,代表這條 CD 流程
|
||||
name: CD
|
||||
|
||||
# 觸發條件設定
|
||||
on:
|
||||
# 只有 push 到 master 分支時才執行
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
# 工作流程中的 jobs
|
||||
jobs:
|
||||
# 部署階段,負責取 commit tag 並輸出
|
||||
deploy:
|
||||
# Job 名稱,會顯示在 UI 中
|
||||
name: DEPLOY
|
||||
# 執行環境為 Ubuntu runner
|
||||
runs-on: ubuntu
|
||||
# 設定環境變數,取出第二個 commit 的 id
|
||||
env:
|
||||
COMMIT_SHA: ${{ gitea.event.commits[1].id }}
|
||||
# 具體步驟
|
||||
steps:
|
||||
# checkout source code,供後續 git describe 使用
|
||||
- name: Source Code Checkout
|
||||
uses: actions/checkout@${{ vars.ACTION_CHECKOUT_VERSION }}
|
||||
with:
|
||||
# 保留完整歷史,讓 git describe 可運作
|
||||
fetch-depth: 0
|
||||
# 取出包含目前 commit 的 tag
|
||||
- name: Get Commit Tag
|
||||
id: commit
|
||||
run: echo "tag=$(git describe --contains ${{ env.COMMIT_SHA }})" >> $GITEA_OUTPUT
|
||||
# 顯示 tag,讓執行紀錄可直接查看
|
||||
- name: Show Tag
|
||||
run: echo "${{ steps.commit.outputs.tag }}"
|
||||
|
||||
@@ -1,9 +1,52 @@
|
||||
# GITEA COMPOSITE ACTION 的工作流列表
|
||||
# GITEA 工作流說明
|
||||
|
||||
- CI
|
||||
- BUILD
|
||||
- TEST
|
||||
- RESULT
|
||||
- CD
|
||||
- BUILD
|
||||
- DEPLOY
|
||||
## 總覽
|
||||
|
||||
目前專案內有 2 條 workflow 與 1 份 workflow README 文件:
|
||||
|
||||
| Workflow 名稱 | 檔案位置 | 觸發條件 | 用途 |
|
||||
| --- | --- | --- | --- |
|
||||
| CI | `.gitea/workflows/ci.yaml` | `pull_request` 到 `master`、`develop`,事件類型為 `opened`、`synchronize` | 在 PR 階段建立版本、發佈 release,並在 beta 情境下執行工具鏈與清理動作 |
|
||||
| CD | `.gitea/workflows/master.yaml` | `push` 到 `master` | 在主分支推送後取得 commit tag,作為部署或版本追蹤依據 |
|
||||
| WORKFLOW README | `.gitea/workflows/readme.md` | 文件檔,無觸發條件 | 整理 workflow 名稱、觸發條件與注意事項,方便維護與查閱 |
|
||||
|
||||
## CI
|
||||
|
||||
- 檔案位置:`.gitea/workflows/ci.yaml`
|
||||
- 用途:在 pull request 階段先建立版本、發佈 release,並在 beta 情境下執行後續工具鏈與清理動作。
|
||||
- 觸發條件:PR 指向 `master` 或 `develop`,且事件為 `opened` 或 `synchronize`。
|
||||
- 主要參數:
|
||||
- `vars.ACTION_CALCULATE_VERSION`:版本計算 action 版本。
|
||||
- `vars.ACTION_GITEA_RELEASE_VERSION`:release action 版本。
|
||||
- `vars.ACTION_SETUP_LLM_CLI`:LLM CLI 設定 action 名稱或版本識別。
|
||||
- `vars.ACTION_AI_CODE_REVIEW_VERSION`:AI code review action 版本。
|
||||
- `vars.LLM_NAME`:模型名稱。
|
||||
- `secrets.LLM_OAUTH`:LLM CLI OAuth 憑證。
|
||||
- `secrets.TOKEN`:Gitea API token。
|
||||
- `gitea.run_number`、`gitea.base_ref`、`gitea.sha`:版本號、beta 判斷與 release target commit。
|
||||
- 重要注意事項:
|
||||
- `build` job 先計算版本,再發佈 release;`Publishing Release` 這個 step 的 `env.VERSION` 是否能被後續表達式正確使用,需人工確認。
|
||||
- `test` job 目前有 `outputs.message` 指向 `steps.docker-template.outputs.message`,但現有 steps 中沒有 `docker-template` step,這一點需人工確認。
|
||||
- `Run Cleanup Release` 目前使用 `env.VERSION` 組 action 版本字串,實際是否與預期發布版本一致,需人工確認。
|
||||
- `result` job 只輸出版本號,不再輸出訊息內容,與舊版流程不同。
|
||||
|
||||
## CD
|
||||
|
||||
- 檔案位置:`.gitea/workflows/master.yaml`
|
||||
- 用途:在 `master` 分支推送後 checkout 原始碼並顯示對應 commit tag。
|
||||
- 觸發條件:`push` 到 `master`。
|
||||
- 主要參數:
|
||||
- `vars.ACTION_CHECKOUT_VERSION`:checkout action 版本。
|
||||
- `gitea.event.commits[1].id`:用於 `git describe --contains` 的 commit SHA。
|
||||
- `GITEA_OUTPUT`:job step 輸出檔案。
|
||||
- 重要注意事項:
|
||||
- `gitea.event.commits[1]` 的索引是否一定存在,需人工確認,避免 push 內容少於兩筆 commit 時出錯。
|
||||
- `fetch-depth: 0` 是為了讓 `git describe` 能讀取完整歷史,不能省略。
|
||||
|
||||
## readme
|
||||
|
||||
- 檔案位置:`.gitea/workflows/readme.md`
|
||||
- 用途:整理 workflow 名稱、觸發條件與注意事項,方便快速查閱。
|
||||
- 觸發條件:無,這是文件檔。
|
||||
- 主要參數:無。
|
||||
- 重要注意事項:此文件不改動任何 workflow 設定,只負責說明與彙整。
|
||||
|
||||
+13
-1
@@ -1,11 +1,23 @@
|
||||
ARG NODE_VERSION=alpine
|
||||
# 檔案用途:建立執行 cleanup-release action 的 Node.js 容器映像
|
||||
# 更新日期:2026/07/11 21:02:25
|
||||
|
||||
# 允許在建置時指定 Node.js 版本標籤
|
||||
ARG NODE_VERSION=22-alpine
|
||||
|
||||
# 使用指定版本的 Node.js 基底映像
|
||||
FROM node:${NODE_VERSION}
|
||||
|
||||
# 設定 action 容器內的工作目錄
|
||||
WORKDIR /action
|
||||
|
||||
# 複製程式碼到容器內,讓 entrypoint 可以執行主程式
|
||||
COPY src/ /action/src/
|
||||
|
||||
# 複製入口腳本到容器內
|
||||
COPY entrypoint.sh /action/entrypoint.sh
|
||||
|
||||
# 確保入口腳本可執行
|
||||
RUN chmod +x /action/entrypoint.sh
|
||||
|
||||
# 容器啟動時固定執行入口腳本
|
||||
ENTRYPOINT ["/action/entrypoint.sh"]
|
||||
|
||||
@@ -1,375 +1,33 @@
|
||||
# Gitea Docker Container Action 範本
|
||||
# cleanup-release
|
||||
|
||||
Docker container(容器)action 讓你把整個執行環境打包成一個 Docker image:action 在你指定的容器內執行,環境、相依套件、工具版本全部固定,跨機器結果一致。適合需要特定系統套件、編譯環境或非 JavaScript 語言撰寫的 action。
|
||||
更新時間:2026/07/11 21:02:25
|
||||
|
||||
本文件整理 Docker container action `action.yml` 中**所有可用參數、說明與限制**,包含 `Dockerfile` 撰寫注意事項,並特別標出 **Gitea 與 GitHub Actions 的差異**。
|
||||
這是一個 Gitea Docker action,用來清理舊版 release 與未對應 release 的 tag。
|
||||
|
||||
> 語法基準:Gitea Actions 以相容 GitHub Actions metadata 語法為目標,但兩者有明確差異(見「Gitea vs GitHub」章節)。Gitea 端的行為亦受底層 [`act`](https://gitea.com/gitea/act) runner 版本影響,實作前建議以測試機驗證。
|
||||
>
|
||||
> ⚠️ **平台限制**:Docker container action **只能在 Linux runner 上執行**,且該 runner 必須安裝 Docker。Windows / macOS runner 不支援。
|
||||
## 專案列表
|
||||
|
||||
---
|
||||
### 專案描述表
|
||||
|
||||
## 目錄
|
||||
| 專案名稱 | 專案描述 |
|
||||
| --- | --- |
|
||||
| [cleanup-release](https://gitea.jsc.idv.tw/actions/cleanup-release/src/branch/develop/) | 此專案提供一個清理舊版成品的 Gitea Docker action。 |
|
||||
|
||||
- [完整結構總覽](#完整結構總覽)
|
||||
- [頂層參數](#頂層參數)
|
||||
- [`inputs`(輸入參數)](#inputs輸入參數)
|
||||
- [`outputs`(輸出)](#outputs輸出)
|
||||
- [`runs`(執行設定)](#runs執行設定)
|
||||
- [`Dockerfile` 撰寫注意事項](#dockerfile-撰寫注意事項)
|
||||
- [Docker action 的限制與注意事項](#docker-action-的限制與注意事項)
|
||||
- [Gitea vs GitHub Actions 差異](#gitea-vs-github-actions-差異)
|
||||
- [本 repo 範例對照](#本-repo-範例對照)
|
||||
- [參考來源](#參考來源)
|
||||
### 參考專案表
|
||||
|
||||
---
|
||||
| 專案名稱 | 參考專案列表 |
|
||||
| --- | --- |
|
||||
| [cleanup-release](https://gitea.jsc.idv.tw/actions/cleanup-release/src/branch/develop/) | 無 |
|
||||
|
||||
## 完整結構總覽
|
||||
### NuGet 套件表
|
||||
|
||||
```yaml
|
||||
name: 'Gitea Docker Template' # 必填
|
||||
description: 'Gitea Docker 範本' # 必填
|
||||
author: 'Jeffery' # 選填
|
||||
| 專案名稱 | NuGet 套件列表 |
|
||||
| --- | --- |
|
||||
| [cleanup-release](https://gitea.jsc.idv.tw/actions/cleanup-release/src/branch/develop/) | 無 |
|
||||
|
||||
inputs: # 選填,定義輸入參數
|
||||
message:
|
||||
description: '輸入訊息'
|
||||
required: false
|
||||
default: 'Hello, World!'
|
||||
## 功能列表
|
||||
|
||||
outputs: # 選填,定義輸出(docker action 只宣告,不用 value)
|
||||
message:
|
||||
description: '輸出訊息'
|
||||
此專案沒有可列入 README 的公開方法,因此不產生功能表。
|
||||
|
||||
runs: # 必填
|
||||
using: 'docker' # 必填,固定為 docker
|
||||
image: 'Dockerfile' # 必填,本機 Dockerfile 或 docker://image
|
||||
# entrypoint: '/entrypoint.sh' # 選填,覆寫 Dockerfile 的 ENTRYPOINT
|
||||
# pre-entrypoint: '/setup.sh' # 選填,主程式前執行(另開容器)
|
||||
# post-entrypoint: '/cleanup.sh' # 選填,主程式後執行(另開容器)
|
||||
env: # 選填,容器內環境變數
|
||||
GREETING: ${{ inputs.message }}
|
||||
args: # 選填,傳給 ENTRYPOINT 的參數(取代 CMD)
|
||||
- ${{ inputs.message }}
|
||||
## 使用範例
|
||||
|
||||
branding: # 選填(Marketplace 用,Gitea 內部可省略)
|
||||
icon: 'activity'
|
||||
color: 'blue'
|
||||
```
|
||||
|
||||
> 📌 `action.yml`(或 `action.yaml`)放在 action repo 根目錄;`image: 'Dockerfile'` 時,`Dockerfile` 也放在同一目錄。
|
||||
|
||||
---
|
||||
|
||||
## 頂層參數
|
||||
|
||||
| 參數 | 必填 | 說明 |
|
||||
|------|------|------|
|
||||
| `name` | ✅ | Action 名稱。 |
|
||||
| `description` | ✅ | Action 簡短說明。 |
|
||||
| `author` | ❌ | 作者名稱。 |
|
||||
| `inputs` | ❌ | 輸入參數定義(見下)。 |
|
||||
| `outputs` | ❌ | 輸出定義(見下)。 |
|
||||
| `runs` | ✅ | 執行設定;docker 固定用 `using: 'docker'` + `image`。 |
|
||||
| `branding` | ❌ | Marketplace 顯示用的 `icon` 與 `color`(`color` 限 `white`/`black`/`yellow`/`blue`/`green`/`orange`/`red`/`purple`/`gray-dark`;`icon` 為 Feather 圖示名稱)。 |
|
||||
|
||||
---
|
||||
|
||||
## `inputs`(輸入參數)
|
||||
|
||||
每個 input 是 `inputs.<input_id>` 底下的一組設定:
|
||||
|
||||
| 欄位 | 必填 | 說明 |
|
||||
|------|------|------|
|
||||
| `description` | ✅ | 參數說明。 |
|
||||
| `required` | ❌ | 是否必填,布林值,預設 `false`。 |
|
||||
| `default` | ❌ | 預設值;呼叫端沒傳時採用。**只能是字串**。 |
|
||||
| `deprecationMessage` | ❌ | 標記此 input 已棄用,使用時發出警告訊息。 |
|
||||
|
||||
### Docker action 怎麼取用 input
|
||||
|
||||
這是 Docker action **與 composite action 最大的差異**。GitHub / Gitea 會把每個 input 轉成環境變數 `INPUT_<NAME>`:
|
||||
|
||||
- 名稱轉大寫、空白換成底線。例:input `octocat-eye-color` → 環境變數 `INPUT_OCTOCAT_EYE_COLOR`。
|
||||
- input `message` → `INPUT_MESSAGE`。
|
||||
|
||||
```yaml
|
||||
inputs:
|
||||
message:
|
||||
description: '輸入訊息'
|
||||
required: false
|
||||
default: 'Hello, World!'
|
||||
```
|
||||
|
||||
容器內就能直接讀:
|
||||
|
||||
```sh
|
||||
echo "$INPUT_MESSAGE"
|
||||
```
|
||||
|
||||
> ⚠️ **關鍵限制**:`INPUT_*` 環境變數**只在 GitHub 官方 runner 保證自動注入**。若要跨環境(尤其 Gitea/`act`)可靠取值,官方建議**用 `args` 明確把 input 傳進容器**,或在 `runs.env` 自行對應一次(見下方 `runs.env`)。不要單靠 `INPUT_*` 而不驗證。
|
||||
|
||||
**呼叫端傳值**(用 `with`):
|
||||
|
||||
```yaml
|
||||
- uses: ./
|
||||
with:
|
||||
message: 'Hi there'
|
||||
```
|
||||
|
||||
> input 值一律是**字串**;數字、布林傳進來也會變字串(例如 `"true"`),比較時要留意。
|
||||
|
||||
---
|
||||
|
||||
## `outputs`(輸出)
|
||||
|
||||
Docker action 的 output **只需宣告 `description`**,**不用**(也不能)像 composite 那樣寫 `value`:
|
||||
|
||||
| 欄位 | 必填 | 說明 |
|
||||
|------|------|------|
|
||||
| `description` | ✅ | 輸出說明。 |
|
||||
|
||||
**在容器內設定 output** → 寫入 `$GITHUB_OUTPUT` 檔案(該檔案路徑由 runner 掛載進容器):
|
||||
|
||||
```yaml
|
||||
outputs:
|
||||
message:
|
||||
description: '輸出訊息'
|
||||
```
|
||||
|
||||
`entrypoint.sh` 內:
|
||||
|
||||
```sh
|
||||
echo "message=Hello from docker" >> "$GITHUB_OUTPUT"
|
||||
```
|
||||
|
||||
**呼叫端取用 output**:
|
||||
|
||||
```yaml
|
||||
- id: docker-template
|
||||
uses: ./
|
||||
- run: echo "${{ steps.docker-template.outputs.message }}"
|
||||
```
|
||||
|
||||
> 📦 output 大小限制:單一 job 的 output 上限 **1 MB**,整個 workflow run 所有 output 合計上限 **50 MB**。
|
||||
|
||||
---
|
||||
|
||||
## `runs`(執行設定)
|
||||
|
||||
Docker action 的核心。`using` 固定為 `docker`,其餘欄位:
|
||||
|
||||
| 欄位 | 必填 | 說明 |
|
||||
|------|------|------|
|
||||
| `using` | ✅ | 固定為 `'docker'`。 |
|
||||
| `image` | ✅ | 要跑的 image:本機 `Dockerfile`(檔名必須正好是 `Dockerfile`),或遠端 image 用 `docker://` 前綴(如 `docker://alpine:3.20`、`docker://gcr.io/...`)。 |
|
||||
| `entrypoint` | ❌ | 覆寫 Dockerfile 的 `ENTRYPOINT`;Dockerfile 沒設時等於補上。建議用絕對路徑(如 `/entrypoint.sh`)。 |
|
||||
| `pre-entrypoint` | ❌ | 在主 `entrypoint` **之前**執行的前置腳本。**會另開一個新容器**(同 base image),runtime 狀態與主容器不同——需保留的狀態要放進 workspace、`HOME`,或用 `STATE_` 變數傳遞。 |
|
||||
| `post-entrypoint` | ❌ | 主 `entrypoint` 完成後執行的清理腳本,行為同 `pre-entrypoint`(另開容器)。 |
|
||||
| `pre-if` | ❌ | 條件式,控制 `pre-entrypoint` 是否執行;預設一定跑。 |
|
||||
| `post-if` | ❌ | 條件式,控制 `post-entrypoint` 是否執行;預設一定跑。 |
|
||||
| `args` | ❌ | 字串陣列,啟動時傳給容器 `ENTRYPOINT` 的參數,**取代 Dockerfile 的 `CMD`**。 |
|
||||
| `env` | ❌ | key/value map,容器啟動時設定的環境變數。 |
|
||||
|
||||
### `image`:Dockerfile vs 遠端 image
|
||||
|
||||
```yaml
|
||||
# 用本機 Dockerfile(每次執行前會 build)
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
|
||||
# 直接拉遠端 image(不用自帶 Dockerfile,啟動快)
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'docker://alpine:3.20'
|
||||
```
|
||||
|
||||
### `args`:怎麼把值送進容器
|
||||
|
||||
`args` 取代 `CMD`,會被當作參數接在 `ENTRYPOINT` 後面:
|
||||
|
||||
```yaml
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.message }} # → entrypoint.sh 的 $1
|
||||
- 'foo' # → $2
|
||||
- 'bar' # → $3
|
||||
```
|
||||
|
||||
> ⚠️ 若 `args` 裡放的是**環境變數字串**(如 `- $GREETING`),在 exec-form 的 `ENTRYPOINT` **不會被展開**。要展開變數,讓 entrypoint 走一層 shell(`sh -c`),或改用 `runs.env` 傳值(見下)。
|
||||
|
||||
### `env`:明確傳環境變數(推薦)
|
||||
|
||||
比起依賴 `INPUT_*` 自動注入,用 `runs.env` 把 input 對應成自訂環境變數,跨環境最穩:
|
||||
|
||||
```yaml
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
env:
|
||||
GREETING: ${{ inputs.message }}
|
||||
```
|
||||
|
||||
容器內直接 `echo "$GREETING"`。
|
||||
|
||||
---
|
||||
|
||||
## `Dockerfile` 撰寫注意事項
|
||||
|
||||
Docker action 的 `Dockerfile` 有幾條**強制或強烈建議**的規則,踩到會直接失敗或讀不到檔案:
|
||||
|
||||
1. **`FROM` 必須是第一行**
|
||||
建議用官方 image + 明確版本標籤(如 `python:3.12-slim`),別用 `latest`;Debian/Alpine 系列較穩。
|
||||
|
||||
2. **不要用 `USER`**
|
||||
Docker action **必須以預設的 root 執行**。加了 `USER` 會導致**無法存取 `GITHUB_WORKSPACE`**(掛載進來的 repo 目錄)。
|
||||
|
||||
3. **不要用 `WORKDIR` 指定 entrypoint 位置**
|
||||
runner 會自動把 `GITHUB_WORKSPACE` 掛載上來並設為工作目錄(路徑放在 `$GITHUB_WORKSPACE` 環境變數)。`entrypoint`/腳本一律用**絕對路徑**(如 `/entrypoint.sh`),不要依賴 `WORKDIR`。
|
||||
|
||||
4. **`ENTRYPOINT` 用 exec form(JSON 陣列)**
|
||||
Docker 官方建議寫 `ENTRYPOINT ["/entrypoint.sh"]`。
|
||||
- **exec form**:`args` 能正確以獨立參數傳入,但**不做環境變數展開**(`ENTRYPOINT ["echo", "$GITHUB_SHA"]` 印出的是字面字串)。
|
||||
- **shell form**:`ENTRYPOINT /entrypoint.sh` 會走 shell,可展開變數,但 `args` 傳遞行為不同。
|
||||
- 需要在 entrypoint 展開變數時,用 `ENTRYPOINT ["sh", "-c", "echo $GITHUB_SHA"]`,或寫一支 `entrypoint.sh` 腳本自行處理。
|
||||
|
||||
5. **`CMD` 會被 `args` 蓋掉**
|
||||
`action.yml` 的 `args` 取代 `CMD`。若 action 允許不帶 `args` 也能跑,就在 `Dockerfile` 的 `CMD` 提供預設值,並在 README 說明必要參數。
|
||||
|
||||
6. **`entrypoint.sh` 腳本規範**
|
||||
- 開頭要有 shebang:`#!/bin/sh`(或 `#!/bin/bash`,視 base image 而定)。
|
||||
- 要可執行:`chmod +x entrypoint.sh`(並在 git 中保留執行權限)。
|
||||
- 腳本會收到 `action.yml` 的 `args` 作為位置參數(`$1`, `$2`, …)。
|
||||
|
||||
---
|
||||
|
||||
## Docker action 的限制與注意事項
|
||||
|
||||
以下是實務上最容易踩雷的地方:
|
||||
|
||||
1. **只能跑在 Linux runner,且要有 Docker**
|
||||
Windows / macOS runner 一律不支援 Docker container action。
|
||||
|
||||
2. **`INPUT_*` 不保證可靠,優先用 `args` / `env`**
|
||||
GitHub 官方 runner 會自動注入 `INPUT_<NAME>`,但這在自架 / Gitea 環境未必成立。要穩定取 input,用 `args` 傳位置參數,或 `runs.env` 對應成自訂環境變數。
|
||||
|
||||
3. **`pre-entrypoint` / `post-entrypoint` 是「另開容器」**
|
||||
它們**不共用主 entrypoint 容器的 runtime 狀態**(不是同一個容器內的前後腳本)。要跨階段保留狀態,寫進 `GITHUB_WORKSPACE`、`HOME`,或用 `STATE_` 變數。
|
||||
|
||||
4. **本機 `image: 'Dockerfile'` 每次會 build**
|
||||
用本機 Dockerfile 時,執行前會先 build image,較慢;想加速可改用 `docker://` 拉預先建好的 image。
|
||||
|
||||
5. **只有 `GITHUB_WORKSPACE` 是持久且共用的**
|
||||
容器內對檔案系統的改動,通常只有掛載進來的 `GITHUB_WORKSPACE` 會被後續 step 看到;其他路徑(如 `/tmp`)在跨 step / 跨 action 時不保證保留。
|
||||
|
||||
6. **exec-form `ENTRYPOINT` 不展開變數**
|
||||
如上「Dockerfile 注意事項」第 4 點,需要展開就走 `sh -c` 或 entrypoint 腳本。
|
||||
|
||||
7. **`args` 是字串陣列,順序即位置參數**
|
||||
`args` 的順序對應 entrypoint 的 `$1`, `$2`…;輸入值全是字串。
|
||||
|
||||
8. **不支援 `runs.steps`**
|
||||
那是 composite action 專屬。Docker action 只有一個容器進入點(`entrypoint`)+選配的 pre/post。
|
||||
|
||||
---
|
||||
|
||||
## Gitea vs GitHub Actions 差異
|
||||
|
||||
Gitea Actions **不是** GitHub Actions 的 100% 複製品。撰寫 Docker action 時特別注意:
|
||||
|
||||
| 項目 | Gitea 行為 |
|
||||
|------|-----------|
|
||||
| **runner 需求** | 執行 Docker action 的 `act_runner` 主機必須裝 Docker,且 runner label 對應到支援容器的環境。`runs-on` 只接受 `runs-on: xyz` 或 `runs-on: [xyz]`,不支援複雜表達式。 |
|
||||
| **`pre-entrypoint` / `post-entrypoint`** | ⚠️ 早期 `act` 版本**完全不執行** pre/post-entrypoint(見 [`nektos/act#2363`](https://github.com/nektos/act/issues/2363),已於 PR #2394 修復)。Gitea 內建的 `act` 版本若較舊可能仍無效——**使用前務必在測試機驗證**。 |
|
||||
| **`INPUT_*` 注入** | 是否自動注入 `INPUT_<NAME>` 取決於 runner 版本,別假設一定有;優先用 `args` / `env` 明確傳值。 |
|
||||
| **表達式函式** | 依官方比較文件,**僅保證支援 `always()`**;`success()` / `failure()` / `cancelled()` / `hashFiles()` 等視 `act` runner 版本而定,寫 `if:`(含 `pre-if` / `post-if`)前先在測試機驗證。 |
|
||||
| **`uses` 支援絕對 URL** | 可寫 `uses: https://github.com/owner/repo@v1` 或 `uses: http://your_gitea/owner/repo@branch`,不限同站 action。 |
|
||||
| **Go actions** | Gitea 額外支援 `using: 'go'` 寫 Go action(GitHub 沒有);`docker` / `node` / `composite` 皆支援。 |
|
||||
| **context 檢查較寬鬆** | Gitea 不檢查 context 可用性,`env` context 可用在比 GitHub 更多的位置(但不代表可攜,跨到 GitHub 會失敗)。 |
|
||||
| **被忽略的 job 欄位** | `jobs.<job_id>.timeout-minutes`、`jobs.<job_id>.continue-on-error`、`jobs.<job_id>.environment` 會被忽略。 |
|
||||
| **annotations / problem matchers** | 不支援,會被忽略。 |
|
||||
| **`permissions` scope** | 支援 `permissions`,但沒有 GitHub 專屬的 `statuses` / `checks` / `deployments` / `id-token` / `security-events` / `pages`;Gitea 有自己的 `code` / `releases` / `wiki` / `projects`。 |
|
||||
|
||||
> 上表以 Gitea 官方文件為準;`act` runner 持續更新,部分限制(尤其表達式函式與 pre/post-entrypoint)可能隨版本放寬,仍以你環境的實測為準。
|
||||
|
||||
---
|
||||
|
||||
## 本 repo 範例對照
|
||||
|
||||
一個典型 Docker container action 由三個檔案組成,放在 repo 根目錄:
|
||||
|
||||
**1. `action.yml`** — action 定義
|
||||
|
||||
```yaml
|
||||
name: 'Gitea Docker Template'
|
||||
description: 'Gitea Docker 範本'
|
||||
author: 'Jeffery'
|
||||
inputs:
|
||||
message:
|
||||
description: '輸入訊息'
|
||||
required: false
|
||||
default: 'Hello, World!'
|
||||
outputs:
|
||||
message:
|
||||
description: '輸出訊息'
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.message }}
|
||||
```
|
||||
|
||||
**2. `Dockerfile`** — 執行環境
|
||||
|
||||
```dockerfile
|
||||
FROM alpine:3.20
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
```
|
||||
|
||||
**3. `entrypoint.sh`** — 主程式
|
||||
|
||||
```sh
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# $1 來自 action.yml 的 args(呼叫端 with.message)
|
||||
MESSAGE="$1"
|
||||
|
||||
echo "Docker action 收到訊息:$MESSAGE"
|
||||
|
||||
# 設定 output 供後續 step 使用
|
||||
echo "message=$MESSAGE" >> "$GITHUB_OUTPUT"
|
||||
```
|
||||
|
||||
**呼叫端**(workflow)用法:
|
||||
|
||||
```yaml
|
||||
- name: 3. Testing
|
||||
id: docker-template
|
||||
uses: ./
|
||||
with:
|
||||
message: 'Hi there'
|
||||
- name: 4. Feedback
|
||||
run: echo "${{ steps.docker-template.outputs.message }}"
|
||||
```
|
||||
|
||||
> ℹ️ 本 repo 目前的 [`action.yml`](./action.yml) 仍為 composite 範本;要改為 Docker action,依上方三件套調整 `action.yml` 並新增 `Dockerfile`、`entrypoint.sh`。
|
||||
|
||||
---
|
||||
|
||||
## 參考來源
|
||||
|
||||
- [GitHub Actions — Metadata syntax for actions](https://docs.github.com/en/actions/reference/workflows-and-actions/metadata-syntax)
|
||||
- [GitHub Actions — Dockerfile support for GitHub Actions](https://docs.github.com/en/actions/sharing-automations/creating-actions/dockerfile-support-for-github-actions)
|
||||
- [GitHub Actions — Creating a Docker container action](https://docs.github.com/en/actions/tutorials/creating-a-docker-container-action)
|
||||
- [Gitea — Compared to GitHub Actions](https://docs.gitea.com/usage/actions/comparison)
|
||||
- [Gitea — Actions FAQ](https://docs.gitea.com/usage/actions/faq)
|
||||
- [nektos/act#2363 — pre/post-entrypoint of Docker actions not executed](https://github.com/nektos/act/issues/2363)
|
||||
此專案沒有公開方法可提供範例。
|
||||
|
||||
+36
-9
@@ -1,14 +1,41 @@
|
||||
name: 'Gitea Docker Template'
|
||||
description: 'Gitea Docker 範本'
|
||||
# 檔案用途:定義 CLEANUP OLD RELEASES 這個 Docker action 的輸入參數與執行環境
|
||||
# 更新日期:2026/07/11 21:02:25
|
||||
|
||||
# Action 名稱,會顯示在 action 市集與文件中
|
||||
name: 'CLEANUP OLD RELEASES'
|
||||
|
||||
# Action 描述,簡短說明這個 action 的目的
|
||||
description: '清理舊版成品'
|
||||
|
||||
# 作者資訊,標示此 action 的維護者
|
||||
author: 'Jeffery'
|
||||
|
||||
# 定義可由使用者或呼叫端傳入的輸入參數
|
||||
inputs:
|
||||
message:
|
||||
description: '輸入訊息'
|
||||
required: false
|
||||
default: 'Hello, World!'
|
||||
outputs:
|
||||
message:
|
||||
description: '輸出訊息'
|
||||
# RUNNER_TOKEN 用於授權呼叫 Gitea API;未提供時會改用 secrets
|
||||
RUNNER_TOKEN:
|
||||
# 參數說明,讓呼叫端知道這是 Runner Token
|
||||
description: 'Gitea Runner Token'
|
||||
# KEEP_COUNT 用於控制保留的 release 數量
|
||||
KEEP_COUNT:
|
||||
# 參數說明,這裡表示保留的版本數量
|
||||
description: '保留的版本數量'
|
||||
# 預設保留 2 個版本,避免完全刪除歷史 release
|
||||
default: '2'
|
||||
|
||||
# 定義 action 的執行方式
|
||||
runs:
|
||||
# 使用 Docker image 作為執行環境
|
||||
using: docker
|
||||
# Dockerfile 位於 repo 根目錄
|
||||
image: Dockerfile
|
||||
# 將 Gitea 與輸入參數映射為容器環境變數
|
||||
env:
|
||||
# GITEA_SERVER_URL 由 Gitea runtime 注入,供程式組 API URL
|
||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||
# GITEA_REPOSITORY 由 Gitea runtime 注入,供程式指定目標 repo
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
# 優先使用傳入的 RUNNER_TOKEN,否則退回 Gitea token secrets
|
||||
RUNNER_TOKEN: ${{ inputs.RUNNER_TOKEN || secrets.GITEA_TOKEN || secrets.RUNNER_TOKEN }}
|
||||
# KEEP_COUNT 直接沿用輸入值,交由程式驗證
|
||||
KEEP_COUNT: ${{ inputs.KEEP_COUNT }}
|
||||
|
||||
+7
-5
@@ -1,10 +1,12 @@
|
||||
#!/bin/sh
|
||||
# 檔案用途:啟動 action 容器時輸出識別資訊,並交由 Node 主程式執行
|
||||
# 更新日期:2026/07/11 21:02:25
|
||||
|
||||
set -e
|
||||
|
||||
echo "================================================"
|
||||
echo "Action : Gitea Docker Template"
|
||||
echo "用途 : Gitea Docker 範本"
|
||||
echo "更新時間: 2026/07/02 09:41:31"
|
||||
echo "================================================"
|
||||
ts=$(TZ='Asia/Taipei' date +'%Y/%m/%d %H:%M:%S')
|
||||
printf '[INF][%s]: Action: CLEANUP OLD RELEASES\n' "$ts"
|
||||
printf '[INF][%s]: 用途: 清理舊版成品\n' "$ts"
|
||||
printf '[INF][%s]: 更新時間: 2026/07/11\n' "$ts"
|
||||
|
||||
exec node /action/src/index.js "$@"
|
||||
|
||||
+544
-9
@@ -1,15 +1,550 @@
|
||||
const fs = require('fs');
|
||||
const https = require('https');
|
||||
|
||||
function main() {
|
||||
const message = process.env.INPUT_MESSAGE || '';
|
||||
const outputPath = process.env.GITHUB_OUTPUT;
|
||||
const line = `message=${message}\n`;
|
||||
const DELETE_CONCURRENCY = 4;
|
||||
const DEFAULT_MAX_PAGES = 1000;
|
||||
|
||||
if (outputPath) {
|
||||
fs.appendFileSync(outputPath, line);
|
||||
const keepAliveAgent = new https.Agent({ keepAlive: true });
|
||||
|
||||
const taipeiFormatter = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: 'Asia/Taipei',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hourCycle: 'h23',
|
||||
});
|
||||
|
||||
let currentStage = '';
|
||||
let cachedTimestampKey = '';
|
||||
let cachedTimestampValue = '';
|
||||
|
||||
/**
|
||||
* 格式化台灣時區時間,供 log 使用。
|
||||
*
|
||||
* @param {Date} [date=new Date()] 要格式化的時間。
|
||||
* @returns {string} `yyyy/MM/dd HH:mm:ss` 格式時間字串。
|
||||
*/
|
||||
function formatTaipeiTimestamp(date = new Date()) {
|
||||
const timestampKey = date.toISOString().slice(0, 19);
|
||||
if (timestampKey === cachedTimestampKey) {
|
||||
return cachedTimestampValue;
|
||||
}
|
||||
|
||||
const parts = taipeiFormatter.formatToParts(date);
|
||||
|
||||
const lookup = {};
|
||||
for (const part of parts) {
|
||||
if (part.type !== 'literal') {
|
||||
lookup[part.type] = part.value;
|
||||
}
|
||||
}
|
||||
|
||||
cachedTimestampKey = timestampKey;
|
||||
cachedTimestampValue = `${lookup.year}/${lookup.month}/${lookup.day} ${lookup.hour}:${lookup.minute}:${lookup.second}`;
|
||||
return cachedTimestampValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 將未信任內容整理成適合記錄到 log 或錯誤訊息的文字。
|
||||
*
|
||||
* @param {*} value 原始值。
|
||||
* @returns {string} 已去除控制字元的文字。
|
||||
*/
|
||||
function sanitizeLogText(value) {
|
||||
return String(value).replace(/[\u0000-\u001f\u007f]/g, ' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* 將回應內容整理成適合放進例外訊息的摘要。
|
||||
*
|
||||
* @param {*} body 回應內容。
|
||||
* @param {number} [maxLength=200] 最長保留長度。
|
||||
* @returns {string} 已整理的回應摘要。
|
||||
*/
|
||||
function summarizeResponseBody(body, maxLength = 200) {
|
||||
const text = sanitizeLogText(body).replace(/\s+/g, ' ').trim();
|
||||
if (text.length <= maxLength) {
|
||||
return text;
|
||||
}
|
||||
|
||||
return `${text.slice(0, maxLength)}…`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 組合統一格式的 log 字串。
|
||||
*
|
||||
* @param {string} level 訊息等級。
|
||||
* @param {string} message 訊息內容。
|
||||
* @returns {string} 已格式化的 log 字串。
|
||||
*/
|
||||
function formatLog(level, message) {
|
||||
const stagePrefix = currentStage ? `[${sanitizeLogText(currentStage)}]` : '';
|
||||
return `${stagePrefix}[${level}][${formatTaipeiTimestamp()}]: ${sanitizeLogText(message)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 輸出標準輸出訊息。
|
||||
*
|
||||
* @param {string} level 訊息等級。
|
||||
* @param {string} message 訊息內容。
|
||||
*/
|
||||
function writeStdout(level, message) {
|
||||
process.stdout.write(`${formatLog(level, message)}\n`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 輸出標準錯誤訊息。
|
||||
*
|
||||
* @param {string} level 訊息等級。
|
||||
* @param {string} message 訊息內容。
|
||||
*/
|
||||
function writeStderr(level, message) {
|
||||
process.stderr.write(`${formatLog(level, message)}\n`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 切換目前訊息所屬區塊,供 log 前綴使用。
|
||||
*
|
||||
* @param {string} title 區塊名稱。
|
||||
*/
|
||||
function section(title) {
|
||||
currentStage = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* 輸出一般資訊訊息。
|
||||
*
|
||||
* @param {string} message 訊息內容。
|
||||
*/
|
||||
function info(message) {
|
||||
writeStdout('INF', message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 輸出警告訊息。
|
||||
*
|
||||
* @param {string} message 訊息內容。
|
||||
*/
|
||||
function warn(message) {
|
||||
writeStdout('WRN', message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 輸出錯誤訊息。
|
||||
*
|
||||
* @param {string} message 訊息內容。
|
||||
*/
|
||||
function fail(message) {
|
||||
writeStderr('ERR', message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判斷值是否視為空值。
|
||||
*
|
||||
* @param {*} value 要檢查的值。
|
||||
* @returns {boolean} 如果是空值則回傳 `true`。
|
||||
*/
|
||||
function isEmptyOrNull(value) {
|
||||
return value === undefined || value === null || value === '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 正規化環境變數值;workflow 模板缺值時可能代入字面值 `'null'`,一律視為未提供。
|
||||
*
|
||||
* @param {string | undefined} value 環境變數原始值。
|
||||
* @returns {string | undefined} 正規化後的值。
|
||||
*/
|
||||
function normalizeEnvValue(value) {
|
||||
return value === 'null' ? undefined : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 將 URL 遮罩成只含 origin 的文字,供 log 使用。
|
||||
*
|
||||
* @param {*} value 原始 URL 值。
|
||||
* @returns {string} 遮罩後的 origin,無法解析時回傳提示文字。
|
||||
*/
|
||||
function maskUrlForLog(value) {
|
||||
try {
|
||||
return new URL(String(value)).origin;
|
||||
} catch (error) {
|
||||
return '[invalid URL]';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 驗證必要值是否存在。
|
||||
*
|
||||
* @param {string} name 參數名稱。
|
||||
* @param {*} value 參數值。
|
||||
* @param {*} [displayValue=value] 寫進 log 的顯示值,敏感內容可先遮罩。
|
||||
*/
|
||||
function requireValue(name, value, displayValue = value) {
|
||||
info(`${name}=${displayValue}`);
|
||||
|
||||
if (isEmptyOrNull(value)) {
|
||||
fail(`${name} is required`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 驗證字串是否為正整數,且落在安全整數範圍內;下限 1 可避免把保留數設成 0 而清空所有 release。
|
||||
*
|
||||
* @param {string} name 參數名稱。
|
||||
* @param {string} value 參數值。
|
||||
*/
|
||||
function requirePositiveInteger(name, value) {
|
||||
if (!/^[0-9]+$/.test(value) || !Number.isSafeInteger(Number(value)) || Number(value) < 1) {
|
||||
fail(`${name} must be a positive integer within the safe integer range`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 驗證值是否為合法的 HTTPS 絕對 URL,避免 URL 解析失敗留到主流程中途才拋出。
|
||||
*
|
||||
* @param {string} name 參數名稱。
|
||||
* @param {*} value 參數值。
|
||||
*/
|
||||
function requireHttpsUrl(name, value) {
|
||||
let parsed;
|
||||
try {
|
||||
parsed = new URL(String(value));
|
||||
} catch (error) {
|
||||
fail(`${name} must be a valid absolute URL`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (parsed.protocol !== 'https:') {
|
||||
fail(`${name} must use HTTPS`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 驗證 repository 是否為 `owner/repo` 格式且僅含安全字元,拒絕 `.`、`..` 等路徑片段。
|
||||
*
|
||||
* @param {string} name 參數名稱。
|
||||
* @param {*} value 參數值。
|
||||
*/
|
||||
function requireRepository(name, value) {
|
||||
const segments = String(value).split('/');
|
||||
const isValidSegment = (segment) =>
|
||||
/^[A-Za-z0-9_.-]+$/.test(segment) && segment !== '.' && segment !== '..';
|
||||
|
||||
if (segments.length !== 2 || !segments.every(isValidSegment)) {
|
||||
fail(`${name} must be in owner/repo format`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 對指定 URL 發送 request,回傳狀態碼與 body。
|
||||
*
|
||||
* @param {string} url 完整目標網址。
|
||||
* @param {{ method?: string, headers?: Record<string, string>, collectBody?: boolean }} [options] request 設定;`collectBody` 為 `false` 時丟棄回應內容、只保留狀態碼。
|
||||
* @returns {Promise<{ statusCode: number, body: string }>} 回應狀態碼與內容。
|
||||
*/
|
||||
function request(url, { method = 'GET', headers = {}, collectBody = true } = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const target = new URL(url);
|
||||
if (target.protocol !== 'https:') {
|
||||
reject(new Error(`Refusing to send request to non-HTTPS URL: ${target.origin}`));
|
||||
return;
|
||||
}
|
||||
|
||||
const req = https.request(
|
||||
target,
|
||||
{
|
||||
method,
|
||||
headers,
|
||||
agent: keepAliveAgent,
|
||||
},
|
||||
(res) => {
|
||||
const statusCode = res.statusCode || 0;
|
||||
|
||||
if (!collectBody) {
|
||||
res.resume();
|
||||
res.on('end', () => {
|
||||
resolve({ statusCode, body: '' });
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const chunks = [];
|
||||
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', (chunk) => {
|
||||
chunks.push(chunk);
|
||||
});
|
||||
res.on('end', () => {
|
||||
resolve({
|
||||
statusCode,
|
||||
body: chunks.join(''),
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
req.on('error', reject);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 逐頁抓取 JSON 陣列資料,直到回傳空頁為止;超過 `maxPages` 即中止並回報異常。
|
||||
*
|
||||
* @param {string} baseUrl 不含 page 參數的 API URL。
|
||||
* @param {Record<string, string>} headers request 標頭。
|
||||
* @param {number} [maxPages=DEFAULT_MAX_PAGES] 分頁上限,可由環境變數 `MAX_PAGES` 覆寫。
|
||||
* @returns {Promise<any[]>} 合併後的陣列資料。
|
||||
*/
|
||||
async function fetchAllPages(baseUrl, headers, maxPages = DEFAULT_MAX_PAGES) {
|
||||
const all = [];
|
||||
|
||||
for (let page = 1; ; page += 1) {
|
||||
if (page > maxPages) {
|
||||
throw new Error(`GET ${baseUrl} 分頁超過 ${maxPages} 頁上限,中止抓取以避免無限迴圈;資料量更大時可用 MAX_PAGES 環境變數調高上限`);
|
||||
}
|
||||
|
||||
const pageUrl = `${baseUrl}?page=${page}`;
|
||||
const { statusCode, body } = await request(pageUrl, { headers });
|
||||
|
||||
if (statusCode < 200 || statusCode >= 300) {
|
||||
throw new Error(`GET ${pageUrl} failed with HTTP ${statusCode}: ${summarizeResponseBody(body)}`);
|
||||
}
|
||||
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(body || '[]');
|
||||
} catch (error) {
|
||||
throw new Error(`GET ${pageUrl} returned invalid JSON: ${summarizeResponseBody(body)}`);
|
||||
}
|
||||
|
||||
if (!Array.isArray(data)) {
|
||||
throw new Error(`GET ${pageUrl} did not return a JSON array`);
|
||||
}
|
||||
|
||||
if (data.length === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
all.push(...data);
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
/**
|
||||
* 對指定 URL 發送 DELETE request。
|
||||
*
|
||||
* @param {string} url 要刪除的資源網址。
|
||||
* @param {Record<string, string>} headers request 標頭。
|
||||
* @returns {Promise<{ statusCode: number, body: string }>} 回應狀態碼與內容。
|
||||
*/
|
||||
async function deleteResource(url, headers) {
|
||||
return request(url, {
|
||||
method: 'DELETE',
|
||||
headers,
|
||||
collectBody: false,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 以固定批次大小處理項目,降低逐筆等待造成的延遲;單筆例外不會中止同批其他項目。
|
||||
*
|
||||
* @param {any[]} items 要處理的項目。
|
||||
* @param {number} batchSize 每批同時處理的數量。
|
||||
* @param {(item: any) => Promise<boolean>} handler 單筆處理函式,回傳該筆是否成功。
|
||||
* @returns {Promise<PromiseSettledResult<boolean>[]>} 依原始順序排列的處理結果。
|
||||
*/
|
||||
async function processInBatches(items, batchSize, handler) {
|
||||
const results = [];
|
||||
|
||||
for (let index = 0; index < items.length; index += batchSize) {
|
||||
const batch = items.slice(index, index + batchSize);
|
||||
results.push(...(await Promise.allSettled(batch.map((item) => handler(item)))));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* 彙總批次結果;記錄被 reject 的例外,並回傳是否有任何一筆失敗。
|
||||
*
|
||||
* @param {PromiseSettledResult<boolean>[]} results 批次處理結果。
|
||||
* @returns {boolean} 只要有任一筆失敗即回傳 `true`。
|
||||
*/
|
||||
function hasBatchFailure(results) {
|
||||
let failed = false;
|
||||
|
||||
for (const result of results) {
|
||||
if (result.status === 'rejected') {
|
||||
failed = true;
|
||||
const reason = result.reason;
|
||||
fail(`批次處理發生例外: ${reason instanceof Error ? reason.message : String(reason)}`);
|
||||
} else if (result.value === false) {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 執行 release 與 tag 清理流程。
|
||||
*/
|
||||
async function main() {
|
||||
const GITEA_SERVER_URL = normalizeEnvValue(process.env.GITEA_SERVER_URL);
|
||||
const GITEA_REPOSITORY = normalizeEnvValue(process.env.GITEA_REPOSITORY);
|
||||
const RUNNER_TOKEN = normalizeEnvValue(process.env.RUNNER_TOKEN) ?? '';
|
||||
const KEEP_COUNT = normalizeEnvValue(process.env.KEEP_COUNT) ?? '';
|
||||
const MAX_PAGES = normalizeEnvValue(process.env.MAX_PAGES) ?? '';
|
||||
|
||||
section('參數檢查');
|
||||
requireValue('GITEA_SERVER_URL', GITEA_SERVER_URL, maskUrlForLog(GITEA_SERVER_URL));
|
||||
requireHttpsUrl('GITEA_SERVER_URL', GITEA_SERVER_URL);
|
||||
requireValue('GITEA_REPOSITORY', GITEA_REPOSITORY);
|
||||
requireRepository('GITEA_REPOSITORY', GITEA_REPOSITORY);
|
||||
requireValue('KEEP_COUNT', KEEP_COUNT);
|
||||
requirePositiveInteger('KEEP_COUNT', KEEP_COUNT);
|
||||
|
||||
let maxPages = DEFAULT_MAX_PAGES;
|
||||
if (!isEmptyOrNull(MAX_PAGES)) {
|
||||
info(`MAX_PAGES=${MAX_PAGES}`);
|
||||
requirePositiveInteger('MAX_PAGES', MAX_PAGES);
|
||||
maxPages = Number(MAX_PAGES);
|
||||
}
|
||||
|
||||
const keepCount = Number(KEEP_COUNT);
|
||||
const authHeaders = {};
|
||||
if (isEmptyOrNull(RUNNER_TOKEN)) {
|
||||
warn('RUNNER_TOKEN is empty; release API calls will be anonymous');
|
||||
} else {
|
||||
process.stdout.write(line);
|
||||
info('RUNNER_TOKEN=[redacted]');
|
||||
authHeaders.Authorization = `token ${RUNNER_TOKEN}`;
|
||||
}
|
||||
|
||||
const serverBase = new URL(GITEA_SERVER_URL);
|
||||
serverBase.username = '';
|
||||
serverBase.password = '';
|
||||
serverBase.search = '';
|
||||
serverBase.hash = '';
|
||||
const serverBaseUrl = serverBase.toString().replace(/\/+$/, '');
|
||||
|
||||
const repositoryPath = GITEA_REPOSITORY.split('/').map(encodeURIComponent).join('/');
|
||||
const releaseApiUrl = `${serverBaseUrl}/api/v1/repos/${repositoryPath}/releases`;
|
||||
|
||||
section('取得成品資訊');
|
||||
info(`GET ${releaseApiUrl}`);
|
||||
|
||||
const releaseJson = await fetchAllPages(releaseApiUrl, authHeaders, maxPages);
|
||||
releaseJson.sort((left, right) => {
|
||||
if (left.created_at < right.created_at) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (left.created_at > right.created_at) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
const releaseCount = releaseJson.length;
|
||||
info(`RELEASE_COUNT=${releaseCount}`);
|
||||
info(`KEEP_COUNT=${KEEP_COUNT}`);
|
||||
|
||||
if (releaseCount <= keepCount) {
|
||||
info('沒有需要清理的舊版本成品');
|
||||
} else {
|
||||
section('刪除舊版本成品');
|
||||
|
||||
const releaseToDelete = releaseJson.slice(keepCount);
|
||||
const releaseResults = await processInBatches(releaseToDelete, DELETE_CONCURRENCY, async (releaseItem) => {
|
||||
const releaseId = releaseItem?.id;
|
||||
if (!Number.isSafeInteger(releaseId) || releaseId <= 0) {
|
||||
fail(
|
||||
`成品 id 不是正整數,視為資料異常: ${sanitizeLogText(releaseItem?.tag_name || '')} (${sanitizeLogText(releaseItem?.name || '')})`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
const releaseTag = sanitizeLogText(releaseItem.tag_name || '');
|
||||
const releaseName = sanitizeLogText(releaseItem.name || '');
|
||||
const deleteUrl = `${releaseApiUrl}/${releaseId}`;
|
||||
info(`DELETE ${releaseTag} (${releaseName})`);
|
||||
|
||||
const { statusCode } = await deleteResource(deleteUrl, authHeaders);
|
||||
if (statusCode === 204) {
|
||||
info(`成功刪除: ${releaseTag} (${releaseName})`);
|
||||
return true;
|
||||
}
|
||||
|
||||
fail(`刪除失敗: ${releaseTag} (${releaseName}), HTTP ${statusCode}`);
|
||||
return false;
|
||||
});
|
||||
|
||||
if (hasBatchFailure(releaseResults)) {
|
||||
throw new Error('至少有一筆 release 刪除失敗');
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
section('刪除未指定 release 的 tag');
|
||||
|
||||
const releaseTags = new Set(
|
||||
releaseJson
|
||||
.slice(0, keepCount)
|
||||
.map((item) => item?.tag_name)
|
||||
.filter((tag) => !isEmptyOrNull(tag)),
|
||||
);
|
||||
|
||||
const tagApiUrl = `${serverBaseUrl}/api/v1/repos/${repositoryPath}/tags`;
|
||||
info(`GET ${tagApiUrl}`);
|
||||
|
||||
const tagJson = await fetchAllPages(tagApiUrl, authHeaders, maxPages);
|
||||
info(`TAG_COUNT=${tagJson.length}`);
|
||||
|
||||
const tagResults = await processInBatches(tagJson, DELETE_CONCURRENCY, async (tagItem) => {
|
||||
const tagName = tagItem?.name;
|
||||
if (isEmptyOrNull(tagName)) {
|
||||
fail('tag 缺少名稱,視為資料異常');
|
||||
return false;
|
||||
}
|
||||
|
||||
const safeTagName = sanitizeLogText(tagName);
|
||||
if (releaseTags.has(tagName)) {
|
||||
info(`保留指定 release 的 tag: ${safeTagName}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
const deleteUrl = `${tagApiUrl}/${encodeURIComponent(tagName)}`;
|
||||
info(`DELETE tag ${safeTagName}`);
|
||||
|
||||
const { statusCode } = await deleteResource(deleteUrl, authHeaders);
|
||||
if (statusCode === 204) {
|
||||
info(`成功刪除未指定 release 的 tag: ${safeTagName}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
fail(`刪除 tag 失敗: ${safeTagName}, HTTP ${statusCode}`);
|
||||
return false;
|
||||
});
|
||||
|
||||
if (hasBatchFailure(tagResults)) {
|
||||
throw new Error('至少有一筆 tag 刪除失敗');
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((error) => {
|
||||
const showStack = process.env.RUNNER_DEBUG === '1';
|
||||
fail(error instanceof Error ? (showStack && error.stack) || error.message : String(error));
|
||||
process.exitCode = 1;
|
||||
})
|
||||
.finally(() => {
|
||||
keepAliveAgent.destroy();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user