@@ -111,74 +111,26 @@ jobs:
111111 fi
112112
113113 # Check if app exists and save state
114- echo "apple"
115- echo "NoBrace: $(cpflow exists -a ${{ env.APP_NAME }})"
116- echo "Brace: $([ cpflow exists -a ${{ env.APP_NAME }} ])"
117114 if ! cpflow exists -a ${{ env.APP_NAME }}; then
118- echo "review app does not exist!"
119115 if [[ "${{ github.event_name }}" == "pull_request" ]]; then
120- echo "Canceling job as review app has not been previously deployed."; sleep inf
116+ echo "Canceling job as review app has not been previously deployed."
121117 fi
122- echo "APP_EXISTS=false"
123118 echo "APP_EXISTS=false" >> $GITHUB_ENV
124- fi
125- echo "bananas"
126-
127- - name : Validate Deployment Request
128- id : validate
129- run : |
130- # Skip validation if deployment is already disabled
131- if [[ "${{ env.DO_DEPLOY }}" == "false" ]]; then
132- echo "Skipping validation - deployment already disabled"
133- exit 0
134- fi
135-
136- if ! [[ "${{ github.event_name }}" == "workflow_dispatch" || \
137- "${{ github.event_name }}" == "issue_comment" || \
138- "${{ github.event_name }}" == "pull_request" || \
139- "${{ github.event_name }}" == "push" ]]; then
140- echo "Error: Unsupported event type ${{ github.event_name }}"
141- exit 1
142- fi
143-
144- # Set DO_DEPLOY based on event type and conditions
145- if [[ "${{ github.event_name }}" == "pull_request" && \
146- ("${{ github.event.action }}" == "opened" || \
147- "${{ github.event.action }}" == "synchronize" || \
148- "${{ github.event.action }}" == "reopened") ]]; then
149- echo "DO_DEPLOY=true" >> $GITHUB_ENV
150- elif [[ "${{ github.event_name }}" == "push" ]]; then
151- echo "DO_DEPLOY=true" >> $GITHUB_ENV
152- elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
153- echo "DO_DEPLOY=true" >> $GITHUB_ENV
154- elif [[ "${{ github.event_name }}" == "issue_comment" ]]; then
155- if [[ "${{ github.event.issue.pull_request }}" ]]; then
156- # Trim spaces and check for exact command
157- COMMENT_BODY=$(echo "${{ github.event.comment.body }}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
158- if [[ "$COMMENT_BODY" == "/deploy-review-app" ]]; then
159- echo "DO_DEPLOY=true" >> $GITHUB_ENV
160- else
161- echo "DO_DEPLOY=false" >> $GITHUB_ENV
162- echo "Skipping deployment - comment '$COMMENT_BODY' does not match '/deploy-review-app'"
163- fi
164- else
165- echo "DO_DEPLOY=false" >> $GITHUB_ENV
166- echo "Skipping deployment for non-PR comment"
167- fi
168- fi
169- if [[ "${{ env.DO_DEPLOY }}" == "false" ]]; then
170- exit 0
119+ else
120+ echo "APP_EXISTS=true" >> $GITHUB_ENV
171121 fi
172122
173123 - name : Setup Control Plane App if Not Existing
174- if : env.APP_EXISTS == 'false'
124+ if : env.APP_EXISTS == 'false' && github.event_name != 'pull_request'
175125 env :
176126 CPLN_TOKEN : ${{ secrets.CPLN_TOKEN_STAGING }}
177127 run : |
178128 echo "🔧 Setting up new Control Plane app..."
179129 cpflow setup-app -a ${{ env.APP_NAME }} --org ${{ vars.CPLN_ORG_STAGING }}
130+ echo "APP_EXISTS=true" >> $GITHUB_ENV
180131
181132 - name : Create Initial Comment
133+ if : env.APP_EXISTS == 'true'
182134 uses : actions/github-script@v7
183135 id : create-comment
184136 with :
@@ -192,6 +144,7 @@ jobs:
192144 core.setOutput('comment-id', result.data.id);
193145
194146 - name : Set Deployment URLs
147+ if : env.APP_EXISTS == 'true'
195148 id : set-urls
196149 uses : actions/github-script@v7
197150 with :
@@ -223,6 +176,7 @@ jobs:
223176 );
224177
225178 - name : Initialize GitHub Deployment
179+ if : env.APP_EXISTS == 'true'
226180 uses : actions/github-script@v7
227181 id : init-deployment
228182 with :
@@ -252,6 +206,7 @@ jobs:
252206 return deployment.data.id;
253207
254208 - name : Update Status - Building
209+ if : env.APP_EXISTS == 'true'
255210 uses : actions/github-script@v7
256211 with :
257212 script : |
@@ -271,6 +226,7 @@ jobs:
271226 });
272227
273228 - name : Build Docker Image
229+ if : env.APP_EXISTS == 'true'
274230 id : build
275231 uses : ./.github/actions/build-docker-image
276232 with :
@@ -280,6 +236,7 @@ jobs:
280236 PR_NUMBER : ${{ env.PR_NUMBER }}
281237
282238 - name : Update Status - Deploying
239+ if : env.APP_EXISTS == 'true'
283240 uses : actions/github-script@v7
284241 with :
285242 script : |
@@ -301,13 +258,16 @@ jobs:
301258 });
302259
303260 - name : Deploy to Control Plane
261+ if : env.APP_EXISTS == 'true'
304262 run : cpflow deploy-image -a ${{ env.APP_NAME }} --run-release-phase --org ${{ vars.CPLN_ORG_STAGING }} --verbose
305263
306264 - name : Retrieve App URL
265+ if : env.APP_EXISTS == 'true'
307266 id : workload
308267 run : echo "WORKLOAD_URL=$(cpln workload get rails --gvc ${{ env.APP_NAME }} | tee | grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' | head -n1)" >> "$GITHUB_OUTPUT"
309268
310269 - name : Update Status - Deployment Complete
270+ if : env.APP_EXISTS == 'true'
311271 uses : actions/github-script@v7
312272 with :
313273 script : |
0 commit comments