|
7 | 7 | - RELEASE_NOTES.md |
8 | 8 | - .github/workflows/publish.yml |
9 | 9 | jobs: |
| 10 | + release-check: |
| 11 | + name: Check release version |
| 12 | + runs-on: windows-latest |
| 13 | + permissions: |
| 14 | + contents: read |
| 15 | + outputs: |
| 16 | + should_publish: ${{ steps.compare.outputs.should_publish }} |
| 17 | + release_notes_version: ${{ steps.compare.outputs.release_notes_version }} |
| 18 | + latest_release_version: ${{ steps.compare.outputs.latest_release_version }} |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + - name: Install Dotnet |
| 23 | + uses: actions/setup-dotnet@v4 |
| 24 | + with: |
| 25 | + global-json-file: global.json |
| 26 | + - name: Restore Tools |
| 27 | + run: dotnet tool restore |
| 28 | + - name: Compare release versions |
| 29 | + id: compare |
| 30 | + shell: pwsh |
| 31 | + env: |
| 32 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + run: | |
| 34 | + function Normalize-Version([string] $Version) { |
| 35 | + if ([string]::IsNullOrWhiteSpace($Version)) { |
| 36 | + return "" |
| 37 | + } |
| 38 | +
|
| 39 | + return $Version.Trim() -replace '^[vV]', '' |
| 40 | + } |
| 41 | +
|
| 42 | + $parseOutput = & dotnet aardpack --parse-only |
| 43 | + if ($LASTEXITCODE -ne 0) { |
| 44 | + throw "dotnet aardpack --parse-only failed with exit code $LASTEXITCODE." |
| 45 | + } |
| 46 | +
|
| 47 | + $releaseNotesVersion = ($parseOutput | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Last 1).Trim() |
| 48 | + if ([string]::IsNullOrWhiteSpace($releaseNotesVersion)) { |
| 49 | + throw "dotnet aardpack --parse-only did not return a release notes version." |
| 50 | + } |
| 51 | +
|
| 52 | + $headers = @{ |
| 53 | + Authorization = "Bearer $env:GITHUB_TOKEN" |
| 54 | + Accept = "application/vnd.github+json" |
| 55 | + "X-GitHub-Api-Version" = "2022-11-28" |
| 56 | + "User-Agent" = "github-actions" |
| 57 | + } |
| 58 | +
|
| 59 | + $latestReleaseVersion = "" |
| 60 | + $shouldPublish = "true" |
| 61 | + try { |
| 62 | + $latestRelease = Invoke-RestMethod ` |
| 63 | + -Uri "https://api.github.com/repos/${{ github.repository }}/releases/latest" ` |
| 64 | + -Headers $headers |
| 65 | + $latestReleaseVersion = [string] $latestRelease.tag_name |
| 66 | +
|
| 67 | + if ((Normalize-Version $releaseNotesVersion) -eq (Normalize-Version $latestReleaseVersion)) { |
| 68 | + $shouldPublish = "false" |
| 69 | + } |
| 70 | + } |
| 71 | + catch { |
| 72 | + $statusCode = $_.Exception.Response.StatusCode.value__ |
| 73 | + if ($statusCode -eq 404) { |
| 74 | + Write-Host "No latest GitHub release found. Continuing publish workflow." |
| 75 | + } |
| 76 | + else { |
| 77 | + throw |
| 78 | + } |
| 79 | + } |
| 80 | +
|
| 81 | + "release_notes_version=$releaseNotesVersion" >> $env:GITHUB_OUTPUT |
| 82 | + "latest_release_version=$latestReleaseVersion" >> $env:GITHUB_OUTPUT |
| 83 | + "should_publish=$shouldPublish" >> $env:GITHUB_OUTPUT |
| 84 | +
|
| 85 | + "## Publish release check" >> $env:GITHUB_STEP_SUMMARY |
| 86 | + "" >> $env:GITHUB_STEP_SUMMARY |
| 87 | + "- Release notes version: ``$releaseNotesVersion``" >> $env:GITHUB_STEP_SUMMARY |
| 88 | + "- Latest GitHub release: ``$latestReleaseVersion``" >> $env:GITHUB_STEP_SUMMARY |
| 89 | + "- Should publish: ``$shouldPublish``" >> $env:GITHUB_STEP_SUMMARY |
| 90 | +
|
10 | 91 | pack: |
11 | 92 | name: Package |
12 | 93 | runs-on: windows-latest |
13 | | - steps: |
| 94 | + needs: release-check |
| 95 | + if: needs.release-check.outputs.should_publish == 'true' |
| 96 | + steps: |
14 | 97 | - name: Checkout |
15 | 98 | uses: actions/checkout@v4 |
16 | 99 | - name: Install Dotnet |
|
0 commit comments