feat: Implementato sistema di versioning automatizzato con MinVer e Gitea Actions
- Aggiunto MinVer per calcolo automatico versione da git tags - Creato modello VersionInfo e servizio VersionService - Integrato display versione nel NavMenu (Data_Coupler v2.1.0) - Aggiornato workflow Gitea Actions (Linux e Windows) per generare version.json - Risolto problema inconsistenza versioning tra container Linux e Windows - Documentazione completa: VERSIONING_SYSTEM.md e MINVER_SETUP.md - Versione ora calcolata automaticamente da git tags (Semantic Versioning)
This commit was merged in pull request #10.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<!-- Version is now automatically calculated by MinVer from git tags -->
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -20,6 +21,10 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="9.0.6" />
|
||||
<PackageReference Include="MinVer" Version="5.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
namespace Data_Coupler.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Modello per le informazioni di versione dell'applicazione
|
||||
/// </summary>
|
||||
public class VersionInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Versione principale (es. "2.1.0")
|
||||
/// </summary>
|
||||
public string Version { get; set; } = "0.0.0";
|
||||
|
||||
/// <summary>
|
||||
/// Commit SHA breve (es. "abc1234")
|
||||
/// </summary>
|
||||
public string CommitSha { get; set; } = "unknown";
|
||||
|
||||
/// <summary>
|
||||
/// Branch Git (es. "main", "development")
|
||||
/// </summary>
|
||||
public string Branch { get; set; } = "unknown";
|
||||
|
||||
/// <summary>
|
||||
/// Data e ora del build
|
||||
/// </summary>
|
||||
public string BuildDate { get; set; } = "unknown";
|
||||
|
||||
/// <summary>
|
||||
/// Ambiente di build (es. "Docker", "Local")
|
||||
/// </summary>
|
||||
public string BuildEnvironment { get; set; } = "Local";
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce una stringa formattata con la versione completa
|
||||
/// </summary>
|
||||
public string GetFullVersion()
|
||||
{
|
||||
if (CommitSha != "unknown" && Branch != "unknown")
|
||||
{
|
||||
return $"v{Version} ({Branch}-{CommitSha})";
|
||||
}
|
||||
return $"v{Version}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce una stringa formattata breve per l'UI
|
||||
/// </summary>
|
||||
public string GetShortVersion()
|
||||
{
|
||||
return $"v{Version}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,9 @@ builder.Services.AddWindowsService();
|
||||
// Register Authentication Service
|
||||
builder.Services.AddSingleton<Data_Coupler.Services.IAuthenticationService, Data_Coupler.Services.AuthenticationService>();
|
||||
|
||||
// Register Version Service
|
||||
builder.Services.AddSingleton<Data_Coupler.Services.IVersionService, Data_Coupler.Services.VersionService>();
|
||||
|
||||
// Configurazione logging per Windows Service
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
using Data_Coupler.Models;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Data_Coupler.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Interfaccia per il servizio di gestione versione applicazione
|
||||
/// </summary>
|
||||
public interface IVersionService
|
||||
{
|
||||
/// <summary>
|
||||
/// Ottiene le informazioni sulla versione corrente dell'applicazione
|
||||
/// </summary>
|
||||
VersionInfo GetVersion();
|
||||
|
||||
/// <summary>
|
||||
/// Ottiene la versione formattata per display nell'UI
|
||||
/// </summary>
|
||||
string GetDisplayVersion();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Servizio per gestire le informazioni di versione dell'applicazione
|
||||
/// Legge i dati da version.json generato durante il build
|
||||
/// </summary>
|
||||
public class VersionService : IVersionService
|
||||
{
|
||||
private readonly VersionInfo _versionInfo;
|
||||
private readonly ILogger<VersionService> _logger;
|
||||
private readonly IWebHostEnvironment _env;
|
||||
|
||||
public VersionService(ILogger<VersionService> logger, IWebHostEnvironment env)
|
||||
{
|
||||
_logger = logger;
|
||||
_env = env;
|
||||
_versionInfo = LoadVersionInfo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Carica le informazioni di versione dal file version.json
|
||||
/// </summary>
|
||||
private VersionInfo LoadVersionInfo()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Cerca il file version.json nella root dell'applicazione
|
||||
var versionFilePath = Path.Combine(_env.ContentRootPath, "version.json");
|
||||
|
||||
if (File.Exists(versionFilePath))
|
||||
{
|
||||
var json = File.ReadAllText(versionFilePath);
|
||||
var version = JsonSerializer.Deserialize<VersionInfo>(json, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
|
||||
if (version != null)
|
||||
{
|
||||
_logger.LogInformation("Version loaded: {Version}", version.GetFullVersion());
|
||||
return version;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("version.json not found at {Path}, using default version", versionFilePath);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error loading version.json, using default version");
|
||||
}
|
||||
|
||||
// Versione di default se il file non esiste o c'è un errore
|
||||
return new VersionInfo
|
||||
{
|
||||
Version = "2.1.0",
|
||||
CommitSha = "local",
|
||||
Branch = "dev",
|
||||
BuildDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
BuildEnvironment = "Local"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ottiene le informazioni complete sulla versione
|
||||
/// </summary>
|
||||
public VersionInfo GetVersion()
|
||||
{
|
||||
return _versionInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ottiene la versione formattata per display nell'UI
|
||||
/// </summary>
|
||||
public string GetDisplayVersion()
|
||||
{
|
||||
return _versionInfo.GetShortVersion();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="top-row ps-3 navbar navbar-dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="">Data_Coupler</a>
|
||||
<a class="navbar-brand" href="">Data_Coupler @_version</a>
|
||||
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
@@ -58,11 +58,19 @@
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
@inject Data_Coupler.Services.IVersionService VersionService
|
||||
|
||||
@code {
|
||||
private bool collapseNavMenu = true;
|
||||
private string _version = "";
|
||||
|
||||
private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_version = VersionService.GetDisplayVersion();
|
||||
}
|
||||
|
||||
private void ToggleNavMenu()
|
||||
{
|
||||
collapseNavMenu = !collapseNavMenu;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"version": "2.1.0",
|
||||
"commitSha": "local",
|
||||
"branch": "dev",
|
||||
"buildDate": "2026-02-02",
|
||||
"buildEnvironment": "Local"
|
||||
}
|
||||
Reference in New Issue
Block a user