Deploying NuGet package using GitHub Actions (without any marketplace actions)

06 Oct 2020 by Kolappan N

GitHub Actions is one of the things I came to love about GitHub. Managing CI/CD within your code repo is a great thing. I started using GitHub Actions for many things from label managemnet to publishing this website. So, I decided to try out publishing a Nuget package using GitHub Actions.

It turned out to be quite easy and dotnet cli has support for publishing Nuget package using the dotnet nuget push command. It was actually quite surprising that some of the top search results for “Publishing Nuget package using GitHub actions” turned out to use a third party action. The problem with this is that the third party actions might not be updated regularly and this is a sigle line command that I don’t want to use a another action for it.

  1. Go the API Keys page in Nuget website.
  2. Create a new API Key by Entering a name, time-period and selecting packages. It is best to create a separate API Key for each package. Also note that the maximum duration of a API Key is 1 year, so you will have to update the key atleast once a year.
  3. Now copy this Key.
  4. Go to the Settings page of your GitHub repo and go to the Secrets setting.
  5. Click on New Secret and paste the previously copied key and provide a name like NUGET_KEY and save it.
    Screenshot of GitHub Settings Page
    GitHub Settings - Secrets
  6. Create a pipeline CD.yml in the .github/workflows folder.
  7. The the workflow,
    • build the Nuget package
    • Naviagate to the bin/release directory
    • Use the following command
      dotnet nuget push "*.nupkg" -s -k $

Here is my CD.yml file,

name: CD

  # Trigger CD when a release is published
    types: [published]

    runs-on: windows-latest
    - name: Checkout
      uses: actions/checkout@v2.3.3
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1.7.2
        dotnet-version: 3.1.402
    - name: Install dependencies
      run: |
        cd ./src
        dotnet restore
    - name: Build
      run: |
        cd ./src
        dotnet build --configuration Release --no-restore
    - name: Test
      run: |
       cd ./src
       dotnet test --no-restore --verbosity normal
    - name: Publish Nuget
      run: |
        cd ./src/nk.logger.csv/bin/Release/
        dotnet nuget push "*.nupkg" -s -k $
Tags: CI/CD GitHub Nuget View Blog Archive

Loading Comments