publish-nuget #26
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: publish-nuget | |
on: | |
workflow_run: | |
workflows: [ "Build" ] | |
types: [ requested ] | |
branches: [ master ] | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version' | |
required: true | |
env: | |
BUILD_CONFIG: 'Release' | |
jobs: | |
pack: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Determine version | |
run: | | |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV | |
else | |
echo "VERSION=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_ENV | |
fi | |
echo "$GITHUB_ENV" | |
- name: 'Validate SemVer' | |
run: | | |
if [[ ! "$VERSION" =~ ^([0-9]+\.){2}[0-9]+$ ]]; then | |
echo "The version does not match the SemVer format (X.Y.Z). Please provide a valid version." | |
exit 1 | |
fi | |
- name: 'Print version' | |
run: | | |
echo "$VERSION" | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
lfs: true | |
fetch-depth: 0 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
- name: Pack | |
run: | | |
dotnet pack \ | |
--output ./artifacts \ | |
--configuration $BUILD_CONFIG \ | |
/p:PackageVersion=${{ env.VERSION }} | |
- name: Install dotnet-validate | |
run: dotnet tool install --global dotnet-validate --version 0.0.1-preview.304 | |
- name: Validate NuGet package | |
run: dotnet-validate package local ./artifacts/**.nupkg | |
- name: Publish packages | |
run: | | |
dotnet nuget push ./artifacts/**.nupkg \ | |
--source 'https://api.nuget.org/v3/index.json' \ | |
--api-key ${{secrets.NUGET_TOKEN}} \ | |
--skip-duplicate \ |