chore: add version tag sha (#359)

* chore: set the git tag version and sha

* fix: inject the git data on build time

* fix: remove try catch
This commit is contained in:
bjarneo 2025-02-07 15:15:09 +01:00 committed by GitHub
parent e9da86edb3
commit 5ef329a268
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 46 additions and 3 deletions

View File

@ -26,6 +26,10 @@ jobs:
with:
fallback: no-tag
- name: Get short SHA
id: short_sha
run: echo "sha=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
- name: Get major version
id: major_version
run: |
@ -42,6 +46,9 @@ jobs:
platforms: linux/amd64, linux/arm64
push: true
tags: hemmeligapp/hemmelig:latest
build-args: |
GIT_SHA=${{ steps.short_sha.outputs.sha }}
GIT_TAG=${{ steps.latest_tag.outputs.tag }}
- name: Push to Docker Hub (full version)
uses: docker/build-push-action@v4
@ -49,6 +56,9 @@ jobs:
platforms: linux/amd64, linux/arm64
push: true
tags: hemmeligapp/hemmelig:${{ steps.latest_tag.outputs.tag }}
build-args: |
GIT_SHA=${{ steps.short_sha.outputs.sha }}
GIT_TAG=${{ steps.latest_tag.outputs.tag }}
- name: Push to Docker Hub (minor version)
uses: docker/build-push-action@v4
@ -56,6 +66,9 @@ jobs:
platforms: linux/amd64, linux/arm64
push: true
tags: hemmeligapp/hemmelig:${{ steps.minor_version.outputs.version }}
build-args: |
GIT_SHA=${{ steps.short_sha.outputs.sha }}
GIT_TAG=${{ steps.latest_tag.outputs.tag }}
- name: Push to Docker Hub (major version)
uses: docker/build-push-action@v4
@ -63,3 +76,6 @@ jobs:
platforms: linux/amd64, linux/arm64
push: true
tags: hemmeligapp/hemmelig:${{ steps.major_version.outputs.version }}
build-args: |
GIT_SHA=${{ steps.short_sha.outputs.sha }}
GIT_TAG=${{ steps.latest_tag.outputs.tag }}

View File

@ -15,6 +15,11 @@ RUN npm install
COPY . .
ARG GIT_SHA
ARG GIT_TAG
ENV GIT_SHA=${GIT_SHA}
ENV GIT_TAG=${GIT_TAG}
ENV NODE_ENV=production
RUN npm run build

View File

@ -7,6 +7,8 @@ import Nav from './components/header/nav';
import MainLinks from './components/settings/main-links';
import SecondaryLinks from './components/settings/secondary-links';
import config from './config';
const AdminShell = () => {
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
@ -72,7 +74,9 @@ const AdminShell = () => {
{/* Version or Additional Info (optional) */}
<div className="pt-4 mt-4 border-t border-gray-700/50">
<div className="px-3 text-xs text-gray-500">Hemmelig</div>
<div className="px-3 text-xs text-gray-500">
Hemmelig - {config.get('git.tag')} ({config.get('git.sha')})
</div>
</div>
</div>
</aside>

View File

@ -1,7 +1,7 @@
import { useTranslation } from 'react-i18next';
import { Link, Outlet } from 'react-router-dom';
import HeaderContent from './components/header';
import config from './config';
const ApplicationShell = () => {
const { t } = useTranslation();
@ -56,7 +56,9 @@ const ApplicationShell = () => {
rel="noreferrer"
className="text-xs text-gray-400 hover:text-gray-200 uppercase transition-colors"
>
<span className="text-xs">Github</span>
<span className="text-xs">
Github - {config.get('git.tag')} ({config.get('git.sha')})
</span>
</a>
</div>
</footer>

View File

@ -5,4 +5,8 @@ export default {
settings: {
forcedLanguage: '',
},
git: {
sha: import.meta.env.VITE_GIT_SHA || 'development',
tag: import.meta.env.VITE_GIT_TAG || 'development',
},
};

View File

@ -7,6 +7,14 @@ import { defineConfig } from 'vite';
const path = fileURLToPath(import.meta.url);
const root = resolve(dirname(path), 'client');
// Get git info
const getGitInfo = () => {
const sha = process.env.GIT_SHA || 'main';
const tag = process.env.GIT_TAG || 'latest';
return { sha, tag };
};
export default defineConfig({
root,
build: {
@ -19,4 +27,8 @@ export default defineConfig({
plugins: [tailwindcss()],
},
},
define: {
'import.meta.env.VITE_GIT_SHA': JSON.stringify(getGitInfo().sha),
'import.meta.env.VITE_GIT_TAG': JSON.stringify(getGitInfo().tag),
},
});