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:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user