Added version to landing page

This commit is contained in:
2025-12-30 22:47:52 +01:00
parent d0c177b46e
commit 4e49a38cf9
14 changed files with 341 additions and 16 deletions
+70
View File
@@ -0,0 +1,70 @@
# Version Management
## Current Version: 0.1.30
The backend version is managed in `/backend/config/version.go`.
## Updating the Version
To update the application version:
1. Edit `/backend/config/version.go`
2. Change the `Version` constant:
```go
const Version = "0.1.31" // Update this
```
## Git Commit Information
The git commit hash is automatically detected at runtime from:
1. `GIT_COMMIT` environment variable (preferred for Docker)
2. Git command output (works in development)
3. Falls back to "unknown" if neither is available
## Setting Git Commit in Docker
### Development Environment
Add to `docker/.env`:
```bash
GIT_COMMIT=$(git rev-parse --short HEAD)
```
Then restart the container:
```bash
cd docker
docker-compose -f docker-compose.dev.yml up -d backend-dev
```
### Production Build
Use build-time variable:
```bash
docker build --build-arg GIT_COMMIT=$(git rev-parse --short HEAD) .
```
Or set in docker-compose.yml:
```yaml
environment:
- GIT_COMMIT=${GIT_COMMIT:-unknown}
```
## API Endpoints
- **Public**: `GET /api/public/version` (no authentication)
- **Protected**: `GET /api/version` (requires JWT token)
Both return:
```json
{
"version": "0.1.30",
"gitCommit": "d0c177b"
}
```
## Frontend Integration
The landing page automatically fetches version information from `/api/public/version` and displays it.
To see the version in the frontend, visit: http://localhost:5173
+2
View File
@@ -82,9 +82,11 @@ func main() {
importer.RegisterRoutes(protected)
pdfrender.RegisterRoutes(protected)
transfer.RegisterRoutes(protected)
config.RegisterRoutes(protected)
// Register public routes (no authentication)
pdfrender.RegisterPublicRoutes(r)
config.RegisterPublicRoutes(r)
logger.Info("API-Routen erfolgreich registriert")
+10
View File
@@ -0,0 +1,10 @@
package config
import (
"github.com/gin-gonic/gin"
)
// Versionsinfo returns version and git commit information
func Versionsinfo(c *gin.Context) {
c.JSON(200, GetInfo())
}
+15
View File
@@ -0,0 +1,15 @@
package config
import "github.com/gin-gonic/gin"
// RegisterRoutes registers config-related routes (protected)
func RegisterRoutes(r *gin.RouterGroup) {
r.GET("/version", Versionsinfo)
}
// RegisterPublicRoutes registers public config routes (no auth required)
func RegisterPublicRoutes(r *gin.Engine) {
// Public version endpoint - no authentication required
public := r.Group("/api/public")
public.GET("/version", Versionsinfo)
}
+60
View File
@@ -0,0 +1,60 @@
package config
// Version is the application version
const Version = "0.1.30"
var (
// GitCommit will be set by build flags or detected at runtime
GitCommit = "unknown"
)
// init detects git commit if not set during build
func init() {
/*
if GitCommit == "" {
// Try environment variable first
if envCommit := os.Getenv("GIT_COMMIT"); envCommit != "" {
GitCommit = envCommit
} else {
// Try to detect from git command
GitCommit = detectGitCommit()
}
}
*/
}
/*
// detectGitCommit tries to get the current git commit hash
func detectGitCommit() string {
cmd := exec.Command("git", "rev-parse", "--short", "HEAD")
output, err := cmd.Output()
if err != nil {
return "unknown"
}
return strings.TrimSpace(string(output))
}
*/
// GetVersion returns the current application version
func GetVersion() string {
return Version
}
/*
// GetGitCommit returns the git commit hash
func GetGitCommit() string {
return GitCommit
}
*/
// Info contains version information
type Info struct {
Version string `json:"version"`
GitCommit string `json:"gitCommit"`
}
// GetInfo returns version information as a struct
func GetInfo() Info {
return Info{
Version: Version,
GitCommit: GitCommit,
}
}
+43
View File
@@ -0,0 +1,43 @@
package config
import (
"testing"
)
func TestGetVersion(t *testing.T) {
version := GetVersion()
if version == "" {
t.Error("Version should not be empty")
}
if version != Version {
t.Errorf("Expected version %s, got %s", Version, version)
}
}
/*
func TestGetGitCommit(t *testing.T) {
commit := GetGitCommit()
if commit == "" {
t.Error("GitCommit should not be empty")
}
// Should be either "unknown" or a valid git hash
if commit != "unknown" && len(commit) < 7 {
t.Errorf("Invalid git commit format: %s", commit)
}
}
*/
func TestGetInfo(t *testing.T) {
info := GetInfo()
if info.Version == "" {
t.Error("Info.Version should not be empty")
}
if info.GitCommit == "" {
t.Error("Info.GitCommit should not be empty")
}
if info.Version != Version {
t.Errorf("Expected info.Version %s, got %s", Version, info.Version)
}
}
+1
View File
@@ -14,6 +14,7 @@ services:
- API_PORT=${API_PORT:-8180}
- TEMPLATES_DIR=${TEMPLATES_DIR:-./templatesx}
- EXPORT_TEMP_DIR=${EXPORT_TEMP_DIR:-./export_tempx}
- GIT_COMMIT=${GIT_COMMIT:-unknown}
depends_on:
mariadb-dev:
condition: service_healthy
+4
View File
@@ -11,6 +11,10 @@ fi
# Gehe ins Docker-Verzeichnis
cd "$(dirname "$0")"
# Get current git commit
export GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
echo "📝 Git Commit: $GIT_COMMIT"
echo "📦 Building and starting development containers..."
# Stoppe vorhandene Container
+87
View File
@@ -0,0 +1,87 @@
# Frontend Version Management
## Current Version: 0.1.30
The frontend version is managed independently from the backend.
## Version Locations
1. **Primary source**: `/frontend/src/version.js`
- Contains the VERSION constant
- Exports version info functions
2. **Package metadata**: `/frontend/package.json`
- Standard npm version field
- Should match version.js
## Updating the Version
### Option 1: Using the update script (Recommended)
```bash
# Updates both backend and frontend
./scripts/update-version.sh 0.1.31
```
### Option 2: Manual update
Edit `/frontend/src/version.js`:
```javascript
export const VERSION = '0.1.31' // Update this
```
And `/frontend/package.json`:
```json
{
"version": "0.1.31" // Update this
}
```
## Git Commit Information
The git commit is injected via environment variable:
- Set `VITE_GIT_COMMIT` in `.env` or at build time
- Falls back to "unknown" if not set
Example `.env`:
```bash
VITE_GIT_COMMIT=d0c177b
```
## Usage in Components
```javascript
import { getVersion, getGitCommit, getVersionInfo } from '@/version'
// Get version string
const version = getVersion() // "0.1.30"
// Get git commit
const commit = getGitCommit() // "d0c177b" or "unknown"
// Get full info object
const info = getVersionInfo() // { version: "0.1.30", gitCommit: "d0c177b" }
```
## Landing Page Display
The landing page shows both:
- **Frontend Version**: From `/frontend/src/version.js`
- **Backend Version**: Fetched from `/api/public/version`
This allows users to see if frontend and backend are in sync.
## Build-time Version Injection
To inject git commit at build time, update `vite.config.js`:
```javascript
import { defineConfig } from 'vite'
import { execSync } from 'child_process'
const gitCommit = execSync('git rev-parse --short HEAD').toString().trim()
export default defineConfig({
define: {
'import.meta.env.VITE_GIT_COMMIT': JSON.stringify(gitCommit)
}
})
```
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "my-app",
"version": "0.0.0",
"name": "bamort-frontend",
"version": "0.1.21",
"private": true,
"type": "module",
"scripts": {
+4 -2
View File
@@ -47,8 +47,10 @@ export default {
Home:'Startseite',
},
landing:{
title:'BaMoRT - Charakterverwaltung für Rollenspiele',
description:'Bamort ist ein modernes Werkzeug zur Charakterverwaltung für Rollenspiele. Es bietet umfassende Funktionen zur Charaktererstellung, -entwicklung und -verwaltung mit Unterstützung für Fertigkeiten, Zauber, Ausrüstung und mehr.',
title:'BaMoRT - Charakterverwaltung für mein Lieblingsrollenspielsystem',
description:'Bamort ist ein Werkzeug zur Charakterverwaltung für Rollenspiele. Es bietet Funktionen zur Charaktererstellung, -entwicklung und -verwaltung mit Unterstützung für Fertigkeiten, Zauber, Ausrüstung und mehr. Viele Ausrüstungsteile, Fertikeiten und Zauber fehlen noch, da das Projekt noch in der Entwicklung ist.',
frontendVersion:'Frontend Version',
backendVersion:'Backend Version',
version:'Version',
commit:'Commit',
login:'Zum Login',
+2
View File
@@ -48,6 +48,8 @@ export default {
landing:{
title:'BaMoRT - Character Management for Role-Playing Games',
description:'Bamort is a modern character management tool for role-playing games. It provides comprehensive features for character creation, development, and management with support for skills, spells, equipment, and more.',
frontendVersion:'Frontend Version',
backendVersion:'Backend Version',
version:'Version',
commit:'Commit',
login:'Login',
+20
View File
@@ -0,0 +1,20 @@
// Frontend version information
export const VERSION = '0.1.21'
// Git commit will be injected at build time or detected from env
export const GIT_COMMIT = import.meta.env.VITE_GIT_COMMIT || 'unknown'
export function getVersion() {
return VERSION
}
export function getGitCommit() {
return GIT_COMMIT
}
export function getVersionInfo() {
return {
version: VERSION,
gitCommit: GIT_COMMIT
}
}
+21 -12
View File
@@ -10,8 +10,8 @@
<p class="description">{{ $t('landing.description') }}</p>
<div class="version-info">
<p>{{ $t('landing.version') }}: {{ version }}</p>
<p>{{ $t('landing.commit') }}: {{ commit }}</p>
<p>{{ $t('landing.frontendVersion') }}: {{ frontendVersion }}<!-- ({{ frontendCommit }})--> </p>
<p>{{ $t('landing.backendVersion') }}: {{ backendVersion }}<!-- ({{ backendCommit }})--> </p>
</div>
<div class="action-links">
@@ -32,28 +32,37 @@
</style>
<script>
import axios from 'axios'
import { getVersion, getGitCommit } from '../version'
export default {
name: "LandingView",
data() {
return {
version: "0.1.0",
commit: "9775290",
frontendVersion: getVersion(),
frontendCommit: getGitCommit(),
backendVersion: "Loading...",
backendCommit: "Loading...",
githubUrl: "https://github.com/Bardioc26/bamort"
}
},
mounted() {
// Fetch version and commit from API if available
this.fetchVersionInfo()
this.fetchBackendVersion()
},
methods: {
async fetchVersionInfo() {
async fetchBackendVersion() {
try {
// For now, using static values
// In future, could fetch from backend API endpoint
this.version = import.meta.env.VITE_APP_VERSION || "0.1.0"
this.commit = import.meta.env.VITE_GIT_COMMIT || "9775290"
const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:8180'
const response = await axios.get(`${apiUrl}/api/public/version`)
if (response.data) {
this.backendVersion = response.data.version || "Unknown"
this.backendCommit = response.data.gitCommit || "Unknown"
}
} catch (error) {
console.warn("Could not fetch version info:", error)
console.warn("Could not fetch backend version:", error)
this.backendVersion = "Unavailable"
this.backendCommit = "N/A"
}
}
}