22
22
jobs :
23
23
Process-Deployment-Command :
24
24
if : |
25
- github.event_name == 'pull_request' ||
25
+ ( github.event_name == 'pull_request') ||
26
26
(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')
30
29
runs-on : ubuntu-latest
31
30
permissions :
32
31
contents : read
@@ -46,72 +45,15 @@ jobs:
46
45
env :
47
46
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
48
47
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
-
58
48
- uses : actions/checkout@v4
59
49
with :
60
50
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 }}
65
52
66
53
- name : Setup Environment
67
54
uses : ./.github/actions/setup-environment
68
55
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
113
56
- name : Initialize Deployment
114
- if : steps.determine_action.outputs.action == 'deploy'
115
57
id : init-deployment
116
58
uses : actions/github-script@v7
117
59
with :
@@ -162,19 +104,16 @@ jobs:
162
104
};
163
105
164
106
- name : Set comment ID and workflow URL
165
- if : steps.determine_action.outputs.action == 'deploy'
166
107
run : |
167
108
echo "COMMENT_ID=${{ fromJSON(steps.init-deployment.outputs.result).commentId }}" >> $GITHUB_ENV
168
109
echo "WORKFLOW_URL=${{ fromJSON(steps.init-deployment.outputs.result).workflowUrl }}" >> $GITHUB_ENV
169
110
170
111
- name : Set commit hash
171
- if : steps.determine_action.outputs.action == 'deploy'
172
112
run : |
173
113
FULL_COMMIT="${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || steps.getRef.outputs.PR_SHA || github.sha }}"
174
114
echo "COMMIT_HASH=${FULL_COMMIT:0:7}" >> $GITHUB_ENV
175
115
176
116
- name : Update Status - Building
177
- if : steps.determine_action.outputs.action == 'deploy'
178
117
uses : actions/github-script@v7
179
118
with :
180
119
script : |
@@ -192,7 +131,6 @@ jobs:
192
131
});
193
132
194
133
- name : Build Docker Image
195
- if : steps.determine_action.outputs.action == 'deploy'
196
134
uses : ./.github/actions/build-docker-image
197
135
with :
198
136
app_name : ${{ env.APP_NAME }}
@@ -201,7 +139,6 @@ jobs:
201
139
PR_NUMBER : ${{ env.PR_NUMBER }}
202
140
203
141
- name : Update Status - Deploying
204
- if : steps.determine_action.outputs.action == 'deploy'
205
142
uses : actions/github-script@v7
206
143
with :
207
144
script : |
@@ -221,28 +158,13 @@ jobs:
221
158
});
222
159
223
160
- name : Deploy to Control Plane
224
- if : steps.determine_action.outputs.action == 'deploy'
225
- id : deploy
226
161
uses : ./.github/actions/deploy-to-control-plane
227
162
with :
228
163
app_name : ${{ env.APP_NAME }}
229
164
org : ${{ env.CPLN_ORG }}
230
165
github_token : ${{ secrets.GITHUB_TOKEN }}
231
166
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
-
244
167
- name : Update Status - Deployment Complete
245
- if : steps.determine_action.outputs.action == 'deploy'
246
168
uses : actions/github-script@v7
247
169
with :
248
170
script : |
@@ -268,15 +190,15 @@ jobs:
268
190
const successMessage = [
269
191
'✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}',
270
192
'',
271
- '🚀 Review App for PR #' + prNumber + ': [`' + appUrl + '` ](' + appUrl + ')',
193
+ '🚀 [ Review App for PR #' + prNumber + '](' + appUrl + ')',
272
194
'',
273
195
'📋 [View Completed Action Build and Deploy Logs](' + workflowUrl + ')'
274
196
].join('\n');
275
197
276
198
const failureMessage = [
277
- '❌ Deployment failed for PR #' + prNumber,
199
+ '❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}' ,
278
200
'',
279
- '[View Workflow Status ](' + workflowUrl + ')'
201
+ '📋 [View Deployment Logs with Errors ](' + workflowUrl + ')'
280
202
].join('\n');
281
203
282
204
// Update the existing comment
@@ -285,4 +207,4 @@ jobs:
285
207
repo: context.repo.repo,
286
208
comment_id: process.env.COMMENT_ID,
287
209
body: isSuccess ? successMessage : failureMessage
288
- });
210
+ });
0 commit comments