Skip to main content

Github - Deploy a Nuget Package on a new release

I have a small library that I created a few years ago to use PostgreSQL as a distributed cache in .NET core.

As I wanted to get more acquainted with Github and all it possibilities, I thought it was a good occasion to make some improvements and optimize the deployment process. (I manually pushed the first version of the package to NuGet.org).

Let’s see how we can automate this by combining the Release functionality in Github with Github actions.  

Create the Github actions workflow

Let’s first create a workflow that does the following:

  • Build the library
  • Create the NuGet package
  • Upload the NuGet package to NuGet.org

Therefore we go to our Github page and select Actions.

Choose New workflow.

We will not use one the suggested workflows but want to create our workflow from scratch so click on set up a workflow yourself.

Now we’ve finally arrived on the Edit workflow screen.

Replace the existing workflow definition with the following:

What is important to notice in the workflow above:

  • The workflow is triggered when we publish a new release(more about this later)
  • We use the tag_name value that can be specified during a release to update the package version:

dotnet pack --configuration Release --no-restore /p:Version=${{ github.event.release.tag_name }}

  • The api key required to push our package to NuGet.org is managed outside the workflow and stored as a Github secret using ‘NUGET_API_SECRET’ as its name:

dotnet nuget push **/*.nupkg --api-key ${{ secrets.NUGET_API_SECRET }} --source https://api.nuget.org/v3/index.json

Set the secret

To set the secret we need to go to Settings.

There we need to go the Secrets section and create a new secret using the New repository secret button.

Specify a name(in this case NUGET_API_SECRET) and a value:

Create a release

Now we can finally create a release. On the home page of your repo click on Releases on the right.

On the Releases page, click on the Draft a new release button.

Hit Choose a tag and enter a new release number here e.g. 2.0.2. What is important here is that this number is a valid NuGet package version number because it is this tag value that will be used inside our workflow.

Click on Publish release.

This should trigger the workflow and after a few minutes, you should see a succesfull run of the workflow on the Actions tab.

Popular posts from this blog

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t

DevToys–A swiss army knife for developers

As a developer there are a lot of small tasks you need to do as part of your coding, debugging and testing activities.  DevToys is an offline windows app that tries to help you with these tasks. Instead of using different websites you get a fully offline experience offering help for a large list of tasks. Many tools are available. Here is the current list: Converters JSON <> YAML Timestamp Number Base Cron Parser Encoders / Decoders HTML URL Base64 Text & Image GZip JWT Decoder Formatters JSON SQL XML Generators Hash (MD5, SHA1, SHA256, SHA512) UUID 1 and 4 Lorem Ipsum Checksum Text Escape / Unescape Inspector & Case Converter Regex Tester Text Comparer XML Validator Markdown Preview Graphic Color B