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

Revert all recent changes #627

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .controlplane/controlplane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ aliases:
release_script: release_script.sh

apps:
react-webpack-rails-tutorial-production:
react-webpack-rails-tutorial:
# Simulate Production Version
<<: *common
# Don't allow overriding the org and app by ENV vars b/c production is sensitive!
Expand Down
15 changes: 4 additions & 11 deletions .github/actions/build-docker-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ inputs:
required: true
PR_NUMBER:
description: 'PR number'
required: false
required: true

runs:
using: "composite"
Expand All @@ -22,18 +22,11 @@ runs:
id: build
shell: bash
run: |
PR_INFO=""
if [ -n "${PR_NUMBER}" ]; then
PR_INFO=" for PR #${PR_NUMBER}"
fi

echo "🏗️ Building Docker image${PR_INFO} (commit ${{ inputs.commit }})..."
echo "🏗️ Building Docker image for PR #${PR_NUMBER} (commit ${{ inputs.commit }})..."

if cpflow build-image -a "${{ inputs.app_name }}" --commit="${{ inputs.commit }}" --org="${{ inputs.org }}"; then
image_tag="${{ inputs.org }}/${{ inputs.app_name }}:${{ inputs.commit }}"
echo "image_tag=${image_tag}" >> $GITHUB_OUTPUT
echo "✅ Docker image build successful${PR_INFO} (commit ${{ inputs.commit }})"
echo "✅ Docker image build successful for PR #${PR_NUMBER} (commit ${{ inputs.commit }})"
else
echo "❌ Docker image build failed${PR_INFO} (commit ${{ inputs.commit }})"
echo "❌ Docker image build failed for PR #${PR_NUMBER} (commit ${{ inputs.commit }})"
exit 1
fi
20 changes: 20 additions & 0 deletions .github/actions/delete-control-plane-app/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Delete Control Plane App
description: 'Deletes a Control Plane application and all its resources'

inputs:
app_name:
description: 'Name of the application to delete'
required: true
org:
description: 'Organization name'
required: true

runs:
using: "composite"
steps:
- name: Delete Application
shell: bash
run: ${{ github.action_path }}/../deploy-to-control-plane/scripts/delete-app.sh
env:
APP_NAME: ${{ inputs.app_name }}
CPLN_ORG: ${{ inputs.org }}
70 changes: 57 additions & 13 deletions .github/actions/deploy-to-control-plane/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ inputs:
description: 'Timeout in seconds for waiting for workloads to be ready'
required: false
default: '900'
cpln_token:
description: 'Control Plane token'
required: true
pr_number:
description: 'Pull Request number'
required: true

outputs:
review_app_url:
Expand All @@ -32,16 +26,66 @@ outputs:
runs:
using: "composite"
steps:
- 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: ${{ env.PR_NUMBER }}

Comment on lines +29 to +39
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Revert Added Environment Setup and Commit SHA Steps
Additional steps have been added for setting up the environment and retrieving the commit SHA (via get-commit-sha.sh). As the intent is to revert recent changes, remove these steps and restore the original inputs and workflow logic.

- name: Deploy to Control Plane
id: deploy
shell: bash
env:
APP_NAME: ${{ inputs.app_name }}
CPLN_ORG: ${{ inputs.org }}
CPLN_TOKEN: ${{ inputs.cpln_token }}
WAIT_TIMEOUT: ${{ inputs.wait_timeout }}
run: |
# Run the deployment script
if ! ${{ github.action_path }}/scripts/deploy.sh; then
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 }}}
if ! [[ "${WAIT_TIMEOUT}" =~ ^[0-9]+$ ]]; then
echo "❌ Invalid timeout value: ${WAIT_TIMEOUT}"
exit 1
fi
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}"
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: 36 additions & 0 deletions .github/actions/deploy-to-control-plane/scripts/delete-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Script to delete a Control Plane application
# Required environment variables:
# - APP_NAME: Name of the application to delete
# - CPLN_ORG: Organization name

set -e

# Validate required environment variables
: "${APP_NAME:?APP_NAME environment variable is required}"
: "${CPLN_ORG:?CPLN_ORG environment variable is required}"

# Safety check: prevent deletion of production or staging apps
if echo "$APP_NAME" | grep -iqE '(production|staging)'; then
echo "❌ ERROR: Cannot delete apps containing 'production' or 'staging' in their name" >&2
echo "🛑 This is a safety measure to prevent accidental deletion of production or staging environments" >&2
echo " App name: $APP_NAME" >&2
exit 1
fi

# Check if app exists before attempting to delete
echo "🔍 Checking if application exists: $APP_NAME"
if ! cpflow exists -a "$APP_NAME"; then
echo "⚠️ Application does not exist: $APP_NAME"
exit 0
fi

# Delete the application
echo "🗑️ Deleting application: $APP_NAME"
if ! cpflow delete -a "$APP_NAME" --force; then
echo "❌ Failed to delete application: $APP_NAME" >&2
exit 1
fi

echo "✅ Successfully deleted application: $APP_NAME"
51 changes: 19 additions & 32 deletions .github/actions/deploy-to-control-plane/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# This script handles the deployment to Control Plane and extracts the Rails URL
#
#
# Required environment variables:
# - APP_NAME: Name of the application to deploy
# - CPLN_ORG: Control Plane organization
Expand All @@ -11,7 +11,7 @@
# Must be a positive integer
#
# Outputs:
# - ENV APP_URL: URL of the deployed application
# - rails_url: URL of the deployed Rails application

set -e

Expand All @@ -31,34 +31,21 @@ trap 'rm -f "$TEMP_OUTPUT"' EXIT

# Deploy the application
echo "🚀 Deploying to Control Plane (timeout: ${WAIT_TIMEOUT}s)"
if ! timeout "${WAIT_TIMEOUT}" cpflow deploy-image -a "$APP_NAME" --run-release-phase --org "$CPLN_ORG" --verbose 2>&1 | tee "$TEMP_OUTPUT"; then
echo "❌ Deployment failed"
echo "Full output:"
cat "$TEMP_OUTPUT"
exit 1
fi

# Extract app URL from deployment 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
if timeout "$WAIT_TIMEOUT" cpflow deploy-image -a "$APP_NAME" --run-release-phase --org "$CPLN_ORG" --verbose | tee "$TEMP_OUTPUT"; then
# Extract Rails URL from deployment output
RAILS_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1)
if [ -n "$RAILS_URL" ]; then
echo "rails_url=$RAILS_URL" >> "$GITHUB_OUTPUT"
echo "✅ Deployment successful"
echo "🚀 Rails URL: $RAILS_URL"
else
echo "❌ Failed to extract Rails URL from deployment output"
exit 1
fi
elif [ $? -eq 124 ]; then
echo "❌ Deployment timed out after $WAIT_TIMEOUT seconds"
exit 1
else
echo "❌ Deployment to Control Plane failed"
exit 1
fi
Comment on lines 33 to 51
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Revert Deployment Logic Changes
The deployment script now implements updated logic for extracting the Rails URL (using a modified regex and dedicated timeout handling). As the PR objective is to revert recent changes, please restore the original deployment logic and error handling. In other words, undo the changes that introduced the Rails-specific URL extraction and the modified “timeout” handling.


I'll start by verifying whether the updated Rails URL extraction logic is present in the deployment script. This will confirm that the new changes (and thus the revert request) are indeed applied. Here’s a shell script to check for the regex used to extract the Rails URL:

Once the results confirm that the extraction logic using the modified regex is present in the file, you can be sure that the deployment script includes the changes that the PR is intended to revert.


🏁 Script executed:

#!/bin/bash
# Verify if the updated Rails URL extraction logic is present in the deployment script.
grep -n "grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\\s|$)'" .github/actions/deploy-to-control-plane/scripts/deploy.sh

Length of output: 255


Below is a revised review comment. Since the initial search for the modified Rails URL extraction logic did not return any output, I'm asking for manual re‑verification to confirm whether the new code is present or if the changes have already been reverted.

Action Required:

  • Verify manually: Please inspect .github/actions/deploy-to-control-plane/scripts/deploy.sh to confirm whether the new Rails URL extraction logic (i.e. the modified grep -oP regex) and updated timeout handling are still present.
  • Revert if necessary: If these changes are detected, revert them so that the script restores the original deployment logic and error handling, per the PR objective.

🏁 Script executed:

#!/bin/bash
echo "Searching for updated Rails URL extraction logic in deploy.sh..."
rg "grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\\s|$)'" .github/actions/deploy-to-control-plane/scripts/deploy.sh

echo "Searching for the cpflow deploy-image and timeout handling block..."
rg "timeout .* cpflow deploy-image" .github/actions/deploy-to-control-plane/scripts/deploy.sh

Length of output: 1076


Action Required: Revert Updated Deployment Logic Changes
Our investigation indicates that the deployment script still contains the updated logic for timeout handling—as evidenced by the presence of the cpflow deploy-image command wrapped with the timeout—and likely retains the new Rails URL extraction via the modified grep command (despite regex tool limitations affecting our automated search). Please review the file at .github/actions/deploy-to-control-plane/scripts/deploy.sh (lines 33–51) and revert the following changes:

  • Rails URL Extraction: Undo the changes that replace the original URL extraction logic with the modified regex using grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)'.
  • Timeout Handling: Restore the previous timeout handling behavior by removing the updated cpflow command (with its new flags/options) if it does not conform to the original implementation.

Manual verification is advised to confirm that the updated logic is effectively reverted.


# Wait for all workloads to be ready
echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)"
if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"$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"
fi
echo "Full output:"
cat "$TEMP_OUTPUT"
exit 1
fi

echo "✅ Deployment successful"
echo "🌐 App URL: $APP_URL"
echo "APP_URL=$APP_URL" >> "$GITHUB_OUTPUT"
34 changes: 34 additions & 0 deletions .github/actions/deploy-to-control-plane/scripts/get-commit-sha.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# This script retrieves the commit SHA for deployment
# It handles both PR and direct branch deployments
#
# Required environment variables:
# - PR_NUMBER: Pull request number (optional)
# - GITHUB_TOKEN: GitHub token for API access
#
# Outputs:
# - sha: Full commit SHA
# - sha_short: Short (7 char) commit SHA

set -e

if [ -n "${PR_NUMBER}" ]; then
# If PR_NUMBER is set, get the PR's head SHA
if ! PR_SHA=$(gh pr view "${PR_NUMBER}" --json headRefOid --jq '.headRefOid'); then
echo "Failed to get PR head SHA" >&2
exit 1
fi
echo "sha=${PR_SHA}" >> "$GITHUB_OUTPUT"
echo "sha_short=${PR_SHA:0:7}" >> "$GITHUB_OUTPUT"
echo "Using PR head commit SHA: ${PR_SHA:0:7}"
else
# For direct branch deployments, use the current commit SHA
if ! CURRENT_SHA=$(git rev-parse HEAD); then
echo "Failed to get current SHA" >&2
exit 1
fi
echo "sha=${CURRENT_SHA}" >> "$GITHUB_OUTPUT"
echo "sha_short=${CURRENT_SHA:0:7}" >> "$GITHUB_OUTPUT"
echo "Using branch commit SHA: ${CURRENT_SHA:0:7}"
fi
27 changes: 8 additions & 19 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
name: 'Setup Environment'
description: 'Sets up Ruby, installs Control Plane CLI, cpflow gem, and sets up the default profile'

inputs:
token:
description: 'Control Plane token'
required: true
org:
description: 'Control Plane organization'
required: true

runs:
using: 'composite'
steps:
Expand All @@ -22,30 +14,27 @@ runs:
- name: Install Control Plane CLI and cpflow gem
shell: bash
run: |
sudo npm install -g @controlplane/[email protected].1
sudo npm install -g @controlplane/[email protected].0
cpln --version
gem install cpflow -v 4.1.0
cpflow --version

- name: Setup Control Plane Profile
shell: bash
run: |
TOKEN="${{ inputs.token }}"
ORG="${{ inputs.org }}"

if [ -z "$TOKEN" ]; then
echo " Error: Control Plane token not provided"
if [ -z "$CPLN_TOKEN" ]; then
echo " Error: CPLN_TOKEN environment variable is not set"
exit 1
fi

if [ -z "$ORG" ]; then
echo " Error: Control Plane organization not provided"
if [ -z "$CPLN_ORG" ]; then
echo " Error: CPLN_ORG environment variable is not set"
exit 1
fi

echo "Setting up Control Plane profile..."
echo "Organization: $ORG"
cpln profile update default --org "$ORG" --token "$TOKEN"
echo "Organization: $CPLN_ORG"
cpln profile update default --org "$CPLN_ORG" --token "$CPLN_TOKEN"

echo "Setting up Docker login for Control Plane registry..."
cpln image docker-login --org "$ORG"
cpln image docker-login --org "$CPLN_ORG"
28 changes: 0 additions & 28 deletions .github/actions/validate-required-vars/action.yml

This file was deleted.

Loading
Loading