From 6d1ff786eb2900ac47111e617f46c91e2dc98b73 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 15 May 2026 02:20:02 +0000 Subject: [PATCH] refactor: rename keep versions input --- README.md | 6 +++--- action.yaml | 2 +- entrypoint.sh | 6 +++--- tests/entrypoint.sh | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index bb61032..a3f3bad 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Action 會依序嘗試以下來源: | 名稱 | 類型 | 預設值 | 說明 | | --- | --- | --- | --- | | `RUNNER_TOKEN` | string | - | Gitea API token,優先順序最高 | -| `KEEP_VERSIONS` | integer string | `2` | 每個套件要保留的最新版本數,必須是整數且 `>= 0` | +| `KEEP_COUNT` | integer string | `2` | 每個套件要保留的最新版本數,必須是整數且 `>= 0` | ## Log 行為 @@ -32,7 +32,7 @@ Action 會依序嘗試以下來源: - `Trying token from ...` - `Using token from ...` -- `keep_versions=...` +- `keep_count=...` - `GET /api/v1/... -> 200 OK` - `Candidate to delete: ...` - `Deleted package ... -> 204 No Content` @@ -48,7 +48,7 @@ jobs: - uses: ./ with: RUNNER_TOKEN: ${{ secrets.GITEA_TOKEN }} - KEEP_VERSIONS: 2 + KEEP_COUNT: 2 ``` ## 測試 diff --git a/action.yaml b/action.yaml index 1f2c3e5..119e87b 100644 --- a/action.yaml +++ b/action.yaml @@ -5,7 +5,7 @@ inputs: RUNNER_TOKEN: description: 'Gitea API token, highest priority source' required: false - KEEP_VERSIONS: + KEEP_COUNT: description: '保留的版本數量' required: false default: '2' diff --git a/entrypoint.sh b/entrypoint.sh index 76d1212..1071a77 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -23,14 +23,14 @@ resolve_token() { } resolve_keep_versions() { - local raw_value="${INPUT_KEEP_VERSIONS:-2}" + local raw_value="${INPUT_KEEP_COUNT:-2}" if [[ -z "${raw_value}" ]]; then raw_value="2" fi if [[ ! "${raw_value}" =~ ^[0-9]+$ ]]; then - fail "Invalid keep_versions: ${raw_value}" + fail "Invalid keep_count: ${raw_value}" fi printf '%s' "${raw_value}" @@ -218,7 +218,7 @@ main() { export RESOLVED_GITEA_TOKEN="$token" init_repo_context keep_versions="$(resolve_keep_versions)" - log "keep_versions=${keep_versions}" + log "keep_count=${keep_versions}" log "Token source resolved successfully" CANDIDATES_FILE="$(mktemp)" diff --git a/tests/entrypoint.sh b/tests/entrypoint.sh index a00f68e..762e3ee 100644 --- a/tests/entrypoint.sh +++ b/tests/entrypoint.sh @@ -90,17 +90,17 @@ run_entrypoint() { write_mock_curl -output="$(run_entrypoint INPUT_RUNNER_TOKEN=abc INPUT_KEEP_VERSIONS=1)" +output="$(run_entrypoint INPUT_RUNNER_TOKEN=abc INPUT_KEEP_COUNT=1)" assert_contains "Using token from inputs.RUNNER_TOKEN" "$output" -assert_contains "keep_versions=1" "$output" +assert_contains "keep_count=1" "$output" assert_contains "request_id=req-123" "$output" assert_contains "Deleted package pkg-a version 1.0.0 -> 204 No Content" "$output" -output="$(run_entrypoint GITEA_TOKEN=secret INPUT_KEEP_VERSIONS=1)" +output="$(run_entrypoint GITEA_TOKEN=secret INPUT_KEEP_COUNT=1)" assert_contains "Using token from secrets.GITEA_TOKEN" "$output" -if run_entrypoint INPUT_KEEP_VERSIONS=-1 >/dev/null 2>&1; then - printf 'Expected invalid keep_versions to fail\n' >&2 +if run_entrypoint INPUT_KEEP_COUNT=-1 >/dev/null 2>&1; then + printf 'Expected invalid keep_count to fail\n' >&2 exit 1 fi @@ -110,6 +110,6 @@ if run_entrypoint >/dev/null 2>&1; then fi delete_log="${TMP_DIR}/delete.log" -output="$(MOCK_DELETE_FILE="$delete_log" run_entrypoint INPUT_RUNNER_TOKEN=abc INPUT_KEEP_VERSIONS=1)" +output="$(MOCK_DELETE_FILE="$delete_log" run_entrypoint INPUT_RUNNER_TOKEN=abc INPUT_KEEP_COUNT=1)" assert_contains "Summary: packages=2 versions=3 kept=2 candidates=1 deleted=1 errors=0" "$output" assert_contains "DELETE https://gitea.example.com/api/v1/packages/test-owner/nuget/pkg-a/1.0.0" "$(cat "$delete_log")"