Skip to content

Fix Review App Deletion Workflows #639

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

Merged
merged 10 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
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
cpln_org:
description: 'Organization name'
required: true

runs:
using: "composite"
steps:
- name: Delete Application
shell: bash
run: ${{ github.action_path }}/delete-app.sh
env:
APP_NAME: ${{ inputs.app_name }}
CPLN_ORG: ${{ inputs.cpln_org }}
38 changes: 38 additions & 0 deletions .github/actions/delete-control-plane-app/delete-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/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

printenv

# 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" --org "$CPLN_ORG"; 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" --org "$CPLN_ORG" --force; then
echo "❌ Failed to delete application: $APP_NAME" >&2
exit 1
fi

echo "✅ Successfully deleted application: $APP_NAME"
17 changes: 2 additions & 15 deletions .github/workflows/delete-review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
missing+=("Variable: CPLN_ORG_STAGING")
fi

if [ -z "$"PREFIX" }} ]; then
if [ -z "$PREFIX" ]; then
missing+=("Variable: REVIEW_APP_PREFIX")
fi

Expand Down Expand Up @@ -131,29 +131,16 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo,
body: '🗑️ Starting app deletion...'
body: [
message,
'',
' 🗑️ [View Delete Logs](' + process.env.WORKFLOW_URL + ')',
'',
getConsoleLink(process.env.PR_NUMBER)
].join('\n')
});
return { commentId: comment.data.id };

- name: Delete Review App
uses: ./.github/actions/delete-control-plane-app
with:
app_name: ${{ env.APP_NAME }}
org: ${{ env.CPLN_ORG }}
github_token: ${{ secrets.GITHUB_TOKEN }}
env:
APP_NAME: ${{ env.APP_NAME }}
CPLN_ORG: ${{ secrets.CPLN_ORG }}
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
cpln_org: ${{ vars.CPLN_ORG_STAGING }}

- name: Update Delete Status
if: always()
uses: actions/github-script@v7
with:
script: |
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/nightly-remove-stale-review-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ jobs:
run: |
for pr in $(echo "${{ steps.stale_prs.outputs.result }}" | jq -r '.[]'); do
APP_NAME="qa-react-webpack-rails-tutorial-pr-$pr"
CPLN_ORG=${{ vars.CPLN_ORG_STAGING }}
echo "🗑️ Deleting stale review app for PR #$pr: $APP_NAME"
${{ github.workspace }}/.github/actions/deploy-to-control-plane/scripts/delete-app.sh
${{ github.workspace }}/.github/actions/delete-control-plane-app/delete-app.sh
done
env:
APP_NAME: qa-react-webpack-rails-tutorial-pr-${{ steps.stale_prs.outputs.result }}

- name: Run cleanup-images script
run: |
cpflow cleanup-images -a qa-react-webpack-rails-tutorial -y
Loading