From 933d83b7e4f889f9f81017cb4a7fb7c1aad94b44 Mon Sep 17 00:00:00 2001
From: Emmanuel Evbuomwan <emmanuel.evbuomwan@aiven.io>
Date: Wed, 18 Dec 2024 15:10:33 +0100
Subject: [PATCH] ci: extract version from git tags

---
 .github/workflows/container-smoke-test.yml |  8 +-------
 .github/workflows/lint.yml                 | 14 ++++++++------
 .github/workflows/tests.yml                |  8 +-------
 3 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/.github/workflows/container-smoke-test.yml b/.github/workflows/container-smoke-test.yml
index 89d6d4a2d..a92bd387f 100644
--- a/.github/workflows/container-smoke-test.yml
+++ b/.github/workflows/container-smoke-test.yml
@@ -20,14 +20,8 @@ jobs:
         with:
           fetch-depth: 0
 
-      - name: Install requirements
-        run: make install-dev
-
       - name: Resolve Karapace version
-        run: |
-          source ./venv/bin/activate
-          KARAPACE_VERSION=$(python -c "from karapace import version; print(version.__version__)")
-          echo KARAPACE_VERSION=$KARAPACE_VERSION >> $GITHUB_ENV
+        run: echo KARAPACE_VERSION="$(git describe --tags | cut -d '-' -f -2 | sed 's/-/.dev/g')" >> $GITHUB_ENV
 
       - run: echo "RUNNER_UID=$(id -u)" >> $GITHUB_ENV
       - run: echo "RUNNER_GID=$(id -g)" >> $GITHUB_ENV
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 1de08c44f..0f3eec51a 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -42,14 +42,15 @@ jobs:
         cache: pip
         python-version: '3.12'
 
-    - name: Install requirements
-      run: make install-dev
+    - name: Gather context
+      id: ctx
+      run: |
+        echo is_release=${{ contains(github.ref, 'refs/tags/') }} | tee -a $GITHUB_OUTPUT
+        echo is_dev=${{ ! contains(github.ref, 'refs/tags/') }} | tee -a $GITHUB_OUTPUT
+        echo version=$(git describe --tags | cut -d '-' -f -2 | sed 's/-/.dev/g')
 
     - name: Resolve Karapace version
-      run: |
-        source ./venv/bin/activate
-        KARAPACE_VERSION=$(python -c "from karapace import version; print(version.__version__)")
-        echo KARAPACE_VERSION=$KARAPACE_VERSION >> $GITHUB_ENV
+      run: echo KARAPACE_VERSION="$(git describe --tags | cut -d '-' -f -2 | sed 's/-/.dev/g')" >> $GITHUB_ENV
 
     - run: echo "RUNNER_UID=$(id -u)" >> $GITHUB_ENV
     - run: echo "RUNNER_GID=$(id -g)" >> $GITHUB_ENV
@@ -57,6 +58,7 @@ jobs:
     - name: Run mypy
       run: make type-check-mypy-in-docker
       env:
+        KV: ${{ steps.ctx.outputs.version }}
         PYTHON_VERSION: 3.12
         KARAPACE_VERSION: ${{ env.KARAPACE_VERSION }}
         RUNNER_UID: ${{ env.RUNNER_UID }}
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index df5b5683b..2c1e0813c 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -40,14 +40,8 @@ jobs:
       with:
         go-version: '1.21.0'
 
-    - name: Install requirements
-      run: make install-dev
-
     - name: Resolve Karapace version
-      run: |
-        source ./venv/bin/activate
-        KARAPACE_VERSION=$(python -c "from karapace import version; print(version.__version__)")
-        echo KARAPACE_VERSION=$KARAPACE_VERSION >> $GITHUB_ENV
+      run: echo KARAPACE_VERSION="$(git describe --tags | cut -d '-' -f -2 | sed 's/-/.dev/g')" >> $GITHUB_ENV
 
     - run: echo "RUNNER_UID=$(id -u)" >> $GITHUB_ENV
     - run: echo "RUNNER_GID=$(id -g)" >> $GITHUB_ENV