@@ -32,16 +32,80 @@ outputs:
3232runs :
3333 using : " composite"
3434 steps :
35+ - name : Validate Required Secrets
36+ shell : bash
37+ run : |
38+ missing_secrets=()
39+ for secret in "CPLN_TOKEN" "CPLN_ORG"; do
40+ if [ -z "${!secret}" ]; then
41+ missing_secrets+=("$secret")
42+ fi
43+ done
44+
45+ if [ ${#missing_secrets[@]} -ne 0 ]; then
46+ echo "Required secrets are not set: ${missing_secrets[*]}"
47+ exit 1
48+ fi
49+
50+ - name : Setup Environment
51+ uses : ./.github/actions/setup-environment
52+
53+ - name : Get Commit SHA
54+ id : get_sha
55+ shell : bash
56+ run : ${{ github.action_path }}/scripts/get-commit-sha.sh
57+ env :
58+ GITHUB_TOKEN : ${{ inputs.github_token }}
59+ PR_NUMBER : ${{ inputs.pr_number }}
60+
3561 - name : Deploy to Control Plane
3662 id : deploy
3763 shell : bash
3864 env :
39- APP_NAME : ${{ inputs.app_name }}
40- CPLN_ORG : ${{ inputs.org }}
4165 CPLN_TOKEN : ${{ inputs.cpln_token }}
42- WAIT_TIMEOUT : ${{ inputs.wait_timeout }}
66+ PR_NUMBER : ${{ inputs.pr_number }}
4367 run : |
44- # Run the deployment script
45- if ! ${{ github.action_path }}/scripts/deploy.sh; then
68+ echo "🚀 Deploying app for PR #${PR_NUMBER}..."
69+
70+ # Create temp file for output
71+ TEMP_OUTPUT=$(mktemp)
72+ trap 'rm -f "${TEMP_OUTPUT}"' EXIT
73+
74+ # Deploy the application and show output in real-time while capturing it
75+ if ! cpflow deploy-image -a "${{ inputs.app_name }}" --run-release-phase --org "${{ inputs.org }}" 2>&1 | tee "${TEMP_OUTPUT}"; then
76+ echo "❌ Deployment failed for PR #${PR_NUMBER}"
77+ echo "Error output:"
78+ cat "${TEMP_OUTPUT}"
79+ exit 1
80+ fi
81+
82+ # Extract app URL from captured output
83+ REVIEW_APP_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "${TEMP_OUTPUT}" | head -n1)
84+ if [ -z "${REVIEW_APP_URL}" ]; then
85+ echo "❌ Failed to get app URL from deployment output"
86+ echo "Deployment output:"
87+ cat "${TEMP_OUTPUT}"
88+ exit 1
89+ fi
90+
91+ # Wait for all workloads to be ready
92+ WAIT_TIMEOUT=${WAIT_TIMEOUT:-${{ inputs.wait_timeout }}}
93+ echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)..."
94+
95+ # Use timeout command with ps:wait and show output in real-time
96+ if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"${{ inputs.app_name }}\"" 2>&1 | tee -a "${TEMP_OUTPUT}"; then
97+ TIMEOUT_EXIT=$?
98+ if [ ${TIMEOUT_EXIT} -eq 124 ]; then
99+ echo "❌ Timed out waiting for workloads after ${WAIT_TIMEOUT} seconds"
100+ else
101+ echo "❌ Workloads did not become ready for PR #${PR_NUMBER} (exit code: ${TIMEOUT_EXIT})"
102+ fi
103+ echo "Full output:"
104+ cat "${TEMP_OUTPUT}"
46105 exit 1
47106 fi
107+
108+ echo "✅ Deployment successful for PR #${PR_NUMBER}"
109+ echo "🌐 App URL: ${REVIEW_APP_URL}"
110+ echo "review_app_url=${REVIEW_APP_URL}" >> $GITHUB_OUTPUT
111+ echo "REVIEW_APP_URL=${REVIEW_APP_URL}" >> $GITHUB_ENV
0 commit comments