2222jobs :
2323 Process-Deployment-Command :
2424 if : |
25- github.event_name == 'pull_request' ||
25+ ( github.event_name == 'pull_request') ||
2626 (github.event_name == 'issue_comment' &&
27- (github.event.comment.body == '/deploy-review-app' ||
28- github.event.comment.body == '/delete-review-app') &&
29- github.event.issue.pull_request)
27+ github.event.issue.pull_request &&
28+ github.event.comment.body == '/deploy')
3029 runs-on : ubuntu-latest
3130 permissions :
3231 contents : read
@@ -46,72 +45,15 @@ jobs:
4645 env :
4746 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4847
49- - name : Determine Action
50- id : determine_action
51- run : |
52- if [[ "${{ github.event.comment.body }}" == "/delete-review-app" ]]; then
53- echo "action=delete" >> $GITHUB_OUTPUT
54- else
55- echo "action=deploy" >> $GITHUB_OUTPUT
56- fi
57-
5848 - uses : actions/checkout@v4
5949 with :
6050 fetch-depth : 0
61- # For PR events: use the head SHA
62- # For PR comments: use the PR head SHA
63- # For other events: use the push SHA
64- ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || steps.getRef.outputs.PR_SHA || github.sha }}
51+ ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || steps.getRef.outputs.PR_REF || github.ref }}
6552
6653 - name : Setup Environment
6754 uses : ./.github/actions/setup-environment
6855
69- # Delete App Steps
70- - name : Create Initial Delete Comment
71- if : steps.determine_action.outputs.action == 'delete'
72- uses : actions/github-script@v7
73- id : init-delete
74- with :
75- script : |
76- const comment = await github.rest.issues.createComment({
77- issue_number: process.env.PR_NUMBER,
78- owner: context.repo.owner,
79- repo: context.repo.repo,
80- body: '🗑️ Starting app deletion...'
81- });
82- return { commentId: comment.data.id };
83-
84- - name : Delete App
85- if : steps.determine_action.outputs.action == 'delete'
86- id : delete
87- run : |
88- echo "🗑️ Deleting review app: $APP_NAME"
89- ${{ github.workspace }}/.github/actions/deploy-to-control-plane/scripts/delete-app.sh
90-
91- - name : Update Delete Status
92- if : steps.determine_action.outputs.action == 'delete'
93- uses : actions/github-script@v7
94- with :
95- script : |
96- const success = '${{ steps.delete.outcome }}' === 'success';
97- const message = success
98- ? [
99- '✅ Review app successfully deleted',
100- '',
101- '⚡ [Control Plane Console](https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/workload)'
102- ].join('\n')
103- : '❌ Review app deletion failed';
104-
105- await github.rest.issues.updateComment({
106- owner: context.repo.owner,
107- repo: context.repo.repo,
108- comment_id: ${{ fromJSON(steps.init-delete.outputs.result).commentId }},
109- body: message
110- });
111-
112- # Deploy Steps
11356 - name : Initialize Deployment
114- if : steps.determine_action.outputs.action == 'deploy'
11557 id : init-deployment
11658 uses : actions/github-script@v7
11759 with :
@@ -162,19 +104,16 @@ jobs:
162104 };
163105
164106 - name : Set comment ID and workflow URL
165- if : steps.determine_action.outputs.action == 'deploy'
166107 run : |
167108 echo "COMMENT_ID=${{ fromJSON(steps.init-deployment.outputs.result).commentId }}" >> $GITHUB_ENV
168109 echo "WORKFLOW_URL=${{ fromJSON(steps.init-deployment.outputs.result).workflowUrl }}" >> $GITHUB_ENV
169110
170111 - name : Set commit hash
171- if : steps.determine_action.outputs.action == 'deploy'
172112 run : |
173113 FULL_COMMIT="${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || steps.getRef.outputs.PR_SHA || github.sha }}"
174114 echo "COMMIT_HASH=${FULL_COMMIT:0:7}" >> $GITHUB_ENV
175115
176116 - name : Update Status - Building
177- if : steps.determine_action.outputs.action == 'deploy'
178117 uses : actions/github-script@v7
179118 with :
180119 script : |
@@ -192,7 +131,6 @@ jobs:
192131 });
193132
194133 - name : Build Docker Image
195- if : steps.determine_action.outputs.action == 'deploy'
196134 uses : ./.github/actions/build-docker-image
197135 with :
198136 app_name : ${{ env.APP_NAME }}
@@ -201,7 +139,6 @@ jobs:
201139 PR_NUMBER : ${{ env.PR_NUMBER }}
202140
203141 - name : Update Status - Deploying
204- if : steps.determine_action.outputs.action == 'deploy'
205142 uses : actions/github-script@v7
206143 with :
207144 script : |
@@ -221,28 +158,13 @@ jobs:
221158 });
222159
223160 - name : Deploy to Control Plane
224- if : steps.determine_action.outputs.action == 'deploy'
225- id : deploy
226161 uses : ./.github/actions/deploy-to-control-plane
227162 with :
228163 app_name : ${{ env.APP_NAME }}
229164 org : ${{ env.CPLN_ORG }}
230165 github_token : ${{ secrets.GITHUB_TOKEN }}
231166
232- - name : Update Status - Success
233- if : steps.determine_action.outputs.action == 'deploy' && success()
234- uses : actions/github-script@v7
235- with :
236- script : |
237- await github.rest.issues.updateComment({
238- owner: context.repo.owner,
239- repo: context.repo.repo,
240- comment_id: process.env.COMMENT_ID,
241- body: `🚀 Review App for PR #${process.env.PR_NUMBER}: [\`${process.env.REVIEW_APP_URL}\`](${process.env.REVIEW_APP_URL})`
242- });
243-
244167 - name : Update Status - Deployment Complete
245- if : steps.determine_action.outputs.action == 'deploy'
246168 uses : actions/github-script@v7
247169 with :
248170 script : |
@@ -268,15 +190,15 @@ jobs:
268190 const successMessage = [
269191 '✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}',
270192 '',
271- '🚀 Review App for PR #' + prNumber + ': [`' + appUrl + '` ](' + appUrl + ')',
193+ '🚀 [ Review App for PR #' + prNumber + '](' + appUrl + ')',
272194 '',
273195 '📋 [View Completed Action Build and Deploy Logs](' + workflowUrl + ')'
274196 ].join('\n');
275197
276198 const failureMessage = [
277- '❌ Deployment failed for PR #' + prNumber,
199+ '❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}' ,
278200 '',
279- '[View Workflow Status ](' + workflowUrl + ')'
201+ '📋 [View Deployment Logs with Errors ](' + workflowUrl + ')'
280202 ].join('\n');
281203
282204 // Update the existing comment
@@ -285,4 +207,4 @@ jobs:
285207 repo: context.repo.repo,
286208 comment_id: process.env.COMMENT_ID,
287209 body: isSuccess ? successMessage : failureMessage
288- });
210+ });
0 commit comments