From c181242e3498685ac3a13383cae7d5a44cd6ab9e Mon Sep 17 00:00:00 2001 From: Berry den Hartog <38954346+berrydenhartog@users.noreply.github.com> Date: Fri, 14 Jun 2024 17:46:27 +0200 Subject: [PATCH 1/2] Add hash to build --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c0faeb7..56135be7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -142,6 +142,15 @@ jobs: steps: - uses: actions/checkout@v4 + - name: get commit hash + id: get_commit_hash + run: | + echo "commit_hash=$(git describe --tags)" >> "$GITHUB_OUTPUT" + + - name: Make changes to project to inject commit hash + run: | + sed -i 's/VERSION: str = .*$/VERSION: str = "${{ steps.get_commit_hash.outputs.commit_hash }}"/g' tad/core/config.py + - name: Log in to the Container registry uses: docker/login-action@v3 with: @@ -168,6 +177,7 @@ jobs: echo "tags: ${{ steps.meta.outputs.tags }}" echo "labels: ${{ steps.meta.outputs.labels }}" echo "annotations: ${{ steps.meta.outputs.annotations }}" + echo "hash: ${{ steps.get_commit_hash.outputs.commit_hash }}" - name: Build and push Docker image From b1268d9a1c7f086cc98df7fc7ee312599c4dc9b2 Mon Sep 17 00:00:00 2001 From: Berry den Hartog <38954346+berrydenhartog@users.noreply.github.com> Date: Sat, 15 Jun 2024 21:11:04 +0200 Subject: [PATCH 2/2] Inject version into template --- tad/api/routes/deps.py | 8 +++++++- tad/site/templates/default_layout.jinja | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tad/api/routes/deps.py b/tad/api/routes/deps.py index 92227899..d5e96e33 100644 --- a/tad/api/routes/deps.py +++ b/tad/api/routes/deps.py @@ -1,9 +1,15 @@ +from fastapi import Request from fastapi.templating import Jinja2Templates from jinja2 import Environment from tad.core.config import settings + +def version_context_processor(request: Request): + return {"version": settings.VERSION} + + env = Environment( autoescape=True, ) -templates = Jinja2Templates(directory=settings.TEMPLATE_DIR, env=env) +templates = Jinja2Templates(directory=settings.TEMPLATE_DIR, context_processors=[version_context_processor], env=env) diff --git a/tad/site/templates/default_layout.jinja b/tad/site/templates/default_layout.jinja index de887deb..2dedbb79 100644 --- a/tad/site/templates/default_layout.jinja +++ b/tad/site/templates/default_layout.jinja @@ -45,11 +45,12 @@