Add onboarding testing for test-renovate workflow
All checks were successful
Test Renovate Config / test-renovate (pull_request) Successful in 1m32s
Test Renovate Config / e2e-renovate (pull_request) Successful in 3m0s

This commit is contained in:
2025-11-22 16:32:19 +01:00
parent 0e8bdec8c2
commit 32124d999f

View File

@@ -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 <<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
# Specific assertions based on the test repo state
# --- 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.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!"