Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get PR review apps working again #623

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
36 changes: 0 additions & 36 deletions .github/actions/deploy-to-control-plane/scripts/delete-app.sh

This file was deleted.

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
Comment on lines +21 to +28
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Address potential security risk in branch info logging.

The direct use of github.head_ref in shell scripts poses a security risk. GitHub recommends passing such values through environment variables.

Apply this diff to fix the security concern:

       - name: Log Branch Info
         run: |
+          # Set branch ref through environment variables
+          echo "HEAD_REF=${{ github.head_ref }}" >> $GITHUB_ENV
+          echo "REF_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
+
           echo "Branch for this run:"
           if [ "${{ github.event_name }}" == "pull_request" ]; then
-            echo "Pull Request Source Branch: ${{ github.head_ref }}"
+            echo "Pull Request Source Branch: $HEAD_REF"
           else
-            echo "Branch: ${{ github.ref_name }}"
+            echo "Branch: $REF_NAME"
           fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- 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: Log Branch Info
run: |
# Set branch ref through environment variables
echo "HEAD_REF=${{ github.head_ref }}" >> $GITHUB_ENV
echo "REF_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
echo "Branch for this run:"
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "Pull Request Source Branch: $HEAD_REF"
else
echo "Branch: $REF_NAME"
fi
🧰 Tools
🪛 actionlint (1.7.4)

22-22: "github.head_ref" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions for more details

(expression)


- 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) }}'
Loading
Loading