1- name : Deploy to Control Plane
1+ name : Deploy Review App to Control Plane
22
33run-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) }}
44
@@ -116,32 +116,11 @@ jobs:
116116 uses : actions/github-script@v7
117117 with :
118118 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-
140119 // Create initial deployment comment
141120 const comment = await github.rest.issues.createComment({
142121 owner: context.repo.owner,
143122 repo: context.repo.repo,
144- issue_number: prNumber ,
123+ issue_number: process.env.PR_NUMBER ,
145124 body: '⏳ Initializing deployment...'
146125 });
147126
@@ -155,14 +134,15 @@ jobs:
155134 required_contexts: []
156135 });
157136
158- const workflowUrl = await getWorkflowUrl(context.runId);
159-
160137 return {
161138 deploymentId: deployment.data.id,
162- commentId: comment.data.id,
163- workflowUrl
139+ commentId: comment.data.id
164140 };
165141
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+
166146 - name : Set commit hash
167147 if : steps.determine_action.outputs.action == 'deploy'
168148 run : |
@@ -180,7 +160,7 @@ jobs:
180160 const buildingMessage = [
181161 '🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + '${{ env.COMMIT_HASH }}',
182162 '',
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}` + ')'
184164 ].join('\n');
185165
186166 await github.rest.issues.updateComment({
@@ -212,7 +192,7 @@ jobs:
212192 '',
213193 '⏳ Waiting for deployment to be ready...',
214194 '',
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}` + ')'
216196 ].join('\n');
217197
218198 await github.rest.issues.updateComment({
@@ -236,10 +216,10 @@ jobs:
236216 uses : actions/github-script@v7
237217 with :
238218 script : |
239- const comment = await github.rest.issues.updateComment({
219+ await github.rest.issues.updateComment({
240220 owner: context.repo.owner,
241221 repo: context.repo.repo,
242- comment_id: steps.init-deployment.outputs.commentId ,
222+ comment_id: process.env.COMMENT_ID ,
243223 body: `🚀 Review App for PR #${process.env.PR_NUMBER}: [\`${process.env.REVIEW_APP_URL}\`](${process.env.REVIEW_APP_URL})`
244224 });
245225
@@ -250,17 +230,14 @@ jobs:
250230 script : |
251231 const prNumber = process.env.PR_NUMBER;
252232 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}` ;
254234 const isSuccess = '${{ job.status }}' === 'success';
255- const result = ${{ steps.init-deployment.outputs.result }};
256- const deploymentId = result.deploymentId;
257- const commentId = result.commentId;
258235
259- // Update deployment status
236+ // Create GitHub deployment status
260237 const deploymentStatus = {
261238 owner: context.repo.owner,
262239 repo: context.repo.repo,
263- deployment_id: deploymentId,
240+ deployment_id: ${{ fromJSON(steps.init-deployment.outputs.result). deploymentId }} ,
264241 state: isSuccess ? 'success' : 'failure',
265242 environment_url: isSuccess ? appUrl : undefined,
266243 log_url: workflowUrl,
@@ -284,10 +261,10 @@ jobs:
284261 '[View Workflow Status](' + workflowUrl + ')'
285262 ].join('\n');
286263
287- // Update the comment with appropriate message
264+ // Update the existing comment
288265 await github.rest.issues.updateComment({
289266 owner: context.repo.owner,
290267 repo: context.repo.repo,
291- comment_id: commentId ,
268+ comment_id: process.env.COMMENT_ID ,
292269 body: isSuccess ? successMessage : failureMessage
293270 });
0 commit comments