diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml index b17c14e..47f0c36 100644 --- a/.gitea/workflows/docker-build.yml +++ b/.gitea/workflows/docker-build.yml @@ -31,6 +31,47 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '9.0.x' + + - name: Generate version.json with MinVer + run: | + # Fetch all tags for MinVer to work correctly + git fetch --tags --force + + # Build project to trigger MinVer (calcola versione automaticamente) + cd Data_Coupler + dotnet build -c Release /p:ContinuousIntegrationBuild=true + + # Extract version calculated by MinVer from build output + VERSION=$(dotnet msbuild -getProperty:Version -p:ContinuousIntegrationBuild=true 2>/dev/null | tail -1) + + # Fallback if MinVer fails (no tags) + if [ -z "$VERSION" ] || [ "$VERSION" = "0.0.0-alpha.0" ]; then + echo "Warning: No git tags found. MinVer returned default. Using fallback." + VERSION="2.1.0-alpha.0.$(git rev-list --count HEAD)" + fi + + echo "MinVer calculated version: $VERSION" + + # Create version.json + cat > wwwroot/version.json <$null | Select-Object -Last 1 + + # Fallback if MinVer fails (no tags) + if ([string]::IsNullOrWhiteSpace($VERSION) -or $VERSION -eq "0.0.0-alpha.0") { + Write-Host "Warning: No git tags found. MinVer returned default. Using fallback." + $commitCount = git rev-list --count HEAD + $VERSION = "2.1.0-alpha.0.$commitCount" + } + + Write-Host "MinVer calculated version: $VERSION" + + $COMMIT_SHA = "${{ github.sha }}" + $SHORT_SHA = $COMMIT_SHA.Substring(0, 7) + $BRANCH = "${{ github.ref_name }}" + $BUILD_DATE = (Get-Date).ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss UTC") + + # Create version.json + $versionJson = @{ + version = $VERSION + commitSha = $SHORT_SHA + branch = $BRANCH + buildDate = $BUILD_DATE + buildEnvironment = "Gitea Actions" + } | ConvertTo-Json + + $versionJson | Out-File -FilePath "wwwroot\version.json" -Encoding UTF8 + + Write-Host "Generated version.json:" + Get-Content "wwwroot\version.json" + cd .. + shell: pwsh + - name: Debug - Verify files run: | echo Working directory: diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 07b08b1..134a403 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -295,6 +295,35 @@ - `Data_Coupler/HealthChecks/DatabaseHealthCheck.cs` - `Data_Coupler/HealthChecks/BackgroundServiceHealthCheck.cs` +### 12. Sistema di Versioning Automatizzato + +#### Caratteristiche: +- **Versioning Automatico**: Generazione automatica della versione tramite Gitea Actions +- **Display UI**: Versione visibile nel NavMenu dell'applicazione +- **Semantic Versioning**: Segue il pattern MAJOR.MINOR.PATCH +- **Metadati Build**: Commit SHA, branch, data build, ambiente +- **Fallback Intelligente**: Versione di default se file non disponibile + +#### Componenti: +- **version.json**: File generato automaticamente durante il build +- **VersionInfo**: Modello dati per informazioni versione +- **VersionService**: Servizio singleton per gestione versione +- **NavMenu Integration**: Display "Data_Coupler v2.1.0" nel navbar + +#### Workflow: +1. Git Push โ†’ Gitea Actions triggered +2. Workflow genera `version.json` con versione da csproj +3. Docker build include il file version.json +4. VersionService carica al startup +5. NavMenu mostra versione nell'interfaccia + +#### File Chiave: +- `Data_Coupler/Models/VersionInfo.cs` +- `Data_Coupler/Services/VersionService.cs` +- `Data_Coupler/wwwroot/version.json` +- `.gitea/workflows/docker-build.yml` +- `VERSIONING_SYSTEM.md` (documentazione completa) + ## ๐Ÿ” Sicurezza ### Gestione Credenziali: @@ -441,7 +470,8 @@ - **SALESFORCE_BATCH_EXTRACTION_IMPROVEMENTS.md**: Batch extraction Salesforce - **PRE_DISCOVERY_SYSTEM.md**: Sistema pre-discovery associazioni - **DELETION_SYNC_IMPLEMENTATION.md**: Sincronizzazione eliminazioni -- **CSV_SCHEDULING_IMPLEMENTATION.md**: Schedulazione file CSV/Excel (NUOVO) +- **CSV_SCHEDULING_IMPLEMENTATION.md**: Schedulazione file CSV/Excel +- **VERSIONING_SYSTEM.md**: Sistema di versioning automatizzato (NUOVO) - **DOCKER_DEPLOYMENT.md**: Guida deployment Docker - **WINDOWS_SERVICE_DEPLOYMENT.md**: Deploy come Windows Service - **.gitea/workflows/README.md**: Configurazione Gitea Actions @@ -478,6 +508,7 @@ ### Feature in Pianificazione: - [x] Supporto file Excel/CSV avanzato (Completato - Gennaio 2026) +- [x] Sistema di versioning automatizzato (Completato - Febbraio 2026) - [ ] Sistema di notifiche (email, webhook) - [ ] Dashboard analytics avanzato - [ ] Multi-tenant support @@ -498,7 +529,7 @@ --- **Versione**: 2.1 -**Ultimo Aggiornamento**: 25 Gennaio 2026 +**Ultimo Aggiornamento**: 2 Febbraio 2026 **Framework**: .NET 9.0 **Sviluppatore**: Alessio Dalsanto **Repository**: https://github.com/AlessioDalsi/Data-Coupler diff --git a/Data_Coupler/Data_Coupler.csproj b/Data_Coupler/Data_Coupler.csproj index 106e539..3f8777f 100644 --- a/Data_Coupler/Data_Coupler.csproj +++ b/Data_Coupler/Data_Coupler.csproj @@ -4,6 +4,7 @@ net9.0 enable enable + @@ -20,6 +21,10 @@ all + + all + runtime; build; native; contentfiles; analyzers + diff --git a/Data_Coupler/Models/VersionInfo.cs b/Data_Coupler/Models/VersionInfo.cs new file mode 100644 index 0000000..42639b2 --- /dev/null +++ b/Data_Coupler/Models/VersionInfo.cs @@ -0,0 +1,53 @@ +namespace Data_Coupler.Models +{ + /// + /// Modello per le informazioni di versione dell'applicazione + /// + public class VersionInfo + { + /// + /// Versione principale (es. "2.1.0") + /// + public string Version { get; set; } = "0.0.0"; + + /// + /// Commit SHA breve (es. "abc1234") + /// + public string CommitSha { get; set; } = "unknown"; + + /// + /// Branch Git (es. "main", "development") + /// + public string Branch { get; set; } = "unknown"; + + /// + /// Data e ora del build + /// + public string BuildDate { get; set; } = "unknown"; + + /// + /// Ambiente di build (es. "Docker", "Local") + /// + public string BuildEnvironment { get; set; } = "Local"; + + /// + /// Restituisce una stringa formattata con la versione completa + /// + public string GetFullVersion() + { + if (CommitSha != "unknown" && Branch != "unknown") + { + return $"v{Version} ({Branch}-{CommitSha})"; + } + return $"v{Version}"; + } + + /// + /// Restituisce una stringa formattata breve per l'UI + /// + public string GetShortVersion() + { + return $"v{Version}"; + } + } +} diff --git a/Data_Coupler/Program.cs b/Data_Coupler/Program.cs index 355d41f..4581e19 100644 --- a/Data_Coupler/Program.cs +++ b/Data_Coupler/Program.cs @@ -32,6 +32,9 @@ builder.Services.AddWindowsService(); // Register Authentication Service builder.Services.AddSingleton(); +// Register Version Service +builder.Services.AddSingleton(); + // Configurazione logging per Windows Service if (OperatingSystem.IsWindows()) { diff --git a/Data_Coupler/Services/VersionService.cs b/Data_Coupler/Services/VersionService.cs new file mode 100644 index 0000000..b70aa90 --- /dev/null +++ b/Data_Coupler/Services/VersionService.cs @@ -0,0 +1,100 @@ +using Data_Coupler.Models; +using System.Text.Json; + +namespace Data_Coupler.Services +{ + /// + /// Interfaccia per il servizio di gestione versione applicazione + /// + public interface IVersionService + { + /// + /// Ottiene le informazioni sulla versione corrente dell'applicazione + /// + VersionInfo GetVersion(); + + /// + /// Ottiene la versione formattata per display nell'UI + /// + string GetDisplayVersion(); + } + + /// + /// Servizio per gestire le informazioni di versione dell'applicazione + /// Legge i dati da version.json generato durante il build + /// + public class VersionService : IVersionService + { + private readonly VersionInfo _versionInfo; + private readonly ILogger _logger; + private readonly IWebHostEnvironment _env; + + public VersionService(ILogger logger, IWebHostEnvironment env) + { + _logger = logger; + _env = env; + _versionInfo = LoadVersionInfo(); + } + + /// + /// Carica le informazioni di versione dal file version.json + /// + 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(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" + }; + } + + /// + /// Ottiene le informazioni complete sulla versione + /// + public VersionInfo GetVersion() + { + return _versionInfo; + } + + /// + /// Ottiene la versione formattata per display nell'UI + /// + public string GetDisplayVersion() + { + return _versionInfo.GetShortVersion(); + } + } +} diff --git a/Data_Coupler/Shared/NavMenu.razor b/Data_Coupler/Shared/NavMenu.razor index 223d28f..d7146d2 100644 --- a/Data_Coupler/Shared/NavMenu.razor +++ b/Data_Coupler/Shared/NavMenu.razor @@ -1,6 +1,6 @@ ๏ปฟ