Skip to content

Commit bd6386b

Browse files
committed
set and use image tag variables with conditional checks
1 parent 477996f commit bd6386b

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

.github/workflows/gitops-staging.yaml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,15 @@ jobs:
212212
- build-and-deploy-server
213213
- build-and-deploy-dashboard
214214
steps:
215-
- name: Skip if no image tags are available
215+
- name: Set image tag variables
216216
run: |
217-
if [[ -z "${{ needs.build-and-deploy-server.outputs.server-image-tag }}" && -z "${{ needs.build-and-deploy-dashboard.outputs.dashboard-image-tag }}" ]]; then
218-
echo "No image tags available — skipping deployment."
219-
exit 0
220-
fi
221-
echo "Image tags available, proceeding with deployment."
217+
echo "SERVER_IMAGE_TAG=${{ needs.build-and-deploy-server.outputs.server-image-tag }}" >> $GITHUB_ENV
218+
echo "DASHBOARD_IMAGE_TAG=${{ needs.build-and-deploy-dashboard.outputs.dashboard-image-tag }}" >> $GITHUB_ENV
219+
echo "Server image tag: ${{ needs.build-and-deploy-server.outputs.server-image-tag }}"
220+
echo "Dashboard image tag: ${{ needs.build-and-deploy-dashboard.outputs.dashboard-image-tag }}"
222221
223222
- name: Checkout GitOps Repository
223+
if: ${{ env.SERVER_IMAGE_TAG != '' || env.DASHBOARD_IMAGE_TAG != '' }}
224224
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
225225
with:
226226
repository: ${{ env.GITOPS_REPO }}
@@ -229,6 +229,7 @@ jobs:
229229
ref: ${{ env.GITOPS_BRANCH }}
230230

231231
- name: Setup GitOps Branch
232+
if: ${{ env.SERVER_IMAGE_TAG != '' || env.DASHBOARD_IMAGE_TAG != '' }}
232233
run: |
233234
cd gitops-repo
234235
git config --local user.email "action@github.com"
@@ -239,31 +240,34 @@ jobs:
239240
git pull origin ${{ env.GITOPS_BRANCH }}
240241
241242
- name: Update Helm Values for Staging
243+
if: ${{ env.SERVER_IMAGE_TAG != '' || env.DASHBOARD_IMAGE_TAG != '' }}
242244
run: |
243245
# Update server image tag if available
244-
if [[ -n "${{ needs.build-and-deploy-server.outputs.server-image-tag }}" ]]; then
245-
echo "Updating server image tag to: ${{ needs.build-and-deploy-server.outputs.server-image-tag }}"
246-
yq eval ".image.tag = \"${{ needs.build-and-deploy-server.outputs.server-image-tag }}\"" \
246+
if [[ -n "${{ env.SERVER_IMAGE_TAG }}" ]]; then
247+
echo "Updating server image tag to: ${{ env.SERVER_IMAGE_TAG }}"
248+
yq eval ".image.tag = \"${{ env.SERVER_IMAGE_TAG }}\"" \
247249
-i gitops-repo/infra/helm/gram/values-dev.yaml
248250
fi
249251
250252
# Update dashboard image tag if available
251-
if [[ -n "${{ needs.build-and-deploy-dashboard.outputs.dashboard-image-tag }}" ]]; then
252-
echo "Updating dashboard image tag to: ${{ needs.build-and-deploy-dashboard.outputs.dashboard-image-tag }}"
253+
if [[ -n "${{ env.DASHBOARD_IMAGE_TAG }}" ]]; then
254+
echo "Updating dashboard image tag to: ${{ env.DASHBOARD_IMAGE_TAG }}"
253255
if grep -q "dashboard:" gitops-repo/infra/helm/gram/values-dev.yaml; then
254-
yq eval ".dashboard.tag = \"${{ needs.build-and-deploy-dashboard.outputs.dashboard-image-tag }}\"" \
256+
yq eval ".dashboard.tag = \"${{ env.DASHBOARD_IMAGE_TAG }}\"" \
255257
-i gitops-repo/infra/helm/gram/values-dev.yaml
256258
fi
257259
fi
258260
259261
- name: Commit and Push Changes
262+
if: ${{ env.SERVER_IMAGE_TAG != '' || env.DASHBOARD_IMAGE_TAG != '' }}
260263
run: |
261264
cd gitops-repo
262265
git add .
263266
git commit -m "chore: update staging images to ${{ github.sha }}"
264267
git push origin ${{ env.GITOPS_BRANCH }}
265268
266269
- name: Deploy to Staging using Terraform
270+
if: ${{ env.SERVER_IMAGE_TAG != '' || env.DASHBOARD_IMAGE_TAG != '' }}
267271
run: |
268272
cd gitops-repo
269273
@@ -278,8 +282,9 @@ jobs:
278282
mise run deploy:up:k8s dev
279283
280284
- name: Notify Deployment
285+
if: ${{ env.SERVER_IMAGE_TAG != '' || env.DASHBOARD_IMAGE_TAG != '' }}
281286
run: |
282287
echo "🚀 Staging deployment completed!"
283-
echo "Server image: ${{ needs.build-and-deploy-server.outputs.server-image-tag }}"
284-
echo "Dashboard image: ${{ needs.build-and-deploy-dashboard.outputs.dashboard-image-tag }}"
288+
echo "Server image: ${{ env.SERVER_IMAGE_TAG }}"
289+
echo "Dashboard image: ${{ env.DASHBOARD_IMAGE_TAG }}"
285290
echo "Commit: ${{ github.sha }}"

0 commit comments

Comments
 (0)