Skip to content

Instantly share code, notes, and snippets.

@ashleybot
Created November 18, 2022 14:20
Show Gist options
  • Save ashleybot/85028dfddd8198c9f805700fdb00d44c to your computer and use it in GitHub Desktop.
Save ashleybot/85028dfddd8198c9f805700fdb00d44c to your computer and use it in GitHub Desktop.
GitHub Action workflow for building and deploying .NET NuGet Packages to GitHub repo
# This is a workflow that is triggered either by a semver tag on a commit or by running manually
# Your own information will need to be updated in the following example, re: [Your repo] and [Your project]
#
# If you are restoring/reading packages from other repos within your GitHub account,
# don't forget to update the scope of the default GITUB_TOKEN or this workflow will fail on restore:
# * Go to your packages view and click on the required package
# * If you are working in an organization context, on the right-side menu, click on "Package settings" and give permissions to your consuming repo to read.
# * For personal accounts, the menu is one the left-hand side.
name: Package release
on:
workflow_dispatch:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
pack:
name: Package and publish
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
source-url: https://nuget.pkg.github.com/[Your repo]/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# There is a bug with building and packing at the solution level with the GitHub runner
# and those issues are resolved by targeting each project individually
- name: Pack [Your project]
run: dotnet pack [Your project] -c Release -o .
# The wildcard here will gather all NuGet packages created in the previous step
- name: Push packages
run: dotnet nuget push [Your project].*.nupkg --skip-duplicate --no-symbols
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment