Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ name: Master - Publish packages
on:
push:
branches: [ master ]
workflow_dispatch:
inputs:
version:
description: Existing release to publish again (e.g. 8.0.0). Builds tag v<version> and pushes it to nuget.org.
required: true

env:
CURRENT_REPO_URL: https://github.com/${{ github.repository }}
Expand All @@ -11,6 +16,7 @@ permissions:
contents: write
issues: write
pull-requests: write
id-token: write # NuGet trusted publishing (OIDC)

jobs:
publish:
Expand All @@ -24,6 +30,7 @@ jobs:
uses: actions/checkout@v7
with:
fetch-depth: 0
ref: ${{ inputs.version && format('v{0}', inputs.version) || github.sha }}

- name: Setup .NET
uses: actions/setup-dotnet@v6
Expand All @@ -41,6 +48,7 @@ jobs:

- name: Semantic Release
id: semantic
if: github.event_name == 'push'
uses: cycjimmy/semantic-release-action@v4
with:
semantic_version: 24
Expand All @@ -51,10 +59,26 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Resolve version
id: version
if: github.event_name == 'workflow_dispatch' || steps.semantic.outputs.new_release_published == 'true'
env:
VERSION: ${{ inputs.version || steps.semantic.outputs.new_release_version }}
run: |
[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]] || { echo "::error::Invalid version '$VERSION'"; exit 1; }
echo "value=$VERSION" >> "$GITHUB_OUTPUT"

- name: Generate Package
if: steps.semantic.outputs.new_release_published == 'true'
run: dotnet pack -c Release -o out -p:Version=${{ steps.semantic.outputs.new_release_version }} -p:RepositoryUrl=${{ env.CURRENT_REPO_URL }}
if: steps.version.outputs.value != ''
run: dotnet pack -c Release -o out -p:Version=${{ steps.version.outputs.value }} -p:RepositoryUrl=${{ env.CURRENT_REPO_URL }}

- name: NuGet login (trusted publishing)
id: nuget
if: steps.version.outputs.value != ''
uses: NuGet/login@v1
with:
user: ${{ vars.NUGET_USER }}

- name: Publish the package to nuget.org
if: steps.semantic.outputs.new_release_published == 'true'
run: dotnet nuget push ./out/*.nupkg --skip-duplicate -k ${{ secrets.NUGET_AUTH_TOKEN }} -s https://api.nuget.org/v3/index.json
if: steps.version.outputs.value != ''
run: dotnet nuget push ./out/*.nupkg --skip-duplicate -k ${{ steps.nuget.outputs.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
Loading