Skip to content

Add GitHub Actions workflow for automated NuGet releases with multi-platform builds#1095

Merged
adamhathcock merged 19 commits intomasterfrom
copilot/add-github-action-nuget-release
Jan 3, 2026
Merged

Add GitHub Actions workflow for automated NuGet releases with multi-platform builds#1095
adamhathcock merged 19 commits intomasterfrom
copilot/add-github-action-nuget-release

Conversation

Copy link
Contributor

Copilot AI commented Jan 1, 2026

Implements automated NuGet publishing for the master and release branches with automatic version detection and prerelease support. The workflow runs on both Windows and Ubuntu for comprehensive testing, with NuGet publishing only on Windows. All version detection, file updates, and publishing logic is implemented in C# in the build project. GitHub releases are created manually.

Workflow Behavior

Version Detection (C# implementation):

  • Tagged commits → stable release (version from tag)
  • Untagged commits → prerelease with next minor version and format {NEXT_MINOR_VERSION}-beta.{COMMIT_COUNT}

Pipeline:

  • Triggers on both master and release branch pushes
  • Triggers on version tag pushes (format: MAJOR.MINOR.PATCH)
  • Builds and tests on Windows and Ubuntu in parallel (matrix strategy)
  • Updates version in SharpCompress.csproj using C# build target
  • Pushes to NuGet.org using NUGET_API_KEY secret (Windows only)
  • Uses --skip-duplicate for idempotency

Implementation

All logic is implemented in C# as build targets in build/Program.cs:

  • determine-version - Detects version from git tags, increments minor version for prereleases, and outputs to GitHub Actions
  • update-version - Updates VersionPrefix, AssemblyVersion, and FileVersion in project file
  • push-to-nuget - Publishes packages to NuGet.org

The workflow calls these C# targets instead of using bash scripts. Cross-platform compatible (Windows/Linux). Matrix builds ensure cross-platform compatibility while keeping NuGet publishing exclusive to Windows to prevent duplicate publishes.

Example Usage

# Stable release - Method 1: Push tag directly
git tag 0.43.0
git push origin 0.43.0
# → Workflow triggers, builds on Windows and Ubuntu, publishes SharpCompress 0.43.0 (Windows only)

# Stable release - Method 2: Push to branch then tag
git checkout master  # or release
git push origin master
git tag 0.43.0
git push origin 0.43.0
# → Workflow triggers on both branch push and tag push

# Prerelease (if last tag is 0.42.x)
git checkout master  # or release
git push origin master  # or release
# → Builds on Windows and Ubuntu, publishes SharpCompress 0.43.0-beta.456 (Windows only)

Setup Required

Add NUGET_API_KEY secret to repository settings with NuGet.org API key.

Files Added/Modified

  • .github/workflows/nuget-release.yml - Multi-platform workflow with matrix strategy calling C# build targets, triggers on branch and tag pushes
  • .github/workflows/NUGET_RELEASE.md - Setup and usage documentation with build targets info
  • .github/workflows/TESTING.md - Testing procedures
  • build/Program.cs - Added 3 new build targets with version detection and publishing logic
  • .gitignore - Added artifacts/ directory
Original prompt

This section details on the original issue you should resolve

<issue_title>GitHub action for nuget releases</issue_title>
<issue_description>Create a GitHub action that builds like things currently do but also pushes a build to nuget.

This is on the release branch. If the release isn't tagged then it's a prerelease version based on the last tag</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Copilot AI and others added 2 commits January 1, 2026 10:47
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GitHub action for NuGet releases Add GitHub Actions workflow for automated NuGet releases Jan 1, 2026
Copilot AI requested a review from adamhathcock January 1, 2026 10:51
@adamhathcock
Copy link
Owner

@copilot move any bash code to c# in the build project then call the step from the action

- Added determine-version, update-version, push-to-nuget, and create-release build targets
- All version detection and publishing logic now in build/Program.cs
- Workflow calls C# build targets instead of bash scripts
- Updated documentation to reflect C# implementation

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 1, 2026

@copilot move any bash code to c# in the build project then call the step from the action

Done! I've moved all the bash logic to C# in the build project.

The following build targets were added to build/Program.cs:

  • determine-version - Detects version from git tags
  • update-version - Updates project file versions using regex
  • push-to-nuget - Publishes packages to NuGet.org
  • create-release - Creates GitHub releases

The workflow now simply calls these C# targets instead of running bash scripts. All version detection, file manipulation, and publishing logic is now in C#.

Commit: 9238cf1

Copilot AI and others added 2 commits January 1, 2026 11:48
- Replaced bash-specific Process execution with SimpleExec's ReadAsync
- Fixed git command execution to work on Windows and Linux
- Added comment about API key handling in push-to-nuget target
- Removed unused System.Diagnostics import

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
@adamhathcock adamhathcock marked this pull request as ready for review January 1, 2026 21:03
Copilot AI review requested due to automatic review settings January 1, 2026 21:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements automated NuGet package publishing for the SharpCompress project with intelligent version detection and prerelease support. The workflow triggers on pushes to the release branch, automatically determining whether to publish stable or prerelease packages based on git tags.

Key changes include:

  • Version detection logic: C# implementation that distinguishes between tagged releases (stable) and untagged commits (prerelease with format {LAST_TAG}-preview.{COMMIT_COUNT}+{SHA})
  • Build targets: Four new C# build targets (determine-version, update-version, push-to-nuget, create-release) that handle all version detection, file updates, and publishing
  • GitHub Actions workflow: Orchestrates the build, test, and publish pipeline using the new C# targets with proper secret management

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
.github/workflows/nuget-release.yml New workflow that automates NuGet publishing on the release branch with version detection, build/test, and conditional GitHub release creation
build/Program.cs Adds 4 new build targets for version detection, project file updates, NuGet publishing, and GitHub release creation with git-based version logic
.github/workflows/NUGET_RELEASE.md Comprehensive documentation explaining workflow behavior, setup requirements, usage examples, and troubleshooting guidance
.github/workflows/TESTING.md Testing procedures and verification steps for both prerelease and stable release scenarios
.gitignore Adds artifacts/ directory to ignore list for build output

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@adamhathcock
Copy link
Owner

@copilot change the untagged versioning to only use commit count and not the short sha

- Changed prerelease version format from {LAST_TAG}-preview.{COMMIT_COUNT}+{SHA} to {LAST_TAG}-preview.{COMMIT_COUNT}
- Updated documentation in NUGET_RELEASE.md and TESTING.md to reflect the change
- Removed git rev-parse call for short SHA since it's no longer needed

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 2, 2026

@copilot change the untagged versioning to only use commit count and not the short sha

Done! Changed the prerelease version format from {LAST_TAG}-preview.{COMMIT_COUNT}+{SHA} to {LAST_TAG}-preview.{COMMIT_COUNT}.

Updated:

  • Version generation logic in build/Program.cs
  • Documentation in NUGET_RELEASE.md and TESTING.md
  • Removed the git rev-parse call for short SHA

Example prerelease version now: 0.42.1-preview.123

Commit: 7f71f76

- Changed example from 0.42.2-test to 0.42.2 to match regex pattern
- Added note that tags must be pure semantic versions (MAJOR.MINOR.PATCH)
- Addresses bot review feedback about documentation inconsistency

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
@adamhathcock
Copy link
Owner

@copilot instead of using last tag, use next tag which is a minor release. Change preview to beta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitHub action for nuget releases

2 participants

Comments