From 159d9bbbef98ef60c0daaa3415ccfde61511c0df Mon Sep 17 00:00:00 2001 From: Duy Dao Date: Wed, 16 Jul 2025 08:09:14 +0700 Subject: [PATCH] feat: add application version and commit hash display in UI, update CI workflow for metadata handling --- .gitea/workflows/ci.yaml | 18 +++++++++++++++--- .../Components/Layout/MainLayout.razor | 13 +++++++++++-- .../Application/ApplicationInfo.cs | 17 +++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 CaddyManager/Configurations/Application/ApplicationInfo.cs diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 5dc13f9..b46483a 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -32,11 +32,23 @@ jobs: cache-dependency-path: '**/packages.lock.json' - name: Restore dependencies run: dotnet restore --locked-mode - - name: Build solution - run: dotnet build --configuration Release --no-restore + - name: Application metadata + id: metadata + run: | + echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + echo "APP_VERSION=$(grep 'public static readonly string Version' CaddyManager/Configurations/Application/ApplicationInfo.cs | sed -E 's/.*"([^"]+)".*/\1/')" >> $GITHUB_OUTPUT + - name: Patch application info + run: | + sed -i "s/public static readonly string CommitHash = \"\[DEVELOPMENT\]\";/public static readonly string CommitHash = \"${{ steps.metadata.outputs.COMMIT_HASH }}\";/" CaddyManager/Configurations/Application/ApplicationInfo.cs - name: Publish container run: | dotnet publish \ --configuration Release --os linux --arch x64 \ /t:PublishContainer -p ContainerRegistry=${{ vars.DOCKER_GITEA_DOMAIN }} \ - -p ContainerRepository=ebolo/caddy-manager \ No newline at end of file + -p ContainerRepository=ebolo/caddy-manager -p:ContainerImageTags='${{ steps.metadata.outputs.APP_VERSION }};latest' + - name: Deploy to Komodo + uses: fjogeleit/http-request-action@v1 + with: + url: '${{ vars.WINDMILL_DOMAIN }}/komodo/pull-stack/${{ secrets.KOMODO_STACK_ID }}' + method: 'PUT' + customHeaders: '{"Auth-Key": "${{ secrets.WINDMILL_KEY }}"}' \ No newline at end of file diff --git a/CaddyManager/Components/Layout/MainLayout.razor b/CaddyManager/Components/Layout/MainLayout.razor index eaf3a2f..ad90505 100644 --- a/CaddyManager/Components/Layout/MainLayout.razor +++ b/CaddyManager/Components/Layout/MainLayout.razor @@ -1,8 +1,8 @@ @inherits LayoutComponentBase +@using CaddyManager.Configurations.Application @* Required *@ - - + @* Needed for dialogs *@ @* Needed for snackbars *@ @@ -16,6 +16,15 @@ Caddy Manager + @ApplicationInfo.Version - + @if(ApplicationInfo.CommitHash != "[DEVELOPMENT]") + { + (@ApplicationInfo.CommitHash) + } + else + { + @ApplicationInfo.CommitHash + } diff --git a/CaddyManager/Configurations/Application/ApplicationInfo.cs b/CaddyManager/Configurations/Application/ApplicationInfo.cs new file mode 100644 index 0000000..c5a68da --- /dev/null +++ b/CaddyManager/Configurations/Application/ApplicationInfo.cs @@ -0,0 +1,17 @@ +namespace CaddyManager.Configurations.Application; + +/// +/// Containing information about the application +/// +public class ApplicationInfo +{ + /// + /// The version of the application, to be defined and tagged + /// + public static readonly string Version = "1.0.0"; + + /// + /// The commit hash of the application + /// + public static readonly string CommitHash = "[DEVELOPMENT]"; +} \ No newline at end of file