From 1be991a8c15811f473514ee96377a00f7d5010f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20=C5=81opatowski?=
 <lukasz.lopatowski@gmail.com>
Date: Mon, 11 Mar 2024 16:26:46 +0100
Subject: [PATCH] Enhanced CI actions to build docker image with appropriate
 tag

---
 .github/workflows/01-build-docker-image.yml | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/01-build-docker-image.yml b/.github/workflows/01-build-docker-image.yml
index 8e450b0..1744904 100644
--- a/.github/workflows/01-build-docker-image.yml
+++ b/.github/workflows/01-build-docker-image.yml
@@ -1,14 +1,28 @@
-name: Build docker image with tag latest
+name: Build docker image with appropriate tag
 
 on:
   push:
     branches:
       - develop
+  release:
+    types: [released]
 
 jobs:
   build_docker_image:
     runs-on: ubuntu-22.04
     steps:
+      - name: Determine Docker Tag
+        id: docker_tag
+        run: |
+          GIT_EVENT=${{ github.event_name }}
+          GIT_BRANCH_NAME=${GITHUB_REF##*/}
+          if [[ $GIT_EVENT == 'push' && $GIT_BRANCH_NAME == 'develop' ]]; then
+            echo "DOCKER_TAG=latest" >> $GITHUB_ENV
+          elif [[ $GIT_EVENT == 'release' ]]; then
+            GIT_TAG_NAME=${{ github.event.release.tag_name }}
+            echo "DOCKER_TAG=$(echo $GIT_TAG_NAME | cut -c 2-)" >> $GITHUB_ENV
+          fi
+
       - name: Checkout code
         uses: actions/checkout@v4
 
@@ -29,4 +43,4 @@ jobs:
           context: .
           push: true
           tags: |
-            ${{ secrets.DOCKER_REPOSITORY_LOCAL }}:latest
\ No newline at end of file
+            ${{ secrets.DOCKER_REPOSITORY_LOCAL }}:${{ env.DOCKER_TAG }}
\ No newline at end of file
-- 
GitLab