Skip to content

Publish Packages

Publish Packages #29

Workflow file for this run

name: Publish Packages
on:
workflow_run:
workflows: ["Build and Test"]
branches: [ main ]
types:
- completed
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get version
# Extract the version from the common.props' Version tag.
run: |
BUILD_VERSION=$(cat common.props | grep -Eo '<Version>(.*)</Version>' | sed -r 's|<Version>(.*)</Version>|\1|')
TAG_NAME=v$BUILD_VERSION
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
# git show-ref ... returns 0 (ok) when the tag exists, and 1 (error) when it doesn't. Use that to decide
# whether we want to publish (and tag) a new version.
if git show-ref --tags $TAG_NAME;
then
echo "Tag $TAG_NAME already exists."
echo "PUBLISH=0" >> $GITHUB_ENV
else
echo "Tag $TAG_NAME does not exist yet."
echo "PUBLISH=1" >> $GITHUB_ENV
fi
- name: Setup .NET
uses: actions/setup-dotnet@v3
# Only execute this when we want to/can publish anything.
if: env.PUBLISH == '1'
with:
dotnet-version: |
6.0.x
7.0.x
- name: Install dependencies
# Only execute this when we want to/can publish anything.
if: env.PUBLISH == '1'
run: dotnet restore
- name: Pack
# Only execute this when we want to/can publish anything.
if: env.PUBLISH == '1'
run: dotnet pack -c Release --no-restore -o .
- name: Publish Nuget packages
# Only execute this when we want to/can publish anything.
if: env.PUBLISH == '1'
run: dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json --skip-duplicate -n -k ${{secrets.NUGET_API_KEY}}
- name: Tag release
# Only execute this when we want to/can publish anything.
if: env.PUBLISH == '1'
run: |
echo "Tagging version $version as '${{ env.TAG_NAME }}'"
git tag "${{ env.TAG_NAME }}"
git push origin "${{ env.TAG_NAME }}"
echo 'Successfully tagged.'