Merge pull request 'feat: add build date/time to sidebar version display' (#184) from feat/sidebar-build-date into develop

Reviewed-on: https://code.cannabrands.app/Cannabrands/hub/pulls/184
This commit is contained in:
kelly
2025-12-11 00:19:56 +00:00
6 changed files with 30 additions and 3 deletions

View File

@@ -109,6 +109,7 @@ class AppServiceProvider extends ServiceProvider
$versionData = cache()->remember('app.version_data', now()->addSeconds(5), function () {
$version = 'dev';
$commit = 'unknown';
$buildDate = null;
// For Docker: read from version.env (injected at build time)
$versionFile = base_path('version.env');
@@ -117,6 +118,7 @@ class AppServiceProvider extends ServiceProvider
$data = parse_ini_file($versionFile);
$version = $data['VERSION'] ?? 'dev';
$commit = $data['COMMIT'] ?? 'unknown';
$buildDate = $data['BUILD_DATE'] ?? null;
}
// For local dev: read from git directly (but cached for 5 seconds)
// Check for .git (directory for regular repos, file for worktrees)
@@ -128,6 +130,13 @@ class AppServiceProvider extends ServiceProvider
// Only proceed if we successfully got a commit SHA
if ($commit !== '' && $commit !== 'unknown') {
// Get commit date for local dev
$dateCommand = sprintf('cd %s && git log -1 --format=%%ci 2>/dev/null', escapeshellarg(base_path()));
$commitDate = trim(shell_exec($dateCommand) ?: '');
if ($commitDate) {
$buildDate = date('M j, g:ia', strtotime($commitDate));
}
// Check for uncommitted changes (dirty working directory)
$diffCommand = sprintf('cd %s && git diff --quiet 2>/dev/null; echo $?', escapeshellarg(base_path()));
$cachedCommand = sprintf('cd %s && git diff --cached --quiet 2>/dev/null; echo $?', escapeshellarg(base_path()));
@@ -147,17 +156,19 @@ class AppServiceProvider extends ServiceProvider
return [
'version' => $version,
'commit' => $commit,
'buildDate' => $buildDate,
];
});
} catch (\Exception $e) {
// If cache fails (e.g., Redis not ready), calculate version without caching
$versionData = ['version' => 'dev', 'commit' => 'unknown'];
$versionData = ['version' => 'dev', 'commit' => 'unknown', 'buildDate' => null];
$versionFile = base_path('version.env');
if (File::exists($versionFile)) {
$data = parse_ini_file($versionFile);
$versionData['version'] = $data['VERSION'] ?? 'dev';
$versionData['commit'] = $data['COMMIT'] ?? 'unknown';
$versionData['buildDate'] = $data['BUILD_DATE'] ?? null;
}
}
@@ -165,6 +176,7 @@ class AppServiceProvider extends ServiceProvider
$view->with([
'appVersion' => $versionData['version'],
'appCommit' => $versionData['commit'],
'appBuildDate' => $versionData['buildDate'],
'appVersionFull' => "{$versionData['version']} (sha-{$versionData['commit']})",
]);
});

View File

@@ -165,6 +165,9 @@
v{{ $appVersion }} (sha-{{ $appCommit }})
@endif
</p>
@if($appBuildDate ?? null)
<p class="text-[10px] text-base-content/40 mb-0.5">{{ $appBuildDate }}</p>
@endif
<p>&copy; {{ date('Y') }} creationshop, {{ config('version.company.suffix') }}</p>
</div>
</div>

View File

@@ -178,13 +178,16 @@
<!-- Version Info Section -->
<div class="mx-2 mb-3 px-3 text-xs text-center text-base-content/50">
<p class="mb-0.5">{{ config('version.company.name') }} hub</p>
<p class="mb-0.5" style="font-family: 'Courier New', monospace;">
<p class="mb-0.5 font-mono">
@if($appVersion === 'dev')
<span class="text-yellow-500 font-semibold">DEV</span> sha-{{ $appCommit }}
@else
v{{ $appVersion }} (sha-{{ $appCommit }})
@endif
</p>
@if($appBuildDate ?? null)
<p class="text-[10px] text-base-content/40 mb-0.5">{{ $appBuildDate }}</p>
@endif
<p>&copy; {{ date('Y') }} Made with <span class="text-error">&hearts;</span> <a href="https://creationshop.io" target="_blank" rel="noopener noreferrer" class="link link-hover text-xs">Creationshop</a></p>
</div>

View File

@@ -179,6 +179,9 @@
v{{ $appVersion }} (sha-{{ $appCommit }})
@endif
</p>
@if($appBuildDate ?? null)
<p class="text-[10px] text-base-content/40 mb-0.5">{{ $appBuildDate }}</p>
@endif
<p>&copy; {{ date('Y') }} creationshop, {{ config('version.company.suffix') }}</p>
</div>
</div>

View File

@@ -693,6 +693,9 @@
v{{ $appVersion }} (sha-{{ $appCommit }})
@endif
</p>
@if($appBuildDate ?? null)
<p class="text-[10px] text-base-content/40 mb-0.5">{{ $appBuildDate }}</p>
@endif
<p>&copy; {{ date('Y') }} creationshop, {{ config('version.company.suffix') }}</p>
</div>
</div>

View File

@@ -1,10 +1,13 @@
<div class="fi-footer flex items-center justify-center gap-x-4 py-3 text-xs text-gray-500 dark:text-gray-400">
<div>
<div class="text-center">
@if ($appVersion === 'dev')
<span class="font-semibold text-yellow-600 dark:text-yellow-500">DEV</span>
<span class="font-mono">sha-{{ $appCommit }}</span>
@else
<span class="font-mono">v{{ $appVersion }} (sha-{{ $appCommit }})</span>
@endif
@if($appBuildDate ?? null)
<span class="text-gray-400 dark:text-gray-500 ml-2">{{ $appBuildDate }}</span>
@endif
</div>
</div>