#!/bin/bash set -e echo "Validating Renovate configuration..." renovate-config-validator echo "Running Renovate E2E (no dry-run)..." # Capture output but also stream it to stdout for debugging set +e renovate > renovate-e2e-output.log 2>&1 RENOVATE_EXIT_CODE=$? set -e cat renovate-e2e-output.log if [ $RENOVATE_EXIT_CODE -ne 0 ]; then echo "Error: Renovate command failed with exit code $RENOVATE_EXIT_CODE" exit 1 fi # Assertions echo "Checking for successful run..." if ! grep -q "Repository finished" renovate-e2e-output.log; then echo "Error: Renovate run did not finish successfully." exit 1 fi echo "Checking for errors..." if grep -q "ERROR" renovate-e2e-output.log; then echo "Error: Renovate log contains errors." exit 1 fi echo "E2E Test passed!" rm renovate-e2e-output.log # API Verification and Cleanup GITEA_API_URL="https://gitea.kovagoadi.hu/api/v1" REPO_OWNER="renovate-test" REPO_NAME="test" # Function to clean up PRs and reset repo cleanup() { echo "Cleaning up..." # 1. Delete all Open PRs PRS=$(curl -s -H "Authorization: token $RENOVATE_TOKEN" "$GITEA_API_URL/repos/$REPO_OWNER/$REPO_NAME/pulls?state=open") PR_INDEXES=$(echo "$PRS" | jq -r '.[].number') for INDEX in $PR_INDEXES; do if [ "$INDEX" != "null" ]; then echo "Deleting PR #$INDEX..." curl -s -X DELETE -H "Authorization: token $RENOVATE_TOKEN" "$GITEA_API_URL/repos/$REPO_OWNER/$REPO_NAME/issues/$INDEX" fi done # 2. Delete renovate.json from main branch to reset state (if exists) 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 } # Register cleanup to run on exit trap cleanup EXIT # --- Step 1: Initial Run (Onboarding) --- echo "Running Renovate E2E (Run 1: Onboarding)..." set +e renovate > renovate-e2e-output.log 2>&1 RENOVATE_EXIT_CODE=$? set -e cat renovate-e2e-output.log if [ $RENOVATE_EXIT_CODE -ne 0 ]; then echo "Error: Renovate command failed." exit 1 fi # Check for Onboarding PR PRS=$(curl -s -H "Authorization: token $RENOVATE_TOKEN" "$GITEA_API_URL/repos/$REPO_OWNER/$REPO_NAME/pulls?state=open") ONBOARDING_PR_NUM=$(echo "$PRS" | jq -r '.[] | select(.title | contains("Configure Renovate")) | .number') if [ -n "$ONBOARDING_PR_NUM" ] && [ "$ONBOARDING_PR_NUM" != "null" ]; then echo "Onboarding PR found (#$ONBOARDING_PR_NUM). Merging it to enable updates..." # Merge Onboarding PR MERGE_RESP=$(curl -s -X POST -H "Authorization: token $RENOVATE_TOKEN" \ -H "Content-Type: application/json" \ -d "{\"Do\": \"merge\"}" \ "$GITEA_API_URL/repos/$REPO_OWNER/$REPO_NAME/pulls/$ONBOARDING_PR_NUM/merge") # Check if merge was successful (simple check) if echo "$MERGE_RESP" | grep -q "Pull request has been merged"; then echo "Onboarding PR merged successfully." else # Fallback: check status code or response echo "Merge response: $MERGE_RESP" fi # --- Step 2: Second Run (Updates) --- echo "Running Renovate E2E (Run 2: Updates)..." set +e renovate > renovate-e2e-output-2.log 2>&1 RENOVATE_EXIT_CODE=$? set -e cat renovate-e2e-output-2.log if [ $RENOVATE_EXIT_CODE -ne 0 ]; then echo "Error: Renovate command (Run 2) failed." exit 1 fi else echo "No Onboarding PR found. Assuming repo is already onboarded or config exists." fi echo "Verifying Update PRs and Content..." # Fetch PRs again PRS=$(curl -s -H "Authorization: token $RENOVATE_TOKEN" "$GITEA_API_URL/repos/$REPO_OWNER/$REPO_NAME/pulls?state=open") # Verify Nginx PR NGINX_PR_NUM=$(echo "$PRS" | jq -r '.[] | select(.title | contains("Update nginx Docker tag")) | .number') if [ -n "$NGINX_PR_NUM" ] && [ "$NGINX_PR_NUM" != "null" ]; then echo "API Verification: Nginx PR found (#$NGINX_PR_NUM)." # Verify Content DIFF=$(curl -s -H "Authorization: token $RENOVATE_TOKEN" "$GITEA_API_URL/repos/$REPO_OWNER/$REPO_NAME/pulls/$NGINX_PR_NUM.diff") if echo "$DIFF" | grep -q "nginx:1.29.3"; then echo "Content Verification: Nginx version update found in diff." else echo "Content Verification Failed: Nginx version update NOT found in diff." exit 1 fi else echo "API Verification Failed: Nginx PR not found." exit 1 fi # Verify Actions/Checkout PR ACTIONS_PR_NUM=$(echo "$PRS" | jq -r '.[] | select(.title | contains("Update actions/checkout action")) | .number') if [ -n "$ACTIONS_PR_NUM" ] && [ "$ACTIONS_PR_NUM" != "null" ]; then echo "API Verification: Actions/Checkout PR found (#$ACTIONS_PR_NUM)." # Verify Content DIFF=$(curl -s -H "Authorization: token $RENOVATE_TOKEN" "$GITEA_API_URL/repos/$REPO_OWNER/$REPO_NAME/pulls/$ACTIONS_PR_NUM.diff") if echo "$DIFF" | grep -q "actions/checkout@v6"; then echo "Content Verification: Actions/Checkout version update found in diff." else echo "Content Verification Failed: Actions/Checkout version update NOT found in diff." exit 1 fi else echo "API Verification Failed: Actions/Checkout PR not found." exit 1 fi echo "API & Content Verification passed!"