Skip to content

Commit 5f50639

Browse files
committed
fixes
1 parent 2be9c2f commit 5f50639

File tree

2 files changed

+44
-37
lines changed

2 files changed

+44
-37
lines changed

.github/actions/deploy-to-control-plane/action.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,22 @@ runs:
4141
id: deploy
4242
shell: bash
4343
run: |
44-
echo "🚀 Deploying app for PR #$PR_NUMBER..."
44+
echo "🚀 Deploying app for PR #${PR_NUMBER}..."
4545
4646
# Deploy the application and capture the Rails URL
47-
if ! DEPLOY_OUTPUT=$(cpflow deploy-image -a ${{ inputs.app_name }} --run-release-phase --org ${{ inputs.org }}); then
48-
echo "❌ Deployment failed for PR #$PR_NUMBER"
47+
if ! DEPLOY_OUTPUT=$(cpflow deploy-image -a "${{ inputs.app_name }}" --run-release-phase --org "${{ inputs.org }}" 2>&1); then
48+
echo "❌ Deployment failed for PR #${PR_NUMBER}"
49+
echo "Error output:"
50+
echo "${DEPLOY_OUTPUT}"
4951
exit 1
5052
fi
5153
5254
# Extract Rails URL from deployment output
53-
RAILS_URL=$(echo "$DEPLOY_OUTPUT" | grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' | head -n1)
54-
if [ -z "$RAILS_URL" ]; then
55+
RAILS_URL=$(echo "${DEPLOY_OUTPUT}" | grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' | head -n1)
56+
if [ -z "${RAILS_URL}" ]; then
5557
echo "❌ Failed to get Rails URL from deployment output"
5658
echo "Deployment output:"
57-
echo "$DEPLOY_OUTPUT"
59+
echo "${DEPLOY_OUTPUT}"
5860
exit 1
5961
fi
6062
@@ -63,18 +65,18 @@ runs:
6365
echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)..."
6466
6567
# Use timeout command with ps:wait
66-
if ! timeout $WAIT_TIMEOUT bash -c "cpflow ps:wait -a ${{ inputs.app_name }}"; then
68+
if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"${{ inputs.app_name }}\"" 2>&1; then
6769
TIMEOUT_EXIT=$?
68-
if [ $TIMEOUT_EXIT -eq 124 ]; then
70+
if [ ${TIMEOUT_EXIT} -eq 124 ]; then
6971
echo "❌ Timed out waiting for workloads after ${WAIT_TIMEOUT} seconds"
7072
else
71-
echo "❌ Workloads did not become ready for PR #$PR_NUMBER (exit code: $TIMEOUT_EXIT)"
73+
echo "❌ Workloads did not become ready for PR #${PR_NUMBER} (exit code: ${TIMEOUT_EXIT})"
7274
fi
7375
echo "Last deployment output:"
74-
echo "$DEPLOY_OUTPUT"
76+
echo "${DEPLOY_OUTPUT}"
7577
exit 1
7678
fi
7779
78-
echo "✅ Deployment successful for PR #$PR_NUMBER"
79-
echo "🌐 Rails URL: $RAILS_URL"
80-
echo "rails_url=$RAILS_URL" >> $GITHUB_OUTPUT
80+
echo "✅ Deployment successful for PR #${PR_NUMBER}"
81+
echo "🌐 Rails URL: ${RAILS_URL}"
82+
echo "rails_url=${RAILS_URL}" >> $GITHUB_OUTPUT

.github/workflows/deploy-to-control-plane.yml

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,46 +116,51 @@ jobs:
116116
uses: actions/github-script@v7
117117
with:
118118
script: |
119-
function getWorkflowUrl(runId) {
120-
return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/job/${context.job.id}`;
119+
async function getWorkflowUrl(runId) {
120+
// Get the current job ID
121+
const jobs = await github.rest.actions.listJobsForWorkflowRun({
122+
owner: context.repo.owner,
123+
repo: context.repo.repo,
124+
run_id: runId
125+
});
126+
127+
const currentJob = jobs.data.jobs.find(job => job.status === 'in_progress');
128+
const jobId = currentJob?.id;
129+
130+
if (!jobId) {
131+
console.log('Warning: Could not find current job ID');
132+
return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
133+
}
134+
135+
return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/job/${jobId}`;
121136
}
122137
123138
const prNumber = process.env.PR_NUMBER;
124-
const getJobUrl = (runId, jobId, prNumber) =>
125-
`${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/job/${jobId}?pr=${prNumber}`;
126139
127-
// Create deployment
128-
const deployment = await github.rest.repos.createDeployment({
140+
// Create initial deployment comment
141+
const comment = await github.rest.issues.createComment({
129142
owner: context.repo.owner,
130143
repo: context.repo.repo,
131-
ref: context.sha,
132-
environment: 'review-' + prNumber,
133-
auto_merge: false,
134-
required_contexts: []
144+
issue_number: prNumber,
145+
body: '⏳ Initializing deployment...'
135146
});
136147
137-
// Get job URL
138-
const jobs = await github.rest.actions.listJobsForWorkflowRun({
148+
// Create GitHub deployment
149+
const deployment = await github.rest.repos.createDeployment({
139150
owner: context.repo.owner,
140151
repo: context.repo.repo,
141-
run_id: context.runId
152+
ref: context.sha,
153+
environment: 'review',
154+
auto_merge: false,
155+
required_contexts: []
142156
});
143157
144-
const jobId = jobs.data.jobs.find(job => job.name === 'Process-Deployment-Command')?.id;
145-
const jobUrl = getJobUrl(context.runId, jobId, prNumber);
146-
147-
// Create initial comment
148-
const comment = await github.rest.issues.createComment({
149-
issue_number: prNumber,
150-
owner: context.repo.owner,
151-
repo: context.repo.repo,
152-
body: '🚀 Deploying to Control Plane...\n\n[View Deployment Progress](' + jobUrl + ')'
153-
});
158+
const workflowUrl = await getWorkflowUrl(context.runId);
154159
155160
return {
156161
deploymentId: deployment.data.id,
157162
commentId: comment.data.id,
158-
workflowUrl: getWorkflowUrl(context.runId)
163+
workflowUrl
159164
};
160165
161166
- name: Set commit hash

0 commit comments

Comments
 (0)