Excellent catch! You've found the two critical errors.
curl: (3) URL rejected: Malformed input: This is because of the curl command itself. You used both --data and -d. These are aliases for the same option. You must use only one.
{"message":"invalid JSON"}: This is the error from the Render API. Even if the curl command were syntactically correct, the way the IMAGE_NAME variable was injected into the JSON string is fragile and can easily lead to invalid JSON.
The most robust and recommended way to fix this is to use a tool like jq to build the JSON payload safely. This completely avoids any issues with shell quoting.
Here is the corrected, complete workflow that fixes both problems.
Corrected GitHub Actions Workflow
This version correctly builds the JSON payload and uses the right curl syntax.
name: Build, Push & Deploy to Render
on:
# This workflow can only be triggered manually from the Actions tab
workflow_dispatch:
env:
REGISTRY: ghcr.io
# Correctly construct the full image name using the repository owner and name
IMAGE_NAME: ${{ github.repository_owner }}/${{ github.event.repository.name }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
# Grant permissions for the job to push to GitHub Packages
permissions:
contents: read
packages: write
steps:
- name: 🛎️ Checkout repository
uses: actions/checkout@v4
- name: 🔧 Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 🔐 Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🏷️ Extract Docker metadata and define tag
id: meta
uses: docker/metadata-action@v5
with:
# Use the full image name defined in the env
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# Use the short git SHA as the tag. This is unique and traceable.
type=sha,format=short
- name: 📦 Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: 🚀 Deploy to Render and Poll for Success
env:
RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }}
RENDER_SERVICE_ID: ${{ secrets.RENDER_SERVICE_ID }}
# The full, tagged image URL from the metadata step
IMAGE_URL: ${{ steps.meta.outputs.tags }}
run: |
set -euo pipefail # Fail on error
echo "Triggering new deployment on Render for service: $RENDER_SERVICE_ID"
echo "Image URL: $IMAGE_URL"
# --- FIX: Build the JSON payload safely using jq ---
# This avoids all quoting issues and ensures valid JSON.
# -n: creates JSON from scratch
# --arg: passes a shell variable safely into jq
JSON_PAYLOAD=$(jq -n \
--arg imageUrl "$IMAGE_URL" \
'{clearCache: "do_not_clear", imageUrl: $imageUrl}')
echo "Sending payload: $JSON_PAYLOAD"
# --- FIX: Use correct curl syntax (-d or --data, not both) ---
DEPLOY_RESPONSE=$(curl -s -X POST \
"https://api.render.com/v1/services/$RENDER_SERVICE_ID/deploys" \
-H "Authorization: Bearer $RENDER_API_KEY" \
-H "Content-Type: application/json" \
-d "$JSON_PAYLOAD") # Pass the safely constructed JSON
# --- Polling logic remains the same ---
DEPLOY_ID=$(echo "$DEPLOY_RESPONSE" | jq -r '.id')
if [ -z "$DEPLOY_ID" ] || [ "$DEPLOY_ID" = "null" ]; then
echo "❌ Failed to create deployment. API Response:"
echo "$DEPLOY_RESPONSE"
exit 1
fi
echo "✅ Deployment created successfully. Deploy ID: $DEPLOY_ID"
echo "Waiting for deployment to go live..."
TIMEOUT_SECONDS=1800 # 30 minutes
START_TIME=$(date +%s)
while true; do
CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [ "$ELAPSED_TIME" -gt "$TIMEOUT_SECONDS" ]; then
echo "⌛ Timeout reached. Deployment took too long."
exit 1
fi
STATUS_RESPONSE=$(curl -s "https://api.render.com/v1/services/$RENDER_SERVICE_ID/deploys/$DEPLOY_ID" \
-H "Authorization: Bearer $RENDER_API_KEY")
DEPLOY_STATUS=$(echo "$STATUS_RESPONSE" | jq -r '.status')
echo "⏳ Current deploy status: $DEPLOY_STATUS (Elapsed: ${ELAPSED_TIME}s)"
if [ "$DEPLOY_STATUS" = "live" ]; then
echo "🎉 Deployment successful!"
break
elif [[ "$DEPLOY_STATUS" =~ (failed|canceled) ]]; then
echo "❌ Deployment failed with status: $DEPLOY_STATUS"
exit 1
fi
sleep 20
done