Release and Publish NuGet #7
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: Release and Publish NuGet | |
| on: | |
| release: | |
| types: [created] | |
| workflow_dispatch: | |
| env: | |
| DOTNET_NOLOGO: true | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | |
| DOTNET_CLI_TELEMETRY_OPTOUT: true | |
| NUGET_AUTH_TOKEN: ${{secrets.PUBLISH_TO_NUGET_ORG}} | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| shell: pwsh | |
| steps: | |
| - run: echo "π The job was automatically triggered by a ${{ github.event_name }} event." | |
| - run: echo "π§ This job is now running on a ${{ runner.os }} server hosted by GitHub!" | |
| - run: echo "π The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| - run: echo "π‘ The ${{ github.repository }} repository has been cloned to the runner." | |
| - name: Cache NuGet packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.nuget/packages | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '8.0.403' | |
| - name: Extract version from Directory.Build.props | |
| id: extract_version | |
| run: | | |
| [xml]$xml = Get-Content -Path "Directory.Build.props" | |
| $version = $xml.SelectSingleNode("//TimeWarpStateVersion").InnerText | |
| echo "Extracted version (raw): '$version'" | |
| $version = $version.Trim() | |
| echo "Extracted version (trimmed): '$version'" | |
| echo "version=$version" >> $env:GITHUB_OUTPUT | |
| shell: pwsh | |
| - name: Validate release version matches tag | |
| run: | | |
| $releaseVersion = "${{ steps.extract_version.outputs.version }}" | |
| $tagName = "${{ github.event.release.tag_name }}" | |
| echo "Release version: $releaseVersion" | |
| echo "Tag name: $tagName" | |
| echo "Event name: ${{ github.event_name }}" | |
| # Only validate tag match for actual release events, not manual dispatch | |
| if ("${{ github.event_name }}" -eq "release") { | |
| # Strip 'v' prefix from tag name if present for comparison | |
| $tagNameForComparison = $tagName | |
| if ($tagName.StartsWith("v")) { | |
| $tagNameForComparison = $tagName.Substring(1) | |
| } | |
| if ($releaseVersion -ne $tagNameForComparison) { | |
| throw "Release version ($releaseVersion) does not match tag name ($tagName - stripped: $tagNameForComparison)" | |
| } | |
| echo "β Release version matches tag name" | |
| } else { | |
| echo "β οΈ Manual dispatch - skipping tag validation" | |
| } | |
| shell: pwsh | |
| - name: Run BuildNuGets.ps1 | |
| run: | | |
| .\BuildNuGets.ps1 | |
| working-directory: ${{ github.workspace }} | |
| - name: Publish TimeWarp.State | |
| run: | | |
| cd Source/TimeWarp.State/bin/Release | |
| if (!(Test-Path "TimeWarp.State.*.nupkg")) { | |
| throw "NuGet package not found for TimeWarp.State" | |
| } | |
| dotnet nuget push TimeWarp.State.*.nupkg --skip-duplicate --source https://api.nuget.org/v3/index.json --api-key ${{secrets.PUBLISH_TO_NUGET_ORG}} | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "Failed to publish TimeWarp.State" | |
| } | |
| working-directory: ${{ github.workspace }} | |
| - name: Publish TimeWarp.State.Plus | |
| run: | | |
| cd Source/TimeWarp.State.Plus/bin/Release | |
| if (!(Test-Path "TimeWarp.State.Plus.*.nupkg")) { | |
| throw "NuGet package not found for TimeWarp.State.Plus" | |
| } | |
| dotnet nuget push TimeWarp.State.Plus.*.nupkg --skip-duplicate --source https://api.nuget.org/v3/index.json --api-key ${{secrets.PUBLISH_TO_NUGET_ORG}} | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "Failed to publish TimeWarp.State.Plus" | |
| } | |
| working-directory: ${{ github.workspace }} | |
| - name: Publish TimeWarp.State.Policies | |
| run: | | |
| cd Source/TimeWarp.State.Policies/bin/Release | |
| if (!(Test-Path "TimeWarp.State.Policies.*.nupkg")) { | |
| throw "NuGet package not found for TimeWarp.State.Policies" | |
| } | |
| dotnet nuget push TimeWarp.State.Policies.*.nupkg --skip-duplicate --source https://api.nuget.org/v3/index.json --api-key ${{secrets.PUBLISH_TO_NUGET_ORG}} | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "Failed to publish TimeWarp.State.Policies" | |
| } | |
| working-directory: ${{ github.workspace }} | |
| - run: echo "π This job's status is ${{ job.status }}." |