# CLEANUP OLD NUGET 清理 Gitea NuGet 套件舊版本的 Docker Action。 ## 功能 - 依序嘗試取得 Gitea API token。 - 預設每個套件保留最新 `2` 個版本。 - 直接刪除超出保留數量的舊版本。 - 只處理你指定的 NuGet 套件名稱,可一次指定多個。 - 輸出可搜尋的 log,包含 API status、request id 與 summary。 - 每頁預設抓取 100 筆版本,可用 `PAGE_LIMIT` 調整。 ## Token 來源順序 Action 會依序嘗試以下來源: 1. `inputs.RUNNER_TOKEN` 2. `secrets.GITEA_TOKEN` 3. `secrets.RUNNER_TOKEN` 若三者都沒有值,Action 會以非零 exit code 結束。 ## Inputs | 名稱 | 類型 | 預設值 | 說明 | | --- | --- | --- | --- | | `RUNNER_TOKEN` | string | - | Gitea API token,優先順序最高 | | `KEEP_COUNT` | integer string | `2` | 每個套件要保留的最新版本數,必須是整數且 `>= 0` | | `PACKAGE_NAMES` | string | - | 要清理的 NuGet 套件名稱,逗號分隔,可一次指定多個 | ## Log 行為 執行時會輸出這類資訊: - `Trying token from ...` - `Using token from ...` - `keep_count=...` - `package_names=...` - `GET /api/v1/... -> 200 OK` - `Candidate to delete: ...` - `Deleted package ... -> 204 No Content` - `Summary: packages=... versions=... kept=... candidates=... deleted=... errors=...` ## Workflow 範例 ```yaml jobs: cleanup: runs-on: ubuntu steps: - uses: https://gitea.jsc.idv.tw/jiantw83/cleanup-nuget@${{ vars.ACTION_CLEANUP_NUGET_VERSION }} with: RUNNER_TOKEN: ${{ secrets.GITEA_TOKEN }} KEEP_COUNT: 2 PACKAGE_NAMES: package-a,package-b ``` ## 相關檔案 - Action 定義: [`action.yaml`](action.yaml) - 執行腳本: [`entrypoint.sh`](entrypoint.sh) ## 專案範圍 - 不需要新增 `.gitea/workflows/ci.yaml` - 不需要新增 `tests/*` - 除非另外明確要求,請不要再補這兩類檔案 ## Review Exclusions 以下審查意見屬於刻意排除,不再以測試或 CI 的形式處理: - `entrypoint.sh:10-15` `trim` - `entrypoint.sh:16-18` `url_encode` - `entrypoint.sh:30-59` `resolve_package_names` - `entrypoint.sh:61-76` `parse_repo_context` - `entrypoint.sh:35-51` `resolve_keep_count` - `entrypoint.sh:78-120` `api_request` - `entrypoint.sh:122-181` `fetch_package_versions` - `entrypoint.sh:183-241` `collect_package_candidates` - `entrypoint.sh:243-286` `process_candidates` - `entrypoint.sh(整體)` 新增測試程式碼與測試框架 - `entrypoint.sh(整體)` 端對端測試 - `entrypoint.sh:7` 結構化 logging - `entrypoint.sh:105` 驗證 `GITEA_SERVER_URL` - `entrypoint.sh:125-126,241` 暫存檔重用與 I/O 微調 - `entrypoint.sh:149` 流式 JSON 合併 - `entrypoint.sh:204,215` 排序與日誌分離建議 - `entrypoint.sh:243-286` 重複 `url_encode` 進一步最佳化 - `entrypoint.sh:183-241` 改回掃描 owner 全量套件的 N+1 API 建議