Release Nuget #27
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release Nuget | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- "v[0-9]+.[0-9]+.[0-9]+" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
outputs: | |
version: ${{ steps.set_version.outputs.version }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup build environment | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '6.0.x' | |
- name: Set VERSION variable from latest tag | |
id: set_version | |
run: | | |
LATEST_TAG=$(git fetch --tags && git for-each-ref --sort=creatordate --format '%(refname)' refs/tags | tail -n 1) | |
if [[ "${LATEST_TAG}" == "" ]]; then echo "Unable to determine latest tag! Exiting"; exit 1; fi | |
echo "LATEST_TAG: ${LATEST_TAG}" | |
VERSION=${LATEST_TAG/refs\/tags\/v/} | |
echo "VERSION: ${VERSION}" | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
echo "::set-output name=version::${VERSION}" | |
- name: Set SOLUTION variable to point to solution file | |
run: | | |
SOLUTION=$(find . -name '*.sln' -printf "%p" -quit) | |
echo "SOLUTION=${SOLUTION}" >> $GITHUB_ENV | |
- name: Build | |
run: dotnet build --configuration Release /p:Version=${VERSION} ${SOLUTION} | |
- name: Test | |
run: dotnet test --configuration Release /p:Version=${VERSION} --no-build ${SOLUTION} | |
- name: Pack with debug symbols | |
run: dotnet pack --configuration Release /p:Version=${VERSION} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output . ${SOLUTION} | |
- name: Upload NuGet packages as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: nuget-packages | |
path: ./*.*nupkg | |
push-to-github: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download NuGet packages from artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: nuget-packages | |
- name: Push to GitHub Packages | |
run: dotnet nuget push *.${{ needs.build.outputs.version }}.nupkg --source https://nuget.pkg.github.com/${GITHUB_REPOSITORY%/*}/index.json --api-key ${GITHUB_TOKEN} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
push-to-nuget: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download NuGet packages from artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: nuget-packages | |
- name: Push to nuget.org | |
env: | |
NUGET_ORG_API_KEY: ${{secrets.NUGET_ORG_API_KEY}} | |
if: env.NUGET_ORG_API_KEY != null | |
run: dotnet nuget push *.${{ needs.build.outputs.version }}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_API_KEY }} | |