Skip to content

Commit c25211f

Browse files
committed
fixes
1 parent 038cf8f commit c25211f

File tree

2 files changed

+35
-45
lines changed

2 files changed

+35
-45
lines changed

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,6 @@ runs:
4646
GITHUB_TOKEN: ${{ inputs.github_token }}
4747
PR_NUMBER: ${{ env.PR_NUMBER }}
4848

49-
- name: Initialize Deployment
50-
id: init-deployment
51-
uses: actions/github-script@v7
52-
with:
53-
script: |
54-
// Create GitHub deployment
55-
const deployment = await github.rest.repos.createDeployment({
56-
owner: context.repo.owner,
57-
repo: context.repo.repo,
58-
ref: context.sha,
59-
environment: 'review-app',
60-
auto_merge: false,
61-
required_contexts: []
62-
});
63-
64-
// Set deployment status to in_progress
65-
await github.rest.repos.createDeploymentStatus({
66-
owner: context.repo.owner,
67-
repo: context.repo.repo,
68-
deployment_id: deployment.data.id,
69-
state: 'in_progress',
70-
description: 'Deployment is in progress'
71-
});
72-
73-
return {
74-
deploymentId: deployment.data.id
75-
};
76-
7749
- name: Build Docker Image
7850
id: build
7951
shell: bash

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

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ jobs:
5353
uses: actions/github-script@v7
5454
with:
5555
script: |
56+
// Helper functions
57+
const getWorkflowUrl = (runId) =>
58+
`${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
59+
60+
const getJobUrl = (runId, jobId, prNumber) =>
61+
`${getWorkflowUrl(runId)}/job/${jobId}?pr=${prNumber}`;
62+
63+
// Get PR number consistently
64+
const prNumber = process.env.PR_NUMBER;
65+
5666
// Create GitHub deployment
5767
const deployment = await github.rest.repos.createDeployment({
5868
owner: context.repo.owner,
@@ -63,25 +73,26 @@ jobs:
6373
required_contexts: []
6474
});
6575
66-
const prNumber = context.issue.number || context.payload.pull_request.number;
67-
68-
// Get the job ID from the workflow run
76+
// Get the job ID
6977
const jobs = await github.rest.actions.listJobsForWorkflowRun({
7078
owner: context.repo.owner,
7179
repo: context.repo.repo,
7280
run_id: context.runId
7381
});
7482
7583
const jobId = jobs.data.jobs.find(job => job.name === 'deploy')?.id;
84+
const jobUrl = getJobUrl(context.runId, jobId, prNumber);
7685
7786
// Create initial comment
7887
const comment = await github.rest.issues.createComment({
7988
issue_number: prNumber,
8089
owner: context.repo.owner,
8190
repo: context.repo.repo,
82-
body: `🚀 Starting deployment for PR ${prNumber}
83-
84-
[View Deployment Log](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${jobId}?pr=${prNumber})`
91+
body: [
92+
'🚀 Starting deployment for PR ' + prNumber,
93+
'',
94+
'[View Deployment Log](' + jobUrl + ')'
95+
].join('\n')
8596
});
8697
8798
// Set deployment status to in_progress
@@ -95,7 +106,8 @@ jobs:
95106
96107
return {
97108
deploymentId: deployment.data.id,
98-
commentId: comment.data.id
109+
commentId: comment.data.id,
110+
workflowUrl: getWorkflowUrl(context.runId)
99111
};
100112
101113
- name: Setup cpflow app
@@ -123,7 +135,9 @@ jobs:
123135
const isSuccess = '${{ job.status }}' === 'success';
124136
const deploymentId = ${{ fromJSON(steps.init-deployment.outputs.result).deploymentId }};
125137
const commentId = ${{ fromJSON(steps.init-deployment.outputs.result).commentId }};
138+
const workflowUrl = ${{ fromJSON(steps.init-deployment.outputs.result).workflowUrl }};
126139
const railsUrl = '${{ steps.deploy.outputs.rails_url }}';
140+
const prNumber = process.env.PR_NUMBER;
127141
128142
// Update deployment status
129143
await github.rest.repos.createDeploymentStatus({
@@ -137,16 +151,20 @@ jobs:
137151
138152
// Update the initial comment
139153
const message = isSuccess
140-
? `✅ Deployment Successful for PR ${context.issue.number}
141-
142-
🚀 Rails App: [${railsUrl}](${railsUrl})
143-
144-
[View Workflow Status](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`
145-
: `❌ Deployment failed for PR ${context.issue.number}
146-
147-
Commit: ${context.sha.substring(0, 7)}
148-
149-
[View Workflow Status](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`;
154+
? [
155+
'✅ Deployment Successful for PR ' + prNumber,
156+
'',
157+
'🚀 Rails App: [' + railsUrl + '](' + railsUrl + ')',
158+
'',
159+
'[View Workflow Status](' + workflowUrl + ')'
160+
].join('\n')
161+
: [
162+
'❌ Deployment failed for PR ' + prNumber,
163+
'',
164+
'Commit: ' + context.sha.substring(0, 7),
165+
'',
166+
'[View Workflow Status](' + workflowUrl + ')'
167+
].join('\n');
150168
151169
await github.rest.issues.updateComment({
152170
owner: context.repo.owner,

0 commit comments

Comments
 (0)