Modifying the version of a nupkg in github actions pipeline

Viewed 437

We're running into a problem with our NuGet pipelines on GitHub. We have it set to run a step to build the project, and NuGet pack it with a specific version (the RC version generally something like 1.0.0-rc.1) this works fine, and we can then pass the artifact to the RC step and upload it to where it needs to go using NuGet push.

The problem comes in when we're trying to then move that package from RC into GA (the desired flow being: build > RC > GA), we want to take the same exact package and modify the version so it no longer has the RC tag (stripping it down to 1.0.0), however I haven't been able to find a clean way to do this. The current workaround is to take the exact same commit and rebuild it with the GA version but we would much rather just modify the RC version to have the correct version number.

Is there a NuGet command or something that I'm missing to accomplish this? I considered downloading the nupkg file, installing it to an output directory and then repacking it with the correct version but I was hoping there may be a better way.

1 Answers

Few options using Action Update Helpers,

the diff. is helpful depending on what you are publishing, nuget libs you are publishing vs. custom libs - since you did not share your sample yaml/code, I am sharing both.


Option 1: use the Release Tag Updater helper lib. from here or a newer one here from Github or Market Place

Helpful for your own, i.e if you publish NUGET libs

Update helpers for Github Actions Release configuration Aws Azure pipelines

In your yaml configuration file for github actions, in the stage that you want to rename you can use the tag option with passed in values

# Filepath of the project to be packaged, relative to root of repository
PROJECT_FILE_PATH: YourProject/YourProject.csproj
          
# NuGet package id, used for version detection & defaults to project name
# PACKAGE_NAME: YourProject

# API key to authenticate with NuGet server
NUGET_KEY: ${{secrets.NUGET_API_KEY}}

# NuGet server uri hosting the packages, defaults to https://api.nuget.org
# NUGET_SOURCE: https://api.nuget.org
          
# Filepath with version info, relative to root of repository & defaults to PROJECT_FILE_PATH
# VERSION_FILE_PATH: Directory.Build.props

# Regex pattern to extract version info in a capturing group
# VERSION_REGEX: <Version>(.*)<\/Version>
          
# Useful with external providers like Nerdbank.GitVersioning, ignores VERSION_FILE_PATH & VERSION_REGEX
# VERSION_STATIC: 1.0.0

# Flag to toggle git tagging, enabled by default
# TAG_COMMIT: true

# Format of the git tag, [*] gets replaced with actual version
# TAG_FORMAT: v*

Option 2: Modify/roll your own yaml properties file

IMHO for your Custom Libs, i.e. if you need something beyond the standard yaml properties and you need some more.

For e.g. in your final release stage, use the yaml deploy section to name it what you want using this lib.

   # your previous yaml code ... there should be a section with the below tage configured and it will look for it an update.

conditional update to your local yaml file


The main differences is one targets the major and minor release of the tag names and helpful for Nuget packages.

The second one allows you to create something beyond and custom as a tag.

Related