diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 65042c3..0c37005 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -69,6 +69,13 @@ Publishes NuGet packages to GitHub Package Registry. https://nuget.pkg.github.com/ClearMeasureLabs/index.json ``` +**Version Management:** +- Package versions are automatically incremented using the format `1.0.{run_number}` +- The `run_number` is provided by GitHub Actions and increments with each workflow run +- This ensures each push to main creates unique package versions +- If a duplicate version is detected, the workflow will fail with an error +- The `--skip-duplicate` flag is NOT used to ensure version conflicts are caught early + ##### 3. Publish Release to GitHub Packages Publishes release packages and attaches them to the GitHub release. @@ -98,6 +105,7 @@ The workflows leverage the `src/build.ps1` PowerShell script for all build opera | `-Pack` | Create NuGet packages | ✅ Yes (pack step) | | `-PackOnly` | Only create packages | ✅ Yes (pack step) | | `-PackageOutputPath` | Package output directory | ✅ Yes (custom path) | +| `-Version` | Version number for packages | ✅ Yes (1.0.{run_number}) | | `-Clean` | Clean before build | ❌ No (fresh checkout) | | `-VerboseOutput` | Verbose MSBuild output | ❌ No (uses defaults) | diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 716ca54..78b4471 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -99,7 +99,9 @@ jobs: if: github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'workflow_dispatch' run: | cd src - .\build.ps1 -Configuration Release -PackOnly -PackageOutputPath "${{ github.workspace }}/packages" + $version = "1.0.${{ github.run_number }}" + Write-Host "Creating packages with version: $version" + .\build.ps1 -Configuration Release -PackOnly -PackageOutputPath "${{ github.workspace }}/packages" -Version $version shell: pwsh - name: Upload NuGet packages @@ -133,9 +135,18 @@ jobs: - name: Publish to GitHub Packages run: | + $hasError = $false Get-ChildItem -Path packages -Filter *.nupkg -Recurse | ForEach-Object { Write-Host "Publishing $($_.Name)..." - dotnet nuget push $_.FullName --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --skip-duplicate + dotnet nuget push $_.FullName --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" + if ($LASTEXITCODE -ne 0) { + $hasError = $true + Write-Error "Failed to publish $($_.Name)" + } + } + if ($hasError) { + Write-Error "One or more packages failed to publish. This may indicate duplicate versions." + exit 1 } shell: pwsh @@ -173,9 +184,18 @@ jobs: - name: Publish to GitHub Packages run: | + $hasError = $false Get-ChildItem -Path packages -Filter *.nupkg -Recurse | ForEach-Object { Write-Host "Publishing release package $($_.Name)..." - dotnet nuget push $_.FullName --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --skip-duplicate + dotnet nuget push $_.FullName --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" + if ($LASTEXITCODE -ne 0) { + $hasError = $true + Write-Error "Failed to publish $($_.Name)" + } + } + if ($hasError) { + Write-Error "One or more packages failed to publish. This may indicate duplicate versions." + exit 1 } shell: pwsh env: diff --git a/src/build.ps1 b/src/build.ps1 index 6d9e7a2..9cf316b 100644 --- a/src/build.ps1 +++ b/src/build.ps1 @@ -14,6 +14,8 @@ Create NuGet packages for library projects .PARAMETER PackageOutputPath Output directory for NuGet packages. Default: ./artifacts/packages +.PARAMETER Version + Version number for NuGet packages. Default: 0.0.999 for local builds .PARAMETER VerboseOutput Enable verbose output .PARAMETER EnableCodeCoverage @@ -34,6 +36,8 @@ .\build.ps1 -Pack .EXAMPLE .\build.ps1 -Pack -PackageOutputPath "C:\packages" +.EXAMPLE + .\build.ps1 -Pack -Version "1.0.5" .EXAMPLE .\build.ps1 -EnableCodeCoverage -GenerateTestReport .EXAMPLE @@ -53,6 +57,8 @@ param( [string]$PackageOutputPath, + [string]$Version = "0.0.999", + [switch]$VerboseOutput, [switch]$EnableCodeCoverage, @@ -471,25 +477,31 @@ function Invoke-Pack { $packagesCreated = 0 foreach ($project in $packProjects) { - $projectPath = Join-Path $scriptPath $project - if (Test-Path $projectPath) { - Write-Info "Packing $(Split-Path $project -Leaf)" - - $packArgs = @( - "pack" - $projectPath - "--configuration", $Configuration - "--no-build" - "--no-restore" - "--output", $PackageOutputPath - "--verbosity", $verbosityLevel - ) - - # Add include symbols option for Release builds - if ($Configuration -eq "Release") { - $packArgs += "--include-symbols" - $packArgs += "--include-source" - } + $projectPath = Join-Path $scriptPath $project + if (Test-Path $projectPath) { + Write-Info "Packing $(Split-Path $project -Leaf)" + + $packArgs = @( + "pack" + $projectPath + "--configuration", $Configuration + "--no-build" + "--no-restore" + "--output", $PackageOutputPath + "--verbosity", $verbosityLevel + ) + + # Add version if specified + if ($Version) { + $packArgs += "-p:Version=$Version" + Write-Info "Using version: $Version" + } + + # Add include symbols option for Release builds + if ($Configuration -eq "Release") { + $packArgs += "--include-symbols" + $packArgs += "--include-source" + } dotnet @packArgs