Skip to content

Commit

Permalink
Create publish-nuget.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Chizaruu committed Dec 5, 2023
1 parent 79ff0b6 commit 2e6c15e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release to NuGet

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build -c Release --no-restore

- name: Test
run: dotnet test -c Release --no-build

- name: Extract Version from Tag
id: get_version
run: echo "VERSION=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_ENV

- name: Get Release Notes
id: get_release_notes
run: |
RELEASE_NOTES=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/tags/${GITHUB_REF#refs/tags/} \
| jq -r ".body")
echo "RELEASE_NOTES=$(echo "$RELEASE_NOTES")" >> $GITHUB_ENV
- name: Pack nugets
run: dotnet pack -c Release --no-build --output nupkgs /p:PackageVersion=${{ env.VERSION }} /p:PackageReleaseNotes="${{ env.RELEASE_NOTES }}"

- name: Push to NuGet
run: dotnet nuget push "nupkgs/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
if: github.ref == 'refs/heads/master' # only push from master branch

0 comments on commit 2e6c15e

Please sign in to comment.