chore: remove ci workflow and tests
This commit is contained in:
@@ -1,17 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- develop
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Install jq
|
|
||||||
run: sudo apt-get update && sudo apt-get install -y jq
|
|
||||||
- name: Run shell tests
|
|
||||||
run: bash tests/entrypoint.sh
|
|
||||||
@@ -51,11 +51,6 @@ jobs:
|
|||||||
KEEP_COUNT: 2
|
KEEP_COUNT: 2
|
||||||
```
|
```
|
||||||
|
|
||||||
## 測試
|
|
||||||
|
|
||||||
- Shell 測試: [`tests/entrypoint.sh`](tests/entrypoint.sh)
|
|
||||||
- Gitea workflow: [`.gitea/workflows/ci.yaml`](.gitea/workflows/ci.yaml)
|
|
||||||
|
|
||||||
## 相關檔案
|
## 相關檔案
|
||||||
|
|
||||||
- Action 定義: [`action.yaml`](action.yaml)
|
- Action 定義: [`action.yaml`](action.yaml)
|
||||||
|
|||||||
@@ -1,115 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
||||||
TMP_DIR="$(mktemp -d)"
|
|
||||||
trap 'rm -rf "${TMP_DIR}"' EXIT
|
|
||||||
|
|
||||||
assert_contains() {
|
|
||||||
local needle="$1"
|
|
||||||
local haystack="$2"
|
|
||||||
|
|
||||||
if ! grep -Fq "$needle" <<<"$haystack"; then
|
|
||||||
printf 'Expected output to contain: %s\n' "$needle" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
write_mock_curl() {
|
|
||||||
cat > "${TMP_DIR}/curl" <<'EOF'
|
|
||||||
#!/bin/sh
|
|
||||||
method=GET
|
|
||||||
out_file=
|
|
||||||
headers_file=
|
|
||||||
url=
|
|
||||||
while [ "$#" -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
-X)
|
|
||||||
method=$2
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-D)
|
|
||||||
headers_file=$2
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-o)
|
|
||||||
out_file=$2
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-w)
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-H|-sS)
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
url=$1
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
status='HTTP/1.1 200 OK'
|
|
||||||
code='200'
|
|
||||||
body='[]'
|
|
||||||
|
|
||||||
case "$url" in
|
|
||||||
*'/api/v1/packages/test-owner?type=nuget&page=1&limit=100')
|
|
||||||
body='[{"name":"pkg-a","version":"1.0.0","created_at":"2023-01-01T00:00:00Z"},{"name":"pkg-a","version":"1.1.0","created_at":"2023-02-01T00:00:00Z"},{"name":"pkg-b","version":"0.1.0","created_at":"2023-03-01T00:00:00Z"}]'
|
|
||||||
;;
|
|
||||||
*'/api/v1/packages/test-owner/nuget/pkg-a/1.0.0')
|
|
||||||
if [ "$method" = "DELETE" ]; then
|
|
||||||
status='HTTP/1.1 204 No Content'
|
|
||||||
code='204'
|
|
||||||
body=''
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
printf '%s' "$body" > "$out_file"
|
|
||||||
{
|
|
||||||
printf '%s\n' "$status"
|
|
||||||
printf 'X-Request-Id: req-123\n'
|
|
||||||
} > "$headers_file"
|
|
||||||
|
|
||||||
if [ "$method" = "DELETE" ] && [ -n "${MOCK_DELETE_FILE:-}" ]; then
|
|
||||||
printf '%s %s\n' "$method" "$url" >> "$MOCK_DELETE_FILE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf '%s' "$code"
|
|
||||||
EOF
|
|
||||||
chmod +x "${TMP_DIR}/curl"
|
|
||||||
}
|
|
||||||
|
|
||||||
run_entrypoint() {
|
|
||||||
PATH="${TMP_DIR}:$PATH" \
|
|
||||||
GITEA_SERVER_URL="https://gitea.example.com" \
|
|
||||||
GITEA_REPOSITORY="test-owner/test-repo" \
|
|
||||||
env "$@" "${ROOT_DIR}/entrypoint.sh" 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
write_mock_curl
|
|
||||||
|
|
||||||
output="$(run_entrypoint INPUT_RUNNER_TOKEN=abc INPUT_KEEP_COUNT=1)"
|
|
||||||
assert_contains "Using token from inputs.RUNNER_TOKEN" "$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_COUNT=1)"
|
|
||||||
assert_contains "Using token from secrets.GITEA_TOKEN" "$output"
|
|
||||||
|
|
||||||
if run_entrypoint INPUT_KEEP_COUNT=-1 >/dev/null 2>&1; then
|
|
||||||
printf 'Expected invalid keep_count to fail\n' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if run_entrypoint >/dev/null 2>&1; then
|
|
||||||
printf 'Expected missing token to fail\n' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
delete_log="${TMP_DIR}/delete.log"
|
|
||||||
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