chore: triage review findings
This commit is contained in:
+90
-12
@@ -6,6 +6,16 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
source "$ROOT_DIR/entrypoint.sh"
|
||||
|
||||
declare -a CLEANUP_PATHS=()
|
||||
|
||||
cleanup() {
|
||||
if [ "${#CLEANUP_PATHS[@]}" -gt 0 ]; then
|
||||
rm -rf "${CLEANUP_PATHS[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
fail() {
|
||||
printf '[error] %s\n' "$1" >&2
|
||||
exit 1
|
||||
@@ -27,6 +37,10 @@ make_mock_curl() {
|
||||
|
||||
cat >"$bin_dir/curl" <<'EOF'
|
||||
#!/bin/sh
|
||||
if [ -n "${FAKE_CURL_LOG_FILE:-}" ]; then
|
||||
printf '%s\n' "$*" >> "$FAKE_CURL_LOG_FILE"
|
||||
fi
|
||||
|
||||
if [ "${FAKE_CURL_STATUS:-0}" != "0" ]; then
|
||||
exit "$FAKE_CURL_STATUS"
|
||||
fi
|
||||
@@ -135,6 +149,7 @@ run_entrypoint() {
|
||||
local stderr_file
|
||||
|
||||
workdir="$(mktemp -d)"
|
||||
CLEANUP_PATHS+=("$workdir")
|
||||
bin_dir="$workdir/bin"
|
||||
mkdir -p "$bin_dir"
|
||||
make_mock_curl "$bin_dir" "$response_file"
|
||||
@@ -147,6 +162,7 @@ run_entrypoint() {
|
||||
if [ -n "$token" ]; then
|
||||
FAKE_CURL_STATUS="$fake_status" \
|
||||
FAKE_CURL_RESPONSE_FILE="$response_file" \
|
||||
FAKE_CURL_LOG_FILE="$workdir/curl_args" \
|
||||
PATH="$bin_dir:$PATH" \
|
||||
GITEA_SERVER_URL="https://gitea.example.com" \
|
||||
GITEA_REPOSITORY="org/repo" \
|
||||
@@ -157,6 +173,7 @@ run_entrypoint() {
|
||||
else
|
||||
FAKE_CURL_STATUS="$fake_status" \
|
||||
FAKE_CURL_RESPONSE_FILE="$response_file" \
|
||||
FAKE_CURL_LOG_FILE="$workdir/curl_args" \
|
||||
PATH="$bin_dir:$PATH" \
|
||||
GITEA_SERVER_URL="https://gitea.example.com" \
|
||||
GITEA_REPOSITORY="org/repo" \
|
||||
@@ -174,13 +191,17 @@ test_unit_helpers() {
|
||||
assert_eq "true" "$(normalize_beta_flag "true")" "normalize_beta_flag true"
|
||||
assert_eq "0.1.0" "$(next_release_version "0.0.9")" "next_release_version carry patch"
|
||||
assert_eq "2.0.0" "$(next_release_version "1.9.9")" "next_release_version carry minor"
|
||||
assert_eq "100.0.0" "$(next_release_version "99.9.9")" "next_release_version carry major"
|
||||
}
|
||||
|
||||
test_stable_release_flow() {
|
||||
local workdir
|
||||
local response_file
|
||||
local output_file
|
||||
|
||||
response_file="$(mktemp)"
|
||||
workdir="$(mktemp -d)"
|
||||
CLEANUP_PATHS+=("$workdir")
|
||||
response_file="$workdir/releases.json"
|
||||
cat >"$response_file" <<'EOF'
|
||||
[
|
||||
{"tag_name":"v1.2.3-beta.1"},
|
||||
@@ -194,10 +215,13 @@ EOF
|
||||
}
|
||||
|
||||
test_beta_release_flow() {
|
||||
local workdir
|
||||
local response_file
|
||||
local output_file
|
||||
|
||||
response_file="$(mktemp)"
|
||||
workdir="$(mktemp -d)"
|
||||
CLEANUP_PATHS+=("$workdir")
|
||||
response_file="$workdir/releases.json"
|
||||
cat >"$response_file" <<'EOF'
|
||||
[
|
||||
{"tag_name":"v1.2.3"},
|
||||
@@ -211,10 +235,13 @@ EOF
|
||||
}
|
||||
|
||||
test_empty_release_list() {
|
||||
local workdir
|
||||
local response_file
|
||||
local output_file
|
||||
|
||||
response_file="$(mktemp)"
|
||||
workdir="$(mktemp -d)"
|
||||
CLEANUP_PATHS+=("$workdir")
|
||||
response_file="$workdir/releases.json"
|
||||
printf '%s\n' '[]' >"$response_file"
|
||||
|
||||
output_file="$(run_entrypoint "$response_file" "false")"
|
||||
@@ -222,10 +249,13 @@ test_empty_release_list() {
|
||||
}
|
||||
|
||||
test_only_beta_releases() {
|
||||
local workdir
|
||||
local response_file
|
||||
local output_file
|
||||
|
||||
response_file="$(mktemp)"
|
||||
workdir="$(mktemp -d)"
|
||||
CLEANUP_PATHS+=("$workdir")
|
||||
response_file="$workdir/releases.json"
|
||||
cat >"$response_file" <<'EOF'
|
||||
[
|
||||
{"tag_name":"v2.4.6-beta.1"},
|
||||
@@ -238,27 +268,73 @@ EOF
|
||||
}
|
||||
|
||||
test_null_release_payload() {
|
||||
local workdir
|
||||
local response_file
|
||||
local output_file
|
||||
|
||||
response_file="$(mktemp)"
|
||||
workdir="$(mktemp -d)"
|
||||
CLEANUP_PATHS+=("$workdir")
|
||||
response_file="$workdir/releases.json"
|
||||
printf '%s\n' 'null' >"$response_file"
|
||||
|
||||
output_file="$(run_entrypoint "$response_file" "false")"
|
||||
assert_eq "version=0.0.1" "$(cat "$output_file")" "null release payload"
|
||||
}
|
||||
|
||||
test_malformed_release_payload() {
|
||||
local response_file
|
||||
test_token_auth_header() {
|
||||
local workdir
|
||||
local response_file
|
||||
local bin_dir
|
||||
local output_file
|
||||
local curl_args
|
||||
local stdout_file
|
||||
local stderr_file
|
||||
|
||||
workdir="$(mktemp -d)"
|
||||
CLEANUP_PATHS+=("$workdir")
|
||||
response_file="$workdir/releases.json"
|
||||
printf '%s\n' '[]' >"$response_file"
|
||||
|
||||
bin_dir="$workdir/bin"
|
||||
mkdir -p "$bin_dir"
|
||||
make_mock_curl "$bin_dir" "$response_file"
|
||||
make_mock_jq "$bin_dir"
|
||||
|
||||
output_file="$workdir/github_output"
|
||||
stdout_file="$workdir/stdout"
|
||||
stderr_file="$workdir/stderr"
|
||||
|
||||
FAKE_CURL_STATUS=0 \
|
||||
FAKE_CURL_RESPONSE_FILE="$response_file" \
|
||||
FAKE_CURL_LOG_FILE="$workdir/curl_args" \
|
||||
PATH="$bin_dir:$PATH" \
|
||||
GITEA_SERVER_URL="https://gitea.example.com" \
|
||||
GITEA_REPOSITORY="org/repo" \
|
||||
RUNNER_TOKEN="secret-token" \
|
||||
IS_BETA="false" \
|
||||
GITHUB_OUTPUT="$output_file" \
|
||||
bash "$ROOT_DIR/entrypoint.sh" >"$stdout_file" 2>"$stderr_file"
|
||||
|
||||
curl_args="$workdir/curl_args"
|
||||
if ! grep -q 'Authorization: token secret-token' "$curl_args"; then
|
||||
fail "token auth header: missing Authorization header"
|
||||
fi
|
||||
|
||||
assert_eq "version=0.0.1" "$(cat "$output_file")" "token auth output"
|
||||
}
|
||||
|
||||
test_malformed_release_payload() {
|
||||
local workdir
|
||||
local response_file
|
||||
local bin_dir
|
||||
local output_file
|
||||
local stdout_file
|
||||
local stderr_file
|
||||
|
||||
response_file="$(mktemp)"
|
||||
printf '%s\n' '{' >"$response_file"
|
||||
workdir="$(mktemp -d)"
|
||||
CLEANUP_PATHS+=("$workdir")
|
||||
response_file="$workdir/releases.json"
|
||||
printf '%s\n' '{' >"$response_file"
|
||||
bin_dir="$workdir/bin"
|
||||
mkdir -p "$bin_dir"
|
||||
make_mock_curl "$bin_dir" "$response_file"
|
||||
@@ -280,16 +356,17 @@ test_malformed_release_payload() {
|
||||
}
|
||||
|
||||
test_curl_failure() {
|
||||
local response_file
|
||||
local workdir
|
||||
local response_file
|
||||
local bin_dir
|
||||
local output_file
|
||||
local stdout_file
|
||||
local stderr_file
|
||||
|
||||
response_file="$(mktemp)"
|
||||
printf '%s\n' '[]' >"$response_file"
|
||||
workdir="$(mktemp -d)"
|
||||
CLEANUP_PATHS+=("$workdir")
|
||||
response_file="$workdir/releases.json"
|
||||
printf '%s\n' '[]' >"$response_file"
|
||||
bin_dir="$workdir/bin"
|
||||
mkdir -p "$bin_dir"
|
||||
make_mock_curl "$bin_dir" "$response_file"
|
||||
@@ -315,6 +392,7 @@ test_beta_release_flow
|
||||
test_empty_release_list
|
||||
test_only_beta_releases
|
||||
test_null_release_payload
|
||||
test_token_auth_header
|
||||
test_malformed_release_payload
|
||||
test_curl_failure
|
||||
|
||||
|
||||
Reference in New Issue
Block a user