@@ -113,68 +113,24 @@ jobs:
113
113
# Check if app exists and save state
114
114
if ! cpflow exists -a ${{ env.APP_NAME }}; then
115
115
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
116
- exit 0
116
+ echo "Canceling job as review app has not been previously deployed."
117
117
fi
118
118
echo "APP_EXISTS=false" >> $GITHUB_ENV
119
119
else
120
120
echo "APP_EXISTS=true" >> $GITHUB_ENV
121
121
fi
122
122
123
- - name : Validate Deployment Request
124
- id : validate
125
- run : |
126
- # Skip validation if deployment is already disabled
127
- if [[ "${{ env.DO_DEPLOY }}" == "false" ]]; then
128
- echo "Skipping validation - deployment already disabled"
129
- exit 0
130
- fi
131
-
132
- if ! [[ "${{ github.event_name }}" == "workflow_dispatch" || \
133
- "${{ github.event_name }}" == "issue_comment" || \
134
- "${{ github.event_name }}" == "pull_request" || \
135
- "${{ github.event_name }}" == "push" ]]; then
136
- echo "Error: Unsupported event type ${{ github.event_name }}"
137
- exit 1
138
- fi
139
-
140
- # Set DO_DEPLOY based on event type and conditions
141
- if [[ "${{ github.event_name }}" == "pull_request" && \
142
- ("${{ github.event.action }}" == "opened" || \
143
- "${{ github.event.action }}" == "synchronize" || \
144
- "${{ github.event.action }}" == "reopened") ]]; then
145
- echo "DO_DEPLOY=true" >> $GITHUB_ENV
146
- elif [[ "${{ github.event_name }}" == "push" ]]; then
147
- echo "DO_DEPLOY=true" >> $GITHUB_ENV
148
- elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
149
- echo "DO_DEPLOY=true" >> $GITHUB_ENV
150
- elif [[ "${{ github.event_name }}" == "issue_comment" ]]; then
151
- if [[ "${{ github.event.issue.pull_request }}" ]]; then
152
- # Trim spaces and check for exact command
153
- COMMENT_BODY=$(echo "${{ github.event.comment.body }}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
154
- if [[ "$COMMENT_BODY" == "/deploy-review-app" ]]; then
155
- echo "DO_DEPLOY=true" >> $GITHUB_ENV
156
- else
157
- echo "DO_DEPLOY=false" >> $GITHUB_ENV
158
- echo "Skipping deployment - comment '$COMMENT_BODY' does not match '/deploy-review-app'"
159
- fi
160
- else
161
- echo "DO_DEPLOY=false" >> $GITHUB_ENV
162
- echo "Skipping deployment for non-PR comment"
163
- fi
164
- fi
165
- if [[ "${{ env.DO_DEPLOY }}" == "false" ]]; then
166
- exit 0
167
- fi
168
-
169
123
- name : Setup Control Plane App if Not Existing
170
- if : env.APP_EXISTS == 'false'
124
+ if : env.APP_EXISTS == 'false' && github.event_name != 'pull_request'
171
125
env :
172
126
CPLN_TOKEN : ${{ secrets.CPLN_TOKEN_STAGING }}
173
127
run : |
174
128
echo "🔧 Setting up new Control Plane app..."
175
129
cpflow setup-app -a ${{ env.APP_NAME }} --org ${{ vars.CPLN_ORG_STAGING }}
130
+ echo "APP_EXISTS=true" >> $GITHUB_ENV
176
131
177
132
- name : Create Initial Comment
133
+ if : env.APP_EXISTS == 'true'
178
134
uses : actions/github-script@v7
179
135
id : create-comment
180
136
with :
@@ -188,6 +144,7 @@ jobs:
188
144
core.setOutput('comment-id', result.data.id);
189
145
190
146
- name : Set Deployment URLs
147
+ if : env.APP_EXISTS == 'true'
191
148
id : set-urls
192
149
uses : actions/github-script@v7
193
150
with :
@@ -219,6 +176,7 @@ jobs:
219
176
);
220
177
221
178
- name : Initialize GitHub Deployment
179
+ if : env.APP_EXISTS == 'true'
222
180
uses : actions/github-script@v7
223
181
id : init-deployment
224
182
with :
@@ -248,6 +206,7 @@ jobs:
248
206
return deployment.data.id;
249
207
250
208
- name : Update Status - Building
209
+ if : env.APP_EXISTS == 'true'
251
210
uses : actions/github-script@v7
252
211
with :
253
212
script : |
@@ -267,6 +226,7 @@ jobs:
267
226
});
268
227
269
228
- name : Build Docker Image
229
+ if : env.APP_EXISTS == 'true'
270
230
id : build
271
231
uses : ./.github/actions/build-docker-image
272
232
with :
@@ -276,6 +236,7 @@ jobs:
276
236
PR_NUMBER : ${{ env.PR_NUMBER }}
277
237
278
238
- name : Update Status - Deploying
239
+ if : env.APP_EXISTS == 'true'
279
240
uses : actions/github-script@v7
280
241
with :
281
242
script : |
@@ -297,13 +258,16 @@ jobs:
297
258
});
298
259
299
260
- name : Deploy to Control Plane
261
+ if : env.APP_EXISTS == 'true'
300
262
run : cpflow deploy-image -a ${{ env.APP_NAME }} --run-release-phase --org ${{ vars.CPLN_ORG_STAGING }} --verbose
301
263
302
264
- name : Retrieve App URL
265
+ if : env.APP_EXISTS == 'true'
303
266
id : workload
304
267
run : echo "WORKLOAD_URL=$(cpln workload get rails --gvc ${{ env.APP_NAME }} | tee | grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' | head -n1)" >> "$GITHUB_OUTPUT"
305
268
306
269
- name : Update Status - Deployment Complete
270
+ if : env.APP_EXISTS == 'true'
307
271
uses : actions/github-script@v7
308
272
with :
309
273
script : |
0 commit comments