Publish NuGet #6
This file contains hidden or 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: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| publish: | |
| runs-on: windows-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 8.0.x | |
| - name: Restore | |
| run: dotnet restore YCode.Designer.Fluxo/YCode.Designer.Fluxo.csproj | |
| - name: Build | |
| run: dotnet build YCode.Designer.Fluxo/YCode.Designer.Fluxo.csproj --configuration Release --no-restore /p:ContinuousIntegrationBuild=true | |
| - name: Pack | |
| run: dotnet pack YCode.Designer.Fluxo/YCode.Designer.Fluxo.csproj --configuration Release --no-build --output artifacts /p:ContinuousIntegrationBuild=true /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg | |
| - name: Determine publishing mode | |
| id: publish-mode | |
| shell: bash | |
| env: | |
| NUGET_USER: ${{ vars.NUGET_USER }} | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| run: | | |
| if [[ -n "$NUGET_API_KEY" ]]; then | |
| echo "mode=classic" >> "$GITHUB_OUTPUT" | |
| elif [[ -n "$NUGET_USER" ]]; then | |
| echo "mode=trusted" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Configure either repo variable NUGET_USER for Trusted Publishing or secret NUGET_API_KEY for classic publishing." | |
| exit 1 | |
| fi | |
| - name: NuGet login with Trusted Publishing | |
| if: ${{ steps.publish-mode.outputs.mode == 'trusted' }} | |
| id: nuget-login | |
| uses: NuGet/login@v1 | |
| with: | |
| user: ${{ vars.NUGET_USER }} | |
| - name: Push package with Trusted Publishing | |
| if: ${{ steps.publish-mode.outputs.mode == 'trusted' }} | |
| shell: pwsh | |
| run: | | |
| Get-ChildItem artifacts -Filter *.nupkg | ForEach-Object { | |
| dotnet nuget push $_.FullName --api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" --source "https://api.nuget.org/v3/index.json" --skip-duplicate | |
| } | |
| Get-ChildItem artifacts -Filter *.snupkg | ForEach-Object { | |
| dotnet nuget push $_.FullName --api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" --source "https://api.nuget.org/v3/index.json" --skip-duplicate | |
| } | |
| - name: Push package with classic API key | |
| if: ${{ steps.publish-mode.outputs.mode == 'classic' }} | |
| shell: pwsh | |
| run: | | |
| Get-ChildItem artifacts -Filter *.nupkg | ForEach-Object { | |
| dotnet nuget push $_.FullName --api-key "${{ secrets.NUGET_API_KEY }}" --source "https://api.nuget.org/v3/index.json" --skip-duplicate | |
| } | |
| Get-ChildItem artifacts -Filter *.snupkg | ForEach-Object { | |
| dotnet nuget push $_.FullName --api-key "${{ secrets.NUGET_API_KEY }}" --source "https://api.nuget.org/v3/index.json" --skip-duplicate | |
| } | |
| - name: Configure GitHub Packages source | |
| shell: pwsh | |
| run: | | |
| dotnet nuget remove source github | Out-Null 2>$null | |
| dotnet nuget add source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" ` | |
| --name github ` | |
| --username "${{ github.actor }}" ` | |
| --password "${{ secrets.GITHUB_TOKEN }}" ` | |
| --store-password-in-clear-text | |
| - name: Push package to GitHub Packages | |
| shell: pwsh | |
| run: | | |
| Get-ChildItem artifacts -Filter *.nupkg | ForEach-Object { | |
| dotnet nuget push $_.FullName --source github --api-key "${{ secrets.GITHUB_TOKEN }}" --skip-duplicate | |
| } | |
| - name: Upload published artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: published-nuget-package | |
| path: | | |
| artifacts/*.nupkg | |
| artifacts/*.snupkg |