From 32124d999f8bec6b101be3e01c2e6c7f8fb7664d Mon Sep 17 00:00:00 2001 From: kovagoadi Date: Sat, 22 Nov 2025 16:32:19 +0100 Subject: [PATCH] Add onboarding testing for test-renovate workflow --- scripts/test-renovate.sh | 125 +++++++++++++++++++++++++++++++-------- 1 file changed, 100 insertions(+), 25 deletions(-) diff --git a/scripts/test-renovate.sh b/scripts/test-renovate.sh index 8824dff..ec4ebcc 100755 --- a/scripts/test-renovate.sh +++ b/scripts/test-renovate.sh @@ -1,56 +1,131 @@ #!/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 -echo "Running Renovate dry-run..." -renovate --dry-run=full > renovate-output.log 2>&1 -cat renovate-output.log +# --- Phase 1: Pre-Onboarding Dry-Run --- +echo "Running Renovate dry-run (Phase 1: Pre-Onboarding)..." +# Ensure repo is clean first +cleanup -# Assertions -echo "Checking for successful run..." -if ! grep -q "Repository finished" renovate-output.log; then - echo "Error: Renovate run did not finish successfully." +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 errors..." -if grep -q "ERROR" renovate-output.log; then - echo "Error: Renovate log contains errors." +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 < 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.log; then - echo "Error: Expected 'renovate/nginx-' branch not found in output." +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.log; then +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.log; then - echo "Error: Expected 'renovate/actions-checkout-' branch not found in output." +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.log; then +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 "Checking for onboarding PR..." -if ! grep -q "Would create onboarding PR" renovate-output.log; then - echo "Error: Expected onboarding PR creation not found." - exit 1 -fi - -echo "Test passed!" -rm renovate-output.log +echo "Phase 3 Passed: Update PRs detected." +echo "All Dry-Run Tests Passed!"