diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index ee87ee1..17731d8 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -11,7 +11,7 @@ on: workflow_dispatch: jobs: - build-and-publish: + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -25,10 +25,41 @@ jobs: run: dotnet build --configuration Release --no-restore - name: Pack run: dotnet pack --no-build --configuration Release PAYNLSDK/PayNLSdk.csproj --output . - - name: Push Nuget - if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/release/v') }} + - name: Upload packages + uses: actions/upload-artifact@v4 + with: + name: nuget-packages + path: | + *.nupkg + *.snupkg + + publish: + runs-on: ubuntu-latest + needs: build + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/release/v') + permissions: + id-token: write + contents: read + steps: + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + - name: Download packages + uses: actions/download-artifact@v4 + with: + name: nuget-packages + - name: Get NuGet OIDC token + id: oidc + uses: actions/github-script@v7 + with: + script: | + const token = await core.getIDToken('api.nuget.org'); + core.setSecret(token); + core.setOutput('token', token); + - name: Push to NuGet env: - NUGET_API_KEY: ${{ secrets.NUGET_PUBLISH_KEY }} + NUGET_TOKEN: ${{ steps.oidc.outputs.token }} run: | - dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key "$NUGET_API_KEY" --skip-duplicate - dotnet nuget push *.snupkg --source https://api.nuget.org/v3/index.json --api-key "$NUGET_API_KEY" --skip-duplicate + dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key "$NUGET_TOKEN" --skip-duplicate + dotnet nuget push *.snupkg --source https://api.nuget.org/v3/index.json --api-key "$NUGET_TOKEN" --skip-duplicate