Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) |

Expand Down
26 changes: 23 additions & 3 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
50 changes: 31 additions & 19 deletions src/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -53,6 +57,8 @@ param(

[string]$PackageOutputPath,

[string]$Version = "0.0.999",

[switch]$VerboseOutput,

[switch]$EnableCodeCoverage,
Expand Down Expand Up @@ -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

Expand Down
Loading