|
| 1 | +name: Publish Release to NuGet |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +env: |
| 7 | + Configuration: Release |
| 8 | + DOTNET_CLI_TELEMETRY_OPTOUT: true |
| 9 | + DOTNET_NOLOGO: true |
| 10 | + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: true |
| 11 | + TERM: xterm-256color |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: nuget-publish |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +jobs: |
| 18 | + publish: |
| 19 | + runs-on: windows-latest |
| 20 | + name: Publish to NuGet |
| 21 | + environment: nuget |
| 22 | + permissions: |
| 23 | + contents: write |
| 24 | + id-token: write |
| 25 | + steps: |
| 26 | + - name: Checkout git repository |
| 27 | + uses: actions/checkout@v6 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - uses: actions/setup-dotnet@v5 |
| 32 | + with: |
| 33 | + dotnet-version: | |
| 34 | + 6.x |
| 35 | + 8.x |
| 36 | +
|
| 37 | + - name: Determine package version |
| 38 | + id: version |
| 39 | + shell: pwsh |
| 40 | + run: | |
| 41 | + $v = (dotnet msbuild Core/Core.csproj -getProperty:PackageVersion).Trim() |
| 42 | + if (-not $v) { throw "PackageVersion could not be determined" } |
| 43 | + "version=$v" >> $env:GITHUB_OUTPUT |
| 44 | + Write-Host "Publishing version $v" |
| 45 | +
|
| 46 | + - name: Run tests |
| 47 | + run: dotnet test --verbosity normal |
| 48 | + |
| 49 | + - name: Restore .NET tools |
| 50 | + run: dotnet tool restore |
| 51 | + |
| 52 | + - name: Create and validate Codecrete.SwissQRBill.Core package |
| 53 | + run: dotnet pack Core/Core.csproj --verbosity normal |
| 54 | + |
| 55 | + - name: Create and validate Codecrete.SwissQRBill.Generator package |
| 56 | + run: dotnet pack PixelCanvas/PixelCanvas.csproj --verbosity normal |
| 57 | + |
| 58 | + - name: Create and validate Codecrete.SwissQRBill.Windows package |
| 59 | + run: dotnet pack Windows/Windows.csproj --verbosity normal |
| 60 | + |
| 61 | + - name: Create API documentation |
| 62 | + run: dotnet docfx docfx/docfx.json |
| 63 | + |
| 64 | + - name: Zip API documentation |
| 65 | + shell: pwsh |
| 66 | + run: | |
| 67 | + Compress-Archive -Path docfx/bin/_site/* -DestinationPath API.Documentation.zip -Force |
| 68 | +
|
| 69 | + - name: NuGet login (OIDC to temporary API key) |
| 70 | + uses: NuGet/login@v1 |
| 71 | + id: login |
| 72 | + with: |
| 73 | + user: ${{ secrets.NUGET_USER }} |
| 74 | + |
| 75 | + - name: Publish Codecrete.SwissQRBill.Core to NuGet |
| 76 | + run: > |
| 77 | + dotnet nuget push |
| 78 | + Core/bin/Release/Codecrete.SwissQRBill.Core.${{ steps.version.outputs.version }}.nupkg |
| 79 | + --source https://api.nuget.org/v3/index.json |
| 80 | + --api-key ${{ steps.login.outputs.NUGET_API_KEY }} |
| 81 | + --skip-duplicate |
| 82 | +
|
| 83 | + - name: Publish Codecrete.SwissQRBill.Generator to NuGet |
| 84 | + run: > |
| 85 | + dotnet nuget push |
| 86 | + PixelCanvas/bin/Release/Codecrete.SwissQRBill.Generator.${{ steps.version.outputs.version }}.nupkg |
| 87 | + --source https://api.nuget.org/v3/index.json |
| 88 | + --api-key ${{ steps.login.outputs.NUGET_API_KEY }} |
| 89 | + --skip-duplicate |
| 90 | +
|
| 91 | + - name: Publish Codecrete.SwissQRBill.Windows to NuGet |
| 92 | + run: > |
| 93 | + dotnet nuget push |
| 94 | + Windows/bin/Release/Codecrete.SwissQRBill.Windows.${{ steps.version.outputs.version }}.nupkg |
| 95 | + --source https://api.nuget.org/v3/index.json |
| 96 | + --api-key ${{ steps.login.outputs.NUGET_API_KEY }} |
| 97 | + --skip-duplicate |
| 98 | +
|
| 99 | + - name: Create and push release tag |
| 100 | + shell: pwsh |
| 101 | + run: | |
| 102 | + $tag = "v${{ steps.version.outputs.version }}" |
| 103 | + if (git ls-remote --tags origin "refs/tags/$tag") { |
| 104 | + Write-Host "Tag $tag already exists - skipping" |
| 105 | + exit 0 |
| 106 | + } |
| 107 | + git config user.name "github-actions[bot]" |
| 108 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 109 | + git tag -a $tag -m "Release $tag" |
| 110 | + if ($LASTEXITCODE) { exit $LASTEXITCODE } |
| 111 | + git push origin "refs/tags/$tag" |
0 commit comments