Skip to content

Commit 2a6af75

Browse files
committed
🔨 chore: update release workflow and improve New-ReleaseZip script
1 parent f081e2a commit 2a6af75

2 files changed

Lines changed: 48 additions & 32 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ jobs:
3131
runs-on: windows-latest
3232

3333
steps:
34-
- name: Check out source
35-
uses: actions/checkout@v4
36-
with:
37-
fetch-depth: 0
34+
# - name: Check out source
35+
# uses: actions/checkout@v4
36+
# with:
37+
# fetch-depth: 0
3838

39-
- name: Set up .NET 8
40-
uses: actions/setup-dotnet@v4
41-
with:
42-
dotnet-version: 8.0.x
39+
# - name: Set up .NET 8
40+
# uses: actions/setup-dotnet@v4
41+
# with:
42+
# dotnet-version: 8.0.x
4343

4444
# - name: Install .NET Framework 4.5.2 Developer Pack
4545
# shell: pwsh

‎scripts/New-ReleaseZip.ps1‎

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,62 @@ $ErrorActionPreference = 'Stop'
1212
$projectRoot = Split-Path -Parent $PSScriptRoot
1313
$projectFile = Join-Path $projectRoot 'SQLBakVersion.csproj'
1414
$artifactsDirectory = Join-Path $projectRoot 'artifacts'
15-
$releaseName = "SQLBakVersion"
16-
$publishDirectory = Join-Path $artifactsDirectory $releaseName
15+
$releaseName = 'SQLBakVersion'
16+
$buildDirectory = Join-Path $artifactsDirectory "$releaseName-$Version-$Runtime"
1717
$zipPath = Join-Path $artifactsDirectory "$releaseName.zip"
18+
$assemblyInfoFile = Join-Path $projectRoot 'Properties\AssemblyInfo.cs'
19+
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
1820

1921
if (-not (Test-Path -LiteralPath $projectFile)) {
2022
throw "Project file was not found: $projectFile"
2123
}
24+
if (-not (Test-Path -LiteralPath $vswhere)) {
25+
throw 'Visual Studio Build Tools were not found.'
26+
}
27+
28+
$msbuild = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -find 'MSBuild\Current\Bin\MSBuild.exe' |
29+
Select-Object -First 1
30+
31+
if (-not $msbuild -or -not (Test-Path -LiteralPath $msbuild)) {
32+
throw 'MSBuild.exe was not found.'
33+
}
2234

2335
New-Item -ItemType Directory -Path $artifactsDirectory -Force | Out-Null
2436

25-
if (Test-Path -LiteralPath $publishDirectory) {
26-
Remove-Item -LiteralPath $publishDirectory -Recurse -Force
37+
if (Test-Path -LiteralPath $buildDirectory) {
38+
Remove-Item -LiteralPath $buildDirectory -Recurse -Force
2739
}
2840
if (Test-Path -LiteralPath $zipPath) {
2941
Remove-Item -LiteralPath $zipPath -Force
3042
}
3143

32-
Write-Host "Restoring packages for $Runtime..."
33-
dotnet restore $projectFile --runtime $Runtime
44+
$platformTarget = if ($Runtime -eq 'win-x86') { 'x86' } else { 'x64' }
45+
$assemblyVersion = "$(($Version -split '[-+]')[0]).0"
46+
$originalAssemblyInfo = [System.IO.File]::ReadAllBytes($assemblyInfoFile)
47+
$assemblyInfo = Get-Content -LiteralPath $assemblyInfoFile -Raw
3448

35-
if ($LASTEXITCODE -ne 0) {
36-
throw "dotnet restore failed with exit code $LASTEXITCODE."
37-
}
49+
$assemblyInfo = [regex]::Replace($assemblyInfo, '(?<=AssemblyVersion\(")[^"]+(?="\))', $assemblyVersion)
50+
$assemblyInfo = [regex]::Replace($assemblyInfo, '(?<=AssemblyFileVersion\(")[^"]+(?="\))', $assemblyVersion)
51+
52+
try {
53+
[System.IO.File]::WriteAllText($assemblyInfoFile, $assemblyInfo, [System.Text.UTF8Encoding]::new($false))
3854

39-
Write-Host "Publishing $releaseName..."
40-
dotnet publish $projectFile `
41-
--configuration Release `
42-
--runtime $Runtime `
43-
--self-contained true `
44-
--no-restore `
45-
-p:PublishSingleFile=true `
46-
-p:IncludeNativeLibrariesForSelfExtract=true `
47-
-p:Version=$Version `
48-
--output $publishDirectory
49-
50-
if ($LASTEXITCODE -ne 0) {
51-
throw "dotnet publish failed with exit code $LASTEXITCODE."
55+
Write-Host "Building $releaseName for $Runtime..."
56+
& $msbuild $projectFile `
57+
/t:Rebuild `
58+
"/p:Configuration=Release;Platform=AnyCPU;PlatformTarget=$platformTarget;OutputPath=$buildDirectory\" `
59+
/nologo `
60+
/verbosity:minimal
61+
62+
if ($LASTEXITCODE -ne 0) {
63+
throw "MSBuild failed with exit code $LASTEXITCODE."
64+
}
65+
}
66+
finally {
67+
[System.IO.File]::WriteAllBytes($assemblyInfoFile, $originalAssemblyInfo)
5268
}
5369

54-
Copy-Item -LiteralPath (Join-Path $projectRoot 'README.md') -Destination $publishDirectory
55-
Compress-Archive -Path (Join-Path $publishDirectory '*') -DestinationPath $zipPath -CompressionLevel Optimal
70+
Copy-Item -LiteralPath (Join-Path $projectRoot 'README.md') -Destination $buildDirectory
71+
Compress-Archive -Path (Join-Path $buildDirectory '*') -DestinationPath $zipPath -CompressionLevel Optimal
5672

5773
Write-Host "Release ZIP created: $zipPath" -ForegroundColor Green

0 commit comments

Comments
 (0)