@@ -105,7 +105,7 @@ jobs:
105
105
echo "Outputs Generated: $formatted_matrix"
106
106
echo "matrix=$formatted_matrix" >> $GITHUB_OUTPUT
107
107
108
- build-and- push-image :
108
+ build-push-deploy -image :
109
109
needs : changes
110
110
if : ${{ fromJson(needs.changes.outputs.matrix)[0] != null }}
111
111
runs-on : ubuntu-latest
@@ -168,6 +168,10 @@ jobs:
168
168
uses : docker/metadata-action@v5
169
169
with :
170
170
images : ${{ matrix.image }}
171
+ tags : |
172
+ type=ref,event=branch
173
+ type=ref,event=pr
174
+ type=raw,value=latest,enable={{is_default_branch}}
171
175
172
176
- name : Build and push Docker images for PeerPrep Services
173
177
uses : docker/build-push-action@v6
@@ -182,14 +186,61 @@ jobs:
182
186
cache-from : type=gha
183
187
cache-to : type=gha,mode=max
184
188
189
+ - name : Auth GCloud
190
+ id : gcloud-auth
191
+ uses : google-github-actions/auth@v2
192
+ if : ${{ contains(github.ref, 'main') && github.event.pull_request.title != 'Feedback' }}
193
+ with :
194
+ credentials_json : ' ${{ secrets.GKE_CJSON }}'
195
+ continue-on-error : true
196
+
197
+ - name : Detect GKE Cluster
198
+ id : gcloud-detect-gke
199
+ if : ${{ contains(github.ref, 'main') && github.event.pull_request.title != 'Feedback' }}
200
+ run : |-
201
+ prev_step_success="${{ steps.gcloud-auth.outcome }}"
202
+ if [[ "$prev_step_success" != "success" ]]; then
203
+ echo "is_up=false" >> $GITHUB_OUTPUT
204
+ exit 0
205
+ fi
206
+
207
+ clusters="$(gcloud container clusters list)"
208
+ is_up="$(echo $clusters | grep ${{ secrets.GKE_CLUSTER }})"
209
+ if [[ -z "$is_up" ]]; then
210
+ echo "is_up=false" >> $GITHUB_OUTPUT
211
+ else
212
+ echo "is_up=true" >> $GITHUB_OUTPUT
213
+ fi
214
+
215
+ - name : Get GKE creds
216
+ id : gcloud-get-gke-creds
217
+ uses : google-github-actions/get-gke-credentials@v2
218
+ if : ${{ contains(github.ref, 'main') && github.event.pull_request.title != 'Feedback' && steps.gcloud-detect-gke.outputs.is_up == 'true' }}
219
+ with :
220
+ cluster_name : ${{ secrets.GKE_CLUSTER }}
221
+ location : ${{ secrets.GKE_ZONE }}
222
+
223
+ - name : Deploy to GKE
224
+ id : gcloud-deploy-gke
225
+ if : ${{ contains(github.ref, 'main') && github.event.pull_request.title != 'Feedback' && steps.gcloud-detect-gke.outputs.is_up == 'true' }}
226
+ run : |-
227
+ service="${{ matrix.package }}"
228
+ deployment="frontend"
229
+ if [[ "$service" == "collaboration" ]]; then
230
+ deployment="collab-service"
231
+ elif [[ "$service" != "frontend" ]]; then
232
+ deployment="$service-service"
233
+ fi
234
+ kubectl -n peerprep rollout restart deployment "$deployment"
235
+
185
236
results :
186
237
if : ${{ always() && !github.event.pull_request.draft }}
187
238
runs-on : ubuntu-latest
188
239
name : Final Results
189
- needs : build-and- push-image
240
+ needs : build-push-deploy -image
190
241
steps :
191
242
- run : |
192
- result="${{ needs.build-and- push-image.result }}"
243
+ result="${{ needs.build-push-deploy -image.result }}"
193
244
if [[ $result == "success" || $result == "skipped" ]]; then
194
245
exit 0
195
246
else
0 commit comments