updated deployment route error handling #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Trigger Deployment | |
| # This workflow triggers a webhook that your instance listens for | |
| # The instance will then pull the latest code and rebuild | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - dev | |
| jobs: | |
| notify: | |
| runs-on: ubuntu-latest | |
| # Determine environment based on branch | |
| environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} | |
| steps: | |
| - name: Trigger deployment webhook | |
| run: | | |
| ENVIRONMENT="${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}" | |
| WEBHOOK_URL="${{ secrets.WEBHOOK_URL }}" | |
| WEBHOOK_SECRET="${{ secrets.WEBHOOK_SECRET }}" | |
| # Validate secrets are configured | |
| if [ -z "$WEBHOOK_URL" ]; then | |
| echo "Error: WEBHOOK_URL secret is not configured for $ENVIRONMENT environment" | |
| echo "Please configure it in: Repository Settings → Environments → $ENVIRONMENT → Secrets" | |
| exit 1 | |
| fi | |
| if [ -z "$WEBHOOK_SECRET" ]; then | |
| echo "Error: WEBHOOK_SECRET secret is not configured for $ENVIRONMENT environment" | |
| echo "Please configure it in: Repository Settings → Environments → $ENVIRONMENT → Secrets" | |
| exit 1 | |
| fi | |
| echo "Triggering deployment webhook for $ENVIRONMENT..." | |
| echo "Webhook URL: $WEBHOOK_URL" | |
| # Create payload | |
| PAYLOAD=$(cat <<EOF | |
| { | |
| "ref": "${{ github.ref }}", | |
| "branch": "${{ github.ref_name }}", | |
| "commit": "${{ github.sha }}", | |
| "environment": "$ENVIRONMENT", | |
| "repository": "${{ github.repository }}" | |
| } | |
| EOF | |
| ) | |
| # Send webhook with secret for authentication | |
| curl -X POST "$WEBHOOK_URL" \ | |
| -H "Content-Type: application/json" \ | |
| -H "X-GitHub-Event: push" \ | |
| -H "X-Webhook-Secret: $WEBHOOK_SECRET" \ | |
| -d "$PAYLOAD" \ | |
| --fail --show-error \ | |
| -w "\nHTTP Status: %{http_code}\n" | |
| echo "Deployment webhook triggered successfully for $ENVIRONMENT" |