Skip to content

Commit

Permalink
clean up duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 committed Jan 28, 2025
1 parent ebbc8d8 commit 735e7f6
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 124 deletions.
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
34 changes: 0 additions & 34 deletions .github/actions/deploy-to-control-plane/scripts/get-commit-sha.sh

This file was deleted.

97 changes: 76 additions & 21 deletions .github/workflows/deploy-to-control-plane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ concurrency:
cancel-in-progress: true

env:
APP_NAME: qa-react-webpack-rails-tutorial-pr-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
APP_NAME: ${{ vars.REVIEW_APP_PREFIX }}-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
CPLN_ORG: ${{ vars.CPLN_ORG_STAGING }}
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
Expand Down Expand Up @@ -62,27 +62,61 @@ jobs:
with:
fetch-depth: 0

- name: Validate Required Secrets and Variables
shell: bash
run: |
missing=()
# Check secrets
if [ -z "${{ secrets.CPLN_TOKEN_STAGING }}" ]; then
missing+=("Secret: CPLN_TOKEN_STAGING")
fi
# Check variables
if [ -z "${{ vars.CPLN_ORG_STAGING }}" ]; then
missing+=("Variable: CPLN_ORG_STAGING")
fi
if [ -z "${{ vars.REVIEW_APP_PREFIX }}" ]; then
missing+=("Variable: REVIEW_APP_PREFIX")
fi
if [ ${#missing[@]} -ne 0 ]; then
echo "Required secrets/variables are not set: ${missing[*]}"
exit 1
fi
- name: Get PR HEAD Ref
id: getRef
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
PR_NUMBER="${{ github.event.inputs.pr }}"
elif [[ "${{ github.event_name }}" == "issue_comment" ]]; then
PR_NUMBER="${{ github.event.issue.number }}"
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
PR_NUMBER="${{ github.event.pull_request.number }}"
elif [[ "${{ github.event_name }}" == "push" ]]; then
# For push events, find associated PR
PR_DATA=$(gh pr list --head "${{ github.ref_name }}" --json number --jq '.[0].number')
if [[ -n "$PR_DATA" ]]; then
PR_NUMBER="$PR_DATA"
else
echo "Error: No PR found for branch ${{ github.ref_name }}"
# Get PR number based on event type
case "${{ github.event_name }}" in
"workflow_dispatch")
PR_NUMBER="${{ github.event.inputs.pr_number }}"
;;
"issue_comment")
PR_NUMBER="${{ github.event.issue.number }}"
;;
"pull_request")
PR_NUMBER="${{ github.event.pull_request.number }}"
;;
"push")
# For push events, find associated PR
PR_DATA=$(gh pr list --head "${{ github.ref_name }}" --json number --jq '.[0].number')
if [[ -n "$PR_DATA" ]]; then
PR_NUMBER="$PR_DATA"
else
echo "Error: No PR found for branch ${{ github.ref_name }}"
exit 1
fi
;;
*)
echo "Error: Unsupported event type ${{ github.event_name }}"
exit 1
fi
fi
;;
esac
if [[ -z "$PR_NUMBER" ]]; then
echo "Error: Could not determine PR number"
Expand All @@ -91,7 +125,7 @@ jobs:
# Set environment variables
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-$PR_NUMBER" >> $GITHUB_ENV
echo "APP_NAME=${{ vars.REVIEW_APP_PREFIX }}-$PR_NUMBER" >> $GITHUB_ENV
# Get PR data using GitHub CLI
PR_DATA=$(gh pr view $PR_NUMBER --repo shakacode/react-webpack-rails-tutorial --json headRefName,headRefOid)
Expand Down Expand Up @@ -150,6 +184,7 @@ jobs:
- name: Create Initial Comment
if: env.DO_DEPLOY != 'false'
uses: actions/github-script@v7
id: create-comment
with:
script: |
const result = await github.rest.issues.createComment({
Expand All @@ -160,6 +195,26 @@ jobs:
});
core.setOutput('comment-id', result.data.id);
- name: Update Comment - Building
if: env.DO_DEPLOY != 'false'
uses: actions/github-script@v7
with:
script: |
const buildingMessage = [
`🏗️ Building Docker image for PR #${process.env.PR_NUMBER}, commit ${process.env.PR_SHA}`,
'',
`📝 [View Build Logs](${process.env.WORKFLOW_URL})`,
'',
process.env.CONSOLE_LINK
].join('\n');
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.create-comment.outputs.comment-id }},
body: buildingMessage
});
- name: Set Deployment URLs
id: set-urls
if: env.DO_DEPLOY != 'false'
Expand Down Expand Up @@ -189,7 +244,7 @@ jobs:
with:
script: |
const buildingMessage = [
'🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + '${{ env.COMMIT_HASH }}',
'🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + process.env.PR_SHA,
'',
'📝 [View Build Logs](' + process.env.WORKFLOW_URL + ')',
'',
Expand All @@ -213,7 +268,7 @@ jobs:
with:
app_name: ${{ env.APP_NAME }}
org: ${{ env.CPLN_ORG_STAGING }}
commit: ${{ env.COMMIT_HASH }}
commit: ${{ env.PR_SHA }}
PR_NUMBER: ${{ env.PR_NUMBER }}

- name: Update Status - Deploying
Expand Down Expand Up @@ -276,7 +331,7 @@ jobs:
// Define messages based on deployment status
const successMessage = [
'✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}',
'✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
'',
'🚀 [Review App for PR #' + prNumber + '](' + appUrl + ')',
consoleLink,
Expand All @@ -285,7 +340,7 @@ jobs:
].join('\n');
const failureMessage = [
'❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}',
'❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
'',
consoleLink,
'',
Expand Down

0 comments on commit 735e7f6

Please sign in to comment.