Skip to content

Commit

Permalink
get PR review apps working again (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 authored Jan 29, 2025
1 parent ebbc8d8 commit f0c726f
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .github/actions/delete-control-plane-app/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runs:
steps:
- name: Delete Application
shell: bash
run: ${{ github.action_path }}/../deploy-to-control-plane/scripts/delete-app.sh
run: ${{ github.action_path }}/scripts/delete-app.sh
env:
APP_NAME: ${{ inputs.app_name }}
CPLN_ORG: ${{ inputs.org }}
74 changes: 5 additions & 69 deletions .github/actions/deploy-to-control-plane/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,80 +32,16 @@ outputs:
runs:
using: "composite"
steps:
- name: Validate Required Secrets
shell: bash
run: |
missing_secrets=()
for secret in "CPLN_TOKEN" "CPLN_ORG"; do
if [ -z "${!secret}" ]; then
missing_secrets+=("$secret")
fi
done
if [ ${#missing_secrets[@]} -ne 0 ]; then
echo "Required secrets are not set: ${missing_secrets[*]}"
exit 1
fi
- name: Setup Environment
uses: ./.github/actions/setup-environment

- name: Get Commit SHA
id: get_sha
shell: bash
run: ${{ github.action_path }}/scripts/get-commit-sha.sh
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
PR_NUMBER: ${{ inputs.pr_number }}

- name: Deploy to Control Plane
id: deploy
shell: bash
env:
APP_NAME: ${{ inputs.app_name }}
CPLN_ORG: ${{ inputs.org }}
CPLN_TOKEN: ${{ inputs.cpln_token }}
PR_NUMBER: ${{ inputs.pr_number }}
WAIT_TIMEOUT: ${{ inputs.wait_timeout }}
run: |
echo "🚀 Deploying app for PR #${PR_NUMBER}..."
# Create temp file for output
TEMP_OUTPUT=$(mktemp)
trap 'rm -f "${TEMP_OUTPUT}"' EXIT
# Deploy the application and show output in real-time while capturing it
if ! cpflow deploy-image -a "${{ inputs.app_name }}" --run-release-phase --org "${{ inputs.org }}" 2>&1 | tee "${TEMP_OUTPUT}"; then
echo "❌ Deployment failed for PR #${PR_NUMBER}"
echo "Error output:"
cat "${TEMP_OUTPUT}"
exit 1
fi
# Extract app URL from captured output
REVIEW_APP_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "${TEMP_OUTPUT}" | head -n1)
if [ -z "${REVIEW_APP_URL}" ]; then
echo "❌ Failed to get app URL from deployment output"
echo "Deployment output:"
cat "${TEMP_OUTPUT}"
exit 1
fi
# Wait for all workloads to be ready
WAIT_TIMEOUT=${WAIT_TIMEOUT:-${{ inputs.wait_timeout }}}
echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)..."
# Use timeout command with ps:wait and show output in real-time
if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"${{ inputs.app_name }}\"" 2>&1 | tee -a "${TEMP_OUTPUT}"; then
TIMEOUT_EXIT=$?
if [ ${TIMEOUT_EXIT} -eq 124 ]; then
echo "❌ Timed out waiting for workloads after ${WAIT_TIMEOUT} seconds"
else
echo "❌ Workloads did not become ready for PR #${PR_NUMBER} (exit code: ${TIMEOUT_EXIT})"
fi
echo "Full output:"
cat "${TEMP_OUTPUT}"
# Run the deployment script
if ! ${{ github.action_path }}/scripts/deploy.sh; then
exit 1
fi
echo "✅ Deployment successful for PR #${PR_NUMBER}"
echo "🌐 App URL: ${REVIEW_APP_URL}"
echo "review_app_url=${REVIEW_APP_URL}" >> $GITHUB_OUTPUT
echo "REVIEW_APP_URL=${REVIEW_APP_URL}" >> $GITHUB_ENV
14 changes: 6 additions & 8 deletions .github/actions/deploy-to-control-plane/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Must be a positive integer
#
# Outputs:
# - rails_url: URL of the deployed Rails application
# - ENV APP_URL: URL of the deployed application

set -e

Expand Down Expand Up @@ -39,11 +39,9 @@ if ! timeout "${WAIT_TIMEOUT}" cpflow deploy-image -a "$APP_NAME" --run-release-
fi

# Extract app URL from deployment output
RAILS_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1)
if [ -z "$RAILS_URL" ]; then
echo "❌ Failed to get app URL from deployment output"
echo "Full output:"
cat "$TEMP_OUTPUT"
APP_URL=$(grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1)
if [ -z "$APP_URL" ]; then
echo "❌ Error: Could not find app URL in deployment output"
exit 1
fi

Expand All @@ -62,5 +60,5 @@ if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"$APP_NAME\"" 2>&1 |
fi

echo "✅ Deployment successful"
echo "🌐 Rails URL: $RAILS_URL"
echo "rails_url=$RAILS_URL" >> "$GITHUB_OUTPUT"
echo "🌐 App URL: $APP_URL"
echo "APP_URL=$APP_URL" >> "$GITHUB_OUTPUT"
34 changes: 0 additions & 34 deletions .github/actions/deploy-to-control-plane/scripts/get-commit-sha.sh

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/debug-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Debug Workflow Information

on:
workflow_call:
inputs:
debug_enabled:
required: false
type: boolean
default: false
description: 'Enable debug logging (defaults to false)'

jobs:
debug-info:
runs-on: ubuntu-latest
if: inputs.debug_enabled || vars.DEBUG_WORKFLOW == 'true'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Log Branch Info
run: |
echo "Branch for this run:"
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "Pull Request Source Branch: ${{ github.head_ref }}"
else
echo "Branch: ${{ github.ref_name }}"
fi
- name: Debug GitHub Context
run: |
echo "Event name: ${{ github.event_name }}"
echo "Event path: ${{ github.event_path }}"
echo "Repository: ${{ github.repository }}"
echo "Full GitHub context:"
echo '${{ toJson(github) }}'
4 changes: 4 additions & 0 deletions .github/workflows/delete-review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ env:
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}

jobs:
debug:
uses: ./.github/workflows/debug-workflow.yml
with:
debug_enabled: false # Will still run if vars.DEBUG_WORKFLOW is true
Process-Delete-Command:
if: |
(github.event_name == 'issue_comment' &&
Expand Down
Loading

0 comments on commit f0c726f

Please sign in to comment.