1
- name : Deploy to Control Plane
1
+ name : Deploy Review App to Control Plane
2
2
3
3
run-name : ${{ (github.event_name == 'pull_request' || (github.event_name == 'issue_comment' && github.event.issue.pull_request)) && 'Deploying Review App' || format('Deploying {0} to Staging App', github.ref_name) }}
4
4
@@ -116,32 +116,11 @@ jobs:
116
116
uses : actions/github-script@v7
117
117
with :
118
118
script : |
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}`;
136
- }
137
-
138
- const prNumber = process.env.PR_NUMBER;
139
-
140
119
// Create initial deployment comment
141
120
const comment = await github.rest.issues.createComment({
142
121
owner: context.repo.owner,
143
122
repo: context.repo.repo,
144
- issue_number: prNumber ,
123
+ issue_number: process.env.PR_NUMBER ,
145
124
body: '⏳ Initializing deployment...'
146
125
});
147
126
@@ -155,14 +134,15 @@ jobs:
155
134
required_contexts: []
156
135
});
157
136
158
- const workflowUrl = await getWorkflowUrl(context.runId);
159
-
160
137
return {
161
138
deploymentId: deployment.data.id,
162
- commentId: comment.data.id,
163
- workflowUrl
139
+ commentId: comment.data.id
164
140
};
165
141
142
+ - name : Set comment ID
143
+ if : steps.determine_action.outputs.action == 'deploy'
144
+ run : echo "COMMENT_ID=${{ fromJSON(steps.init-deployment.outputs.result).commentId }}" >> $GITHUB_ENV
145
+
166
146
- name : Set commit hash
167
147
if : steps.determine_action.outputs.action == 'deploy'
168
148
run : |
@@ -180,7 +160,7 @@ jobs:
180
160
const buildingMessage = [
181
161
'🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + '${{ env.COMMIT_HASH }}',
182
162
'',
183
- '[View Build Logs](' + result.workflowUrl + ')'
163
+ '[View Build Logs](' + `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job.id}` + ')'
184
164
].join('\n');
185
165
186
166
await github.rest.issues.updateComment({
@@ -212,7 +192,7 @@ jobs:
212
192
'',
213
193
'⏳ Waiting for deployment to be ready...',
214
194
'',
215
- '[View Deploy Logs](' + result.workflowUrl + ')'
195
+ '[View Deploy Logs](' + `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job.id}` + ')'
216
196
].join('\n');
217
197
218
198
await github.rest.issues.updateComment({
@@ -236,10 +216,10 @@ jobs:
236
216
uses : actions/github-script@v7
237
217
with :
238
218
script : |
239
- const comment = await github.rest.issues.updateComment({
219
+ await github.rest.issues.updateComment({
240
220
owner: context.repo.owner,
241
221
repo: context.repo.repo,
242
- comment_id: steps.init-deployment.outputs.commentId ,
222
+ comment_id: process.env.COMMENT_ID ,
243
223
body: `🚀 Review App for PR #${process.env.PR_NUMBER}: [\`${process.env.REVIEW_APP_URL}\`](${process.env.REVIEW_APP_URL})`
244
224
});
245
225
@@ -250,17 +230,14 @@ jobs:
250
230
script : |
251
231
const prNumber = process.env.PR_NUMBER;
252
232
const appUrl = process.env.REVIEW_APP_URL;
253
- const workflowUrl = steps.init-deployment.outputs.workflowUrl ;
233
+ const workflowUrl = `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job.id}` ;
254
234
const isSuccess = '${{ job.status }}' === 'success';
255
- const result = ${{ steps.init-deployment.outputs.result }};
256
- const deploymentId = result.deploymentId;
257
- const commentId = result.commentId;
258
235
259
- // Update deployment status
236
+ // Create GitHub deployment status
260
237
const deploymentStatus = {
261
238
owner: context.repo.owner,
262
239
repo: context.repo.repo,
263
- deployment_id: deploymentId,
240
+ deployment_id: ${{ fromJSON(steps.init-deployment.outputs.result). deploymentId }} ,
264
241
state: isSuccess ? 'success' : 'failure',
265
242
environment_url: isSuccess ? appUrl : undefined,
266
243
log_url: workflowUrl,
@@ -284,10 +261,10 @@ jobs:
284
261
'[View Workflow Status](' + workflowUrl + ')'
285
262
].join('\n');
286
263
287
- // Update the comment with appropriate message
264
+ // Update the existing comment
288
265
await github.rest.issues.updateComment({
289
266
owner: context.repo.owner,
290
267
repo: context.repo.repo,
291
- comment_id: commentId ,
268
+ comment_id: process.env.COMMENT_ID ,
292
269
body: isSuccess ? successMessage : failureMessage
293
270
});
0 commit comments