Files
Renovate/scripts/test-renovate.sh
kovagoadi 972a851ad0
All checks were successful
Test Renovate Config / test-renovate (push) Successful in 1m25s
Test Renovate Config / e2e-renovate (push) Successful in 3m0s
Run Renovate / renovate (push) Successful in 6m20s
Add renovate tests (#35)
Reviewed-on: #35
Co-authored-by: kovagoadi <kovagoadi@gmail.com>
Co-committed-by: kovagoadi <kovagoadi@gmail.com>
2025-11-22 17:13:00 +01:00

132 lines
4.2 KiB
Bash
Executable File

#!/bin/bash
set -e
# Configuration
GITEA_API_URL="https://gitea.kovagoadi.hu/api/v1"
REPO_OWNER="renovate-test"
REPO_NAME="test"
RENOVATE_CONFIG_FILE=${RENOVATE_CONFIG_FILE:-"/workspace/kovagoadi.hu/Renovate/renovate-config.js"}
# Ensure RENOVATE_TOKEN is available
if [ -z "$RENOVATE_TOKEN" ]; then
echo "Error: RENOVATE_TOKEN is not set."
exit 1
fi
# Cleanup function
cleanup() {
echo "Cleaning up..."
# Delete renovate.json from main branch if it exists (to reset state)
FILE_INFO=$(curl -s -H "Authorization: token $RENOVATE_TOKEN" "$GITEA_API_URL/repos/$REPO_OWNER/$REPO_NAME/contents/renovate.json?ref=main")
FILE_SHA=$(echo "$FILE_INFO" | jq -r '.sha')
if [ "$FILE_SHA" != "null" ] && [ -n "$FILE_SHA" ]; then
echo "Deleting renovate.json to reset repository state..."
curl -s -X DELETE -H "Authorization: token $RENOVATE_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"message\": \"Cleanup: Delete renovate.json\", \"sha\": \"$FILE_SHA\", \"branch\": \"main\"}" \
"$GITEA_API_URL/repos/$REPO_OWNER/$REPO_NAME/contents/renovate.json"
fi
rm -f renovate-output-pre.log renovate-output-post.log
}
# Register cleanup to run on exit
trap cleanup EXIT
echo "Validating Renovate configuration..."
renovate-config-validator
# --- Phase 1: Pre-Onboarding Dry-Run ---
echo "Running Renovate dry-run (Phase 1: Pre-Onboarding)..."
# Ensure repo is clean first
cleanup
set +e
renovate --dry-run=full > renovate-output-pre.log 2>&1
RENOVATE_EXIT_CODE=$?
set -e
cat renovate-output-pre.log
if [ $RENOVATE_EXIT_CODE -ne 0 ]; then
echo "Error: Renovate dry-run (Phase 1) failed."
exit 1
fi
echo "Checking for onboarding PR in Phase 1..."
if ! grep -q "Would create onboarding PR" renovate-output-pre.log; then
echo "Error: Expected 'Would create onboarding PR' not found in Phase 1 output."
exit 1
fi
echo "Phase 1 Passed: Onboarding PR detected."
# --- Phase 2: Onboarding Simulation ---
echo "Simulating Onboarding..."
# Content of renovate.json (base64 encoded for API if needed, but Gitea API takes content string)
# We'll use a simple config similar to the repo's renovate.json
CONTENT=$(cat <<EOF
{
"\$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
],
"pinDigests": true
}
EOF
)
# Base64 encode content
CONTENT_B64=$(echo "$CONTENT" | base64 -w 0)
echo "Pushing renovate.json to $REPO_OWNER/$REPO_NAME..."
CREATE_RESP=$(curl -s -X POST -H "Authorization: token $RENOVATE_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"content\": \"$CONTENT_B64\", \"message\": \"Simulate Onboarding: Add renovate.json\", \"branch\": \"main\"}" \
"$GITEA_API_URL/repos/$REPO_OWNER/$REPO_NAME/contents/renovate.json")
if echo "$CREATE_RESP" | grep -q "sha"; then
echo "renovate.json pushed successfully."
else
echo "Error pushing renovate.json: $CREATE_RESP"
exit 1
fi
# --- Phase 3: Post-Onboarding Dry-Run ---
echo "Running Renovate dry-run (Phase 3: Post-Onboarding)..."
set +e
renovate --dry-run=full > renovate-output-post.log 2>&1
RENOVATE_EXIT_CODE=$?
set -e
cat renovate-output-post.log
if [ $RENOVATE_EXIT_CODE -ne 0 ]; then
echo "Error: Renovate dry-run (Phase 3) failed."
exit 1
fi
# Specific assertions based on the test repo state (now onboarded)
echo "Checking for expected nginx update..."
if ! grep -q "renovate/nginx-" renovate-output-post.log; then
echo "Error: Expected 'renovate/nginx-' branch not found in Phase 3 output."
exit 1
fi
echo "Checking for nginx PR title..."
if ! grep -q "Update nginx Docker tag to" renovate-output-post.log; then
echo "Error: Expected PR title 'Update nginx Docker tag to...' not found."
exit 1
fi
echo "Checking for expected actions/checkout update..."
if ! grep -q "renovate/actions-checkout-" renovate-output-post.log; then
echo "Error: Expected 'renovate/actions-checkout-' branch not found in Phase 3 output."
exit 1
fi
echo "Checking for actions/checkout PR title..."
if ! grep -q "Update actions/checkout action to" renovate-output-post.log; then
echo "Error: Expected PR title 'Update actions/checkout action to...' not found."
exit 1
fi
echo "Phase 3 Passed: Update PRs detected."
echo "All Dry-Run Tests Passed!"