[PR #1095] Add GitHub Actions workflow for automated NuGet releases with multi-platform builds #1525

Open
opened 2026-01-29 22:20:58 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/adamhathcock/sharpcompress/pull/1095

State: closed
Merged: Yes


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.

**Original Pull Request:** https://github.com/adamhathcock/sharpcompress/pull/1095 **State:** closed **Merged:** Yes --- 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 ```bash # 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 <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *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) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes adamhathcock/sharpcompress#1094 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
claunia added the pull-request label 2026-01-29 22:20:58 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1525