20
20
PR_NUMBER : ${{ github.event.pull_request.number || github.event.issue.number }}
21
21
22
22
jobs :
23
- process-command :
23
+ Process-Deployment-Command :
24
24
if : |
25
25
github.event_name == 'pull_request' ||
26
26
(github.event_name == 'issue_comment' &&
27
27
(github.event.comment.body == '/deploy-review-app' ||
28
- github.event.comment.body == '/delete-app') &&
28
+ github.event.comment.body == '/delete-review- app') &&
29
29
github.event.issue.pull_request)
30
30
runs-on : ubuntu-latest
31
31
permissions :
@@ -35,10 +35,19 @@ jobs:
35
35
issues : write
36
36
37
37
steps :
38
+ - name : Get PR HEAD Ref
39
+ if : github.event_name == 'issue_comment'
40
+ id : getRef
41
+ run : |
42
+ echo "PR_REF=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT
43
+ echo "PR_SHA=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefOid | jq -r '.headRefOid')" >> $GITHUB_OUTPUT
44
+ env :
45
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
46
+
38
47
- name : Determine Action
39
48
id : determine_action
40
49
run : |
41
- if [[ "${{ github.event.comment.body }}" == "/delete-app" ]]; then
50
+ if [[ "${{ github.event.comment.body }}" == "/delete-review- app" ]]; then
42
51
echo "action=delete" >> $GITHUB_OUTPUT
43
52
else
44
53
echo "action=deploy" >> $GITHUB_OUTPUT
83
92
script : |
84
93
const success = '${{ steps.delete.outcome }}' === 'success';
85
94
const message = success
86
- ? '✅ App deletion successful '
87
- : '❌ App deletion failed';
95
+ ? '✅ Review app successfully deleted '
96
+ : '❌ Review app deletion failed';
88
97
89
98
await github.rest.issues.updateComment({
90
99
owner: context.repo.owner,
@@ -93,74 +102,46 @@ jobs:
93
102
body: message
94
103
});
95
104
96
- # Deploy Steps (existing steps)
97
- - name : Get PR HEAD Ref
98
- if : steps.determine_action.outputs.action == 'deploy'
99
- id : getRef
100
- run : |
101
- echo "PR_REF=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT
102
- env :
103
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
104
-
105
- - uses : actions/checkout@v4
106
- with :
107
- fetch-depth : 0
108
- ref : ${{ steps.getRef.outputs.PR_REF || github.ref }}
109
-
105
+ # Deploy Steps
110
106
- name : Initialize Deployment
107
+ if : steps.determine_action.outputs.action == 'deploy'
111
108
id : init-deployment
112
109
uses : actions/github-script@v7
113
110
with :
114
111
script : |
115
- // Helper functions
112
+ const prNumber = process.env.PR_NUMBER;
116
113
const getWorkflowUrl = (runId) =>
117
114
`${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
118
-
119
- const getJobUrl = (runId, jobId, prNumber) =>
120
- `${getWorkflowUrl(runId)}/job/${jobId}?pr=${prNumber}`;
121
115
122
- // Get PR number consistently
123
- const prNumber = process.env.PR_NUMBER ;
116
+ const getJobUrl = (runId, jobId, prNumber) =>
117
+ `${ process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/job/${jobId}?pr=${prNumber}` ;
124
118
125
- // Create GitHub deployment
119
+ // Create deployment
126
120
const deployment = await github.rest.repos.createDeployment({
127
121
owner: context.repo.owner,
128
122
repo: context.repo.repo,
129
123
ref: context.sha,
130
- environment: 'review-app' ,
124
+ environment: 'review-' + prNumber ,
131
125
auto_merge: false,
132
126
required_contexts: []
133
127
});
134
128
135
- // Get the job ID
129
+ // Get job URL
136
130
const jobs = await github.rest.actions.listJobsForWorkflowRun({
137
131
owner: context.repo.owner,
138
132
repo: context.repo.repo,
139
133
run_id: context.runId
140
134
});
141
135
142
- const jobId = jobs.data.jobs.find(job => job.name === 'process-command ')?.id;
136
+ const jobId = jobs.data.jobs.find(job => job.name === 'Process-Deployment-Command ')?.id;
143
137
const jobUrl = getJobUrl(context.runId, jobId, prNumber);
144
138
145
139
// Create initial comment
146
140
const comment = await github.rest.issues.createComment({
147
141
issue_number: prNumber,
148
142
owner: context.repo.owner,
149
143
repo: context.repo.repo,
150
- body: [
151
- '🚀 Starting deployment for PR ' + prNumber,
152
- '',
153
- '[View Deployment Log](' + jobUrl + ')'
154
- ].join('\n')
155
- });
156
-
157
- // Set deployment status to in_progress
158
- await github.rest.repos.createDeploymentStatus({
159
- owner: context.repo.owner,
160
- repo: context.repo.repo,
161
- deployment_id: deployment.data.id,
162
- state: 'in_progress',
163
- description: 'Deployment is in progress'
144
+ body: '🚀 Deploying to Control Plane...\n\n[View Deployment Progress](' + jobUrl + ')'
164
145
});
165
146
166
147
return {
@@ -169,35 +150,23 @@ jobs:
169
150
workflowUrl: getWorkflowUrl(context.runId)
170
151
};
171
152
172
- - name : Setup cpflow app
173
- run : |
174
- set -e
175
-
176
- # Validate required environment variables
177
- : "${APP_NAME:?APP_NAME environment variable is required}"
178
-
179
- if ! cpflow exists -a ${{ env.APP_NAME }} ; then
180
- echo "🔧 Setting up new application: ${{ env.APP_NAME }}"
181
- if ! cpflow setup-app -a ${{ env.APP_NAME }}; then
182
- echo "❌ Failed to setup application"
183
- exit 1
184
- fi
185
- echo "✅ Application setup complete"
186
- fi
153
+ - name : Build Docker Image
154
+ if : steps.determine_action.outputs.action == 'deploy'
155
+ uses : ./.github/actions/build-docker-image
156
+ with :
157
+ github_token : ${{ secrets.GITHUB_TOKEN }}
187
158
188
159
- name : Deploy to Control Plane
160
+ if : steps.determine_action.outputs.action == 'deploy'
189
161
id : deploy
190
162
uses : ./.github/actions/deploy-to-control-plane
191
- env :
192
- CPLN_TOKEN : ${{ secrets.CPLN_TOKEN_STAGING }}
193
- CPLN_ORG : ${{ secrets.CPLN_ORG_STAGING }}
194
163
with :
195
164
app_name : ${{ env.APP_NAME }}
196
165
org : ${{ env.CPLN_ORG }}
197
166
github_token : ${{ secrets.GITHUB_TOKEN }}
198
167
199
168
- name : Update Status
200
- if : always()
169
+ if : steps.determine_action.outputs.action == 'deploy'
201
170
uses : actions/github-script@v7
202
171
with :
203
172
script : |
@@ -208,6 +177,7 @@ jobs:
208
177
const workflowUrl = result.workflowUrl;
209
178
const railsUrl = '${{ steps.deploy.outputs.rails_url }}';
210
179
const prNumber = process.env.PR_NUMBER;
180
+ const commitSha = '${{ github.event.comment.body && steps.getRef.outputs.PR_SHA || github.sha }}';
211
181
212
182
// Update deployment status
213
183
const deploymentStatus = {
@@ -231,17 +201,17 @@ jobs:
231
201
232
202
// Update the initial comment
233
203
const successMessage = [
234
- '✅ Deployment Successful for PR ' + prNumber ,
204
+ '🚀 Rails App Deployed to Control Plane for Commit ' + commitSha.substring(0, 7) ,
235
205
'',
236
- '🚀 Rails App: [' + railsUrl + '](' + railsUrl + ')',
206
+ '🌐 Rails App: [' + railsUrl + '](' + railsUrl + ')',
237
207
'',
238
208
'[View Workflow Status](' + workflowUrl + ')'
239
209
].join('\n');
240
210
241
211
const failureMessage = [
242
212
'❌ Deployment failed for PR ' + prNumber,
243
213
'',
244
- 'Commit: ' + context.sha .substring(0, 7),
214
+ 'Commit: ' + commitSha .substring(0, 7),
245
215
'',
246
216
'[View Workflow Status](' + workflowUrl + ')'
247
217
].join('\n');
0 commit comments