refactor: rename keep versions input
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
||||
## 測試
|
||||
|
||||
+1
-1
@@ -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'
|
||||
|
||||
+3
-3
@@ -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)"
|
||||
|
||||
+6
-6
@@ -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")"
|
||||
|
||||
Reference in New Issue
Block a user