|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ['v*'] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + release: |
| 12 | + runs-on: windows-latest |
| 13 | + steps: |
| 14 | + - name: Check out tagged source |
| 15 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 16 | + with: |
| 17 | + persist-credentials: false |
| 18 | + - name: Install .NET SDK |
| 19 | + uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 |
| 20 | + with: |
| 21 | + global-json-file: global.json |
| 22 | + - name: Verify tag matches package version |
| 23 | + shell: pwsh |
| 24 | + env: |
| 25 | + RELEASE_TAG: ${{ github.ref_name }} |
| 26 | + run: | |
| 27 | + $project = [xml](Get-Content -LiteralPath Directory.Build.props -Raw) |
| 28 | + $version = $project.Project.PropertyGroup.VersionPrefix | Select-Object -First 1 |
| 29 | + if ($env:RELEASE_TAG -ne "v$version") { |
| 30 | + throw "Tag '$env:RELEASE_TAG' does not match VersionPrefix '$version'." |
| 31 | + } |
| 32 | + - name: Build and verify release |
| 33 | + shell: pwsh |
| 34 | + run: .\build.ps1 -Configuration Release -BuildMsi $true |
| 35 | + - name: Preserve release artifacts |
| 36 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 37 | + with: |
| 38 | + name: resodrive-${{ github.ref_name }} |
| 39 | + path: | |
| 40 | + artifacts/win-x64/*.zip |
| 41 | + artifacts/win-x64/*.zip.sha256 |
| 42 | + artifacts/win-x64/*.msi |
| 43 | + artifacts/win-x64/*.msi.sha256 |
| 44 | + artifacts/win-x64/*.exe |
| 45 | + artifacts/win-x64/*.exe.sha256 |
| 46 | + if-no-files-found: error |
| 47 | + - name: Publish GitHub release |
| 48 | + shell: pwsh |
| 49 | + env: |
| 50 | + GH_TOKEN: ${{ github.token }} |
| 51 | + RELEASE_TAG: ${{ github.ref_name }} |
| 52 | + run: | |
| 53 | + $releaseDirectory = 'artifacts\win-x64' |
| 54 | + $versionedSetup = Get-ChildItem -LiteralPath $releaseDirectory -File -Filter 'resodrive-win-x64-*-setup.exe' |
| 55 | + if (@($versionedSetup).Count -ne 1) { |
| 56 | + throw "Expected one versioned setup bundle, found $(@($versionedSetup).Count)." |
| 57 | + } |
| 58 | + $stableSetup = Join-Path $releaseDirectory 'ResoDrive-Setup.exe' |
| 59 | + $stableChecksum = "$stableSetup.sha256" |
| 60 | + Copy-Item -LiteralPath $versionedSetup.FullName -Destination $stableSetup |
| 61 | + $hash = (Get-FileHash -LiteralPath $stableSetup -Algorithm SHA256).Hash.ToLowerInvariant() |
| 62 | + Set-Content -LiteralPath $stableChecksum -Value "$hash ResoDrive-Setup.exe" -Encoding ascii |
| 63 | + $assets = Get-ChildItem -LiteralPath $releaseDirectory -File | |
| 64 | + Where-Object Name -Match '\.(zip|msi|exe)(\.sha256)?$' | |
| 65 | + Sort-Object Name |
| 66 | + if ($assets.Count -ne 8) { |
| 67 | + throw "Expected eight release files, found $($assets.Count)." |
| 68 | + } |
| 69 | + gh release create $env:RELEASE_TAG $assets.FullName ` |
| 70 | + --verify-tag --notes-file RELEASE_NOTES.md --title "ResoDrive $env:RELEASE_TAG" |
| 71 | + if ($LASTEXITCODE -ne 0) { |
| 72 | + throw "GitHub release creation failed with exit code $LASTEXITCODE." |
| 73 | + } |
0 commit comments