#!/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 < 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!"