refactor: rename keep versions input

This commit is contained in:
2026-05-15 02:20:02 +00:00
parent c923a6ce55
commit 6d1ff786eb
4 changed files with 13 additions and 13 deletions
+3 -3
View File
@@ -24,7 +24,7 @@ Action 會依序嘗試以下來源:
| 名稱 | 類型 | 預設值 | 說明 | | 名稱 | 類型 | 預設值 | 說明 |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| `RUNNER_TOKEN` | string | - | Gitea API token,優先順序最高 | | `RUNNER_TOKEN` | string | - | Gitea API token,優先順序最高 |
| `KEEP_VERSIONS` | integer string | `2` | 每個套件要保留的最新版本數,必須是整數且 `>= 0` | | `KEEP_COUNT` | integer string | `2` | 每個套件要保留的最新版本數,必須是整數且 `>= 0` |
## Log 行為 ## Log 行為
@@ -32,7 +32,7 @@ Action 會依序嘗試以下來源:
- `Trying token from ...` - `Trying token from ...`
- `Using token from ...` - `Using token from ...`
- `keep_versions=...` - `keep_count=...`
- `GET /api/v1/... -> 200 OK` - `GET /api/v1/... -> 200 OK`
- `Candidate to delete: ...` - `Candidate to delete: ...`
- `Deleted package ... -> 204 No Content` - `Deleted package ... -> 204 No Content`
@@ -48,7 +48,7 @@ jobs:
- uses: ./ - uses: ./
with: with:
RUNNER_TOKEN: ${{ secrets.GITEA_TOKEN }} RUNNER_TOKEN: ${{ secrets.GITEA_TOKEN }}
KEEP_VERSIONS: 2 KEEP_COUNT: 2
``` ```
## 測試 ## 測試
+1 -1
View File
@@ -5,7 +5,7 @@ inputs:
RUNNER_TOKEN: RUNNER_TOKEN:
description: 'Gitea API token, highest priority source' description: 'Gitea API token, highest priority source'
required: false required: false
KEEP_VERSIONS: KEEP_COUNT:
description: '保留的版本數量' description: '保留的版本數量'
required: false required: false
default: '2' default: '2'
+3 -3
View File
@@ -23,14 +23,14 @@ resolve_token() {
} }
resolve_keep_versions() { resolve_keep_versions() {
local raw_value="${INPUT_KEEP_VERSIONS:-2}" local raw_value="${INPUT_KEEP_COUNT:-2}"
if [[ -z "${raw_value}" ]]; then if [[ -z "${raw_value}" ]]; then
raw_value="2" raw_value="2"
fi fi
if [[ ! "${raw_value}" =~ ^[0-9]+$ ]]; then if [[ ! "${raw_value}" =~ ^[0-9]+$ ]]; then
fail "Invalid keep_versions: ${raw_value}" fail "Invalid keep_count: ${raw_value}"
fi fi
printf '%s' "${raw_value}" printf '%s' "${raw_value}"
@@ -218,7 +218,7 @@ main() {
export RESOLVED_GITEA_TOKEN="$token" export RESOLVED_GITEA_TOKEN="$token"
init_repo_context init_repo_context
keep_versions="$(resolve_keep_versions)" keep_versions="$(resolve_keep_versions)"
log "keep_versions=${keep_versions}" log "keep_count=${keep_versions}"
log "Token source resolved successfully" log "Token source resolved successfully"
CANDIDATES_FILE="$(mktemp)" CANDIDATES_FILE="$(mktemp)"
+6 -6
View File
@@ -90,17 +90,17 @@ run_entrypoint() {
write_mock_curl 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 "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 "request_id=req-123" "$output"
assert_contains "Deleted package pkg-a version 1.0.0 -> 204 No Content" "$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" assert_contains "Using token from secrets.GITEA_TOKEN" "$output"
if run_entrypoint INPUT_KEEP_VERSIONS=-1 >/dev/null 2>&1; then if run_entrypoint INPUT_KEEP_COUNT=-1 >/dev/null 2>&1; then
printf 'Expected invalid keep_versions to fail\n' >&2 printf 'Expected invalid keep_count to fail\n' >&2
exit 1 exit 1
fi fi
@@ -110,6 +110,6 @@ if run_entrypoint >/dev/null 2>&1; then
fi fi
delete_log="${TMP_DIR}/delete.log" 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 "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")" assert_contains "DELETE https://gitea.example.com/api/v1/packages/test-owner/nuget/pkg-a/1.0.0" "$(cat "$delete_log")"