Skip to content

Fix GitHub Actions NuGet publish: glob expansion, version number, PR pre-release versioning, and deterministic builds - #234

Merged
304NotModified merged 7 commits into
masterfrom
copilot/fix-nuget-push-issues
Mar 7, 2026
Merged

Fix GitHub Actions NuGet publish: glob expansion, version number, PR pre-release versioning, and deterministic builds#234
304NotModified merged 7 commits into
masterfrom
copilot/fix-nuget-push-issues

Conversation

Copilot AI commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Two bugs prevented NuGet publishing from working after migrating to GitHub Actions: dotnet nuget push artifacts/*.nupkg failed on Windows because PowerShell doesn't expand globs for executables, and packages were always versioned 1.0.0 because no <Version> was set in the csproj (Azure Pipelines injected it via -p:Version=).

NLog.MailKit.csproj

  • Replace <Version> with <VersionPrefix>6.0.5</VersionPrefix> — required so --version-suffix in the workflow actually appends (setting <Version> directly silently ignores the suffix flag)
  • Add <FileVersion>$(VersionPrefix).0</FileVersion> — without this the SDK defaults FileVersion to AssemblyVersion (6.0.0.0); now 6.0.5.0
  • Add <PublishRepositoryUrl>true</PublishRepositoryUrl> and <EmbedUntrackedSources>true</EmbedUntrackedSources> — enables SourceLink to map PDBs back to source
  • Add <IncludeSymbols>true</IncludeSymbols> and <SymbolPackageFormat>snupkg</SymbolPackageFormat> — produces a .snupkg debug symbols package alongside the .nupkg
  • Add <ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild> — sets Deterministic=true automatically in CI for reproducible builds (see DeterministicBuilds)

.github/workflows/build-and-test.yml (renamed from build.yml)

  • Restore, build, and test only — runs on windows-latest and ubuntu-latest
  • No NuGet permissions required

.github/workflows/nuget.yml (new)

  • Glob fix: shell: bash on the push step so bash expands artifacts/*.nupkg
  • PR pre-release versioning: "Determine version suffix" step — master produces no suffix (clean release); any other branch/PR cleans the ref name to alphanumeric+hyphens and passes it as --version-suffix, e.g. NLog.MailKit.6.0.5-pull-42-head.nupkg
  • Pack step conditionally applies the suffix
  • Upload artifact path set to artifacts/*pkg to capture both .nupkg and .snupkg
  • Push step uses a single dotnet nuget push artifacts/*.nupkgdotnet nuget push automatically pushes the matching .snupkg alongside each .nupkg
  • id-token: write permission scoped only to this workflow where it is needed

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 7, 2026 21:24
Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
@pull-request-size pull-request-size Bot added size/S and removed size/XS labels Mar 7, 2026
Copilot AI changed the title [WIP] Fix nuget push errors in GitHub Actions Fix GitHub Actions NuGet publish: glob expansion, version number, and PR pre-release versioning Mar 7, 2026
@304NotModified

Copy link
Copy Markdown
Member

@copilot rename build to build-and-test.yml
move the Nuget pack stuff to nuget.yml

Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
@pull-request-size pull-request-size Bot added size/M and removed size/S labels Mar 7, 2026

Copilot AI commented Mar 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot rename build to build-and-test.yml
move the Nuget pack stuff to nuget.yml

Done in c178313. build.yml is renamed to build-and-test.yml (restore, build, test on windows + ubuntu only), and all NuGet steps (pack, upload artifact, login, push) are moved to a new nuget.yml (windows-latest only). The id-token: write permission is now scoped only to nuget.yml where it's needed.

@304NotModified

Copy link
Copy Markdown
Member

@copilot the package isn't determenistic anymore and also missing debug symbols (snupkg needed for that). Also sourcelink is broken

We need also something like ContinuousIntegrationBuild=true, see https://github.com/clairernovotny/DeterministicBuilds

Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Mar 7, 2026

Copilot AI commented Mar 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the package isn't determenistic anymore and also missing debug symbols (snupkg needed for that). Also sourcelink is broken

We need also something like ContinuousIntegrati...

Done in 51ceed0. Changes to NLog.MailKit.csproj:

  • <PublishRepositoryUrl>true</PublishRepositoryUrl> + <EmbedUntrackedSources>true</EmbedUntrackedSources> — activates SourceLink
  • <IncludeSymbols>true</IncludeSymbols> + <SymbolPackageFormat>snupkg</SymbolPackageFormat> — produces .snupkg with debug symbols
  • <ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild> — enables deterministic builds in CI (mirrors the DeterministicBuilds pattern)

nuget.yml updated to upload artifacts/*pkg (both .nupkg and .snupkg) and push both to NuGet.org.

Copilot AI changed the title Fix GitHub Actions NuGet publish: glob expansion, version number, and PR pre-release versioning Fix GitHub Actions NuGet publish: glob expansion, version number, PR pre-release versioning, and deterministic builds Mar 7, 2026
@304NotModified

Copy link
Copy Markdown
Member

@copilot I think dotnet nuget push automaticlly pushes snupkg? Or doesn't that work with this wildcard?

…ongside nupkg)

Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>

Copilot AI commented Mar 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot I think dotnet nuget push automaticlly pushes snupkg? Or doesn't that work with this wildcard?

Yes — dotnet nuget push automatically looks for and pushes the matching .snupkg alongside each .nupkg it pushes (same directory, same base name). The explicit *.snupkg line was redundant. Removed it in 71a4485, keeping just the single dotnet nuget push artifacts/*.nupkg command.

@304NotModified
304NotModified marked this pull request as ready for review March 7, 2026 21:41
@sonarqubecloud

sonarqubecloud Bot commented Mar 7, 2026

Copy link
Copy Markdown

@304NotModified
304NotModified merged commit ff5456b into master Mar 7, 2026
7 checks passed
@304NotModified
304NotModified deleted the copilot/fix-nuget-push-issues branch March 7, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants