diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 887d320..a32d2f0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,6 +3,11 @@ name: NetDevPack - MASTER Publish on: push: branches: [ master ] + workflow_dispatch: + inputs: + version: + description: Existing release to publish again (e.g. 10.0.1). Builds tag v and pushes it to nuget.org. + required: true env: CURRENT_REPO_URL: https://github.com/${{ github.repository }} @@ -11,6 +16,7 @@ permissions: contents: write issues: write pull-requests: write + id-token: write # NuGet trusted publishing (OIDC) jobs: publish: @@ -23,6 +29,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + ref: ${{ inputs.version && format('v{0}', inputs.version) || github.sha }} - name: Setup .NET uses: actions/setup-dotnet@v4 @@ -43,6 +50,7 @@ jobs: - name: Semantic Release id: semantic + if: github.event_name == 'push' uses: cycjimmy/semantic-release-action@v4 with: semantic_version: 24 @@ -52,10 +60,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:PackageVersion=${{ 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:PackageVersion=${{ 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 -k ${{ secrets.NUGET_AUTH_TOKEN }} -s https://api.nuget.org/v3/index.json --skip-duplicate + 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