8181 - name : Get PR HEAD Ref
8282 id : getRef
8383 if : |
84- github.event_name == 'issue_comment' ||
84+ (github.event_name == 'issue_comment' &&
85+ github.event.issue.pull_request &&
86+ github.event.comment.body == '/deploy-review-app') ||
8587 (steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
8688 run : |
8789 PR_DATA=$(gh pr view ${{ env.PR_NUMBER }} --repo ${{ github.repository }} --json headRefName,headRefOid)
9092 env :
9193 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9294
95+ - name : Create Initial Comment
96+ if : |
97+ (github.event_name == 'issue_comment' &&
98+ github.event.issue.pull_request &&
99+ github.event.comment.body == '/deploy-review-app') ||
100+ (steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
101+ id : create-comment
102+ uses : actions/github-script@v7
103+ with :
104+ script : |
105+ const result = await github.rest.issues.createComment({
106+ owner: context.repo.owner,
107+ repo: context.repo.repo,
108+ issue_number: process.env.PR_NUMBER,
109+ body: '🚀 Starting deployment process...'
110+ });
111+ console.log('Created comment:', result.data.id);
112+ return { commentId: result.data.id };
113+
114+ - name : Set Comment ID
115+ if : |
116+ (github.event_name == 'issue_comment' &&
117+ github.event.issue.pull_request &&
118+ github.event.comment.body == '/deploy-review-app') ||
119+ (steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
120+ run : echo "COMMENT_ID=${{ fromJSON(steps.create-comment.outputs.result).commentId }}" >> $GITHUB_ENV
121+
122+ - name : Set Workflow URL
123+ if : |
124+ (github.event_name == 'issue_comment' &&
125+ github.event.issue.pull_request &&
126+ github.event.comment.body == '/deploy-review-app') ||
127+ (steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
128+ id : workflow-url
129+ uses : actions/github-script@v7
130+ with :
131+ script : |
132+ async function getWorkflowUrl(runId) {
133+ const jobs = await github.rest.actions.listJobsForWorkflowRun({
134+ owner: context.repo.owner,
135+ repo: context.repo.repo,
136+ run_id: runId
137+ });
138+
139+ const currentJob = jobs.data.jobs.find(job => job.status === 'in_progress');
140+ const jobId = currentJob?.id;
141+
142+ if (!jobId) {
143+ return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
144+ }
145+
146+ return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/job/${jobId}`;
147+ }
148+
149+ const workflowUrl = await getWorkflowUrl(context.runId);
150+ core.exportVariable('WORKFLOW_URL', workflowUrl);
151+ core.exportVariable('GET_CONSOLE_LINK', `
152+ function getConsoleLink(prNumber) {
153+ return '🎮 [Control Plane Console](' +
154+ 'https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/-info)';
155+ }
156+ `);
157+
158+ - name : Update Status - Building
159+ if : |
160+ (github.event_name == 'issue_comment' &&
161+ github.event.issue.pull_request &&
162+ github.event.comment.body == '/deploy-review-app') ||
163+ (steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
164+ uses : actions/github-script@v7
165+ with :
166+ script : |
167+ eval(process.env.GET_CONSOLE_LINK);
168+
169+ const buildingMessage = [
170+ '🏗️ Building Docker image...',
171+ '',
172+ '📝 [View Build Logs](' + process.env.WORKFLOW_URL + ')',
173+ '',
174+ getConsoleLink(process.env.PR_NUMBER)
175+ ].join('\n');
176+
177+ await github.rest.issues.updateComment({
178+ owner: context.repo.owner,
179+ repo: context.repo.repo,
180+ comment_id: process.env.COMMENT_ID,
181+ body: buildingMessage
182+ });
183+
93184 - name : Checkout PR Branch
94185 if : |
95186 (github.event_name == 'issue_comment' &&
@@ -111,6 +202,34 @@ jobs:
111202 commit : ${{ steps.getRef.outputs.PR_SHA }}
112203 PR_NUMBER : ${{ env.PR_NUMBER }}
113204
205+ - name : Update Status - Deploying
206+ if : |
207+ (github.event_name == 'issue_comment' &&
208+ github.event.issue.pull_request &&
209+ github.event.comment.body == '/deploy-review-app') ||
210+ (steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
211+ uses : actions/github-script@v7
212+ with :
213+ script : |
214+ eval(process.env.GET_CONSOLE_LINK);
215+
216+ const deployingMessage = [
217+ '🚀 Deploying to Control Plane...',
218+ '',
219+ '⏳ Waiting for deployment to be ready...',
220+ '',
221+ '📝 [View Deploy Logs](' + process.env.WORKFLOW_URL + ')',
222+ '',
223+ getConsoleLink(process.env.PR_NUMBER)
224+ ].join('\n');
225+
226+ await github.rest.issues.updateComment({
227+ owner: context.repo.owner,
228+ repo: context.repo.repo,
229+ comment_id: process.env.COMMENT_ID,
230+ body: deployingMessage
231+ });
232+
114233 - name : Deploy to Control Plane
115234 if : |
116235 (github.event_name == 'issue_comment' &&
@@ -126,3 +245,27 @@ jobs:
126245 env :
127246 CPLN_TOKEN : ${{ env.CPLN_TOKEN }}
128247 PR_NUMBER : ${{ env.PR_NUMBER }}
248+
249+ - name : Update Status - Success
250+ if : success()
251+ uses : actions/github-script@v7
252+ with :
253+ script : |
254+ eval(process.env.GET_CONSOLE_LINK);
255+
256+ const successMessage = [
257+ '✅ Deployment successful!',
258+ '',
259+ '🌐 Review app is ready at: ${{ env.REVIEW_APP_URL }}',
260+ '',
261+ '📝 [View App Logs](' + process.env.WORKFLOW_URL + ')',
262+ '',
263+ getConsoleLink(process.env.PR_NUMBER)
264+ ].join('\n');
265+
266+ await github.rest.issues.updateComment({
267+ owner: context.repo.owner,
268+ repo: context.repo.repo,
269+ comment_id: process.env.COMMENT_ID,
270+ body: successMessage
271+ });
0 commit comments