Skip to content

Commit adebee7

Browse files
committedSep 1, 2024·
chore: Add automated do-release script to build files for github release
1 parent 11302ac commit adebee7

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ obj/
1111
*.user
1212

1313
launchsettings.json
14+
15+
artifacts/

‎Cpp2IL.sln

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1919
LibCpp2Il\README.md = LibCpp2Il\README.md
2020
Cpp2IL.Core\README_CORE.md = Cpp2IL.Core\README_CORE.md
2121
global.json = global.json
22+
do-release.ps1 = do-release.ps1
2223
EndProjectSection
2324
EndProject
2425
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibCpp2ILTests", "LibCpp2ILTests\LibCpp2ILTests.csproj", "{EB3CFC80-2125-48D2-AA2F-548F5AA58342}"

‎do-release.ps1

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
param (
2+
[switch]$help,
3+
[string]$version
4+
)
5+
6+
$ErrorActionPreference = "Stop"
7+
8+
if ($help) {
9+
Write-Host "Usage: do-release.ps1 [-help] [-version <version>]"
10+
Write-Host " -help: Display this help message"
11+
Write-Host " -version: The version to build"
12+
exit
13+
}
14+
15+
if (-not $version) {
16+
Write-Host "You must specify a version to build"
17+
exit
18+
}
19+
20+
Write-Host "===CPP2IL RELEASE SCRIPT==="
21+
22+
$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
23+
$MainCommandLineAppDir = Join-Path $ProjectRoot "Cpp2IL"
24+
$ArtifactsDir = Join-Path $ProjectRoot "artifacts"
25+
$BuildDir = Join-Path $MainCommandLineAppDir "bin"
26+
$ReleaseBuildDir = Join-Path $BuildDir "release"
27+
28+
Write-Host "Cleaning up old build and artifacts directories"
29+
if(Test-Path $ReleaseBuildDir)
30+
{
31+
Remove-Item -Recurse -Force $ReleaseBuildDir
32+
}
33+
34+
if(Test-Path $ArtifactsDir)
35+
{
36+
Remove-Item -Recurse -Force $ArtifactsDir
37+
}
38+
39+
cd $MainCommandLineAppDir
40+
41+
$baseVersion = (Select-Xml -XPath "//Project/PropertyGroup/VersionPrefix" -Path ".\Cpp2IL.csproj").Node.InnerText
42+
$fullVersionString = "$baseVersion-$version"
43+
Write-Host "Building Cpp2IL release version $fullVersionString"
44+
45+
Write-Host " Building Cpp2IL - Windows, Standalone .NET"
46+
47+
$null = dotnet publish -c Release -f "net7.0" -r "win-x64" /p:VersionSuffix=$version /p:PublishSingleFile=true --self-contained
48+
49+
Write-Host " Building Cpp2IL - Linux, Standalone .NET"
50+
51+
$null = dotnet publish -c Release -f "net7.0" -r "linux-x64" /p:VersionSuffix=$version /p:PublishSingleFile=true --self-contained
52+
53+
Write-Host " Building Cpp2IL - MacOS, Standalone .NET"
54+
55+
$null = dotnet publish -c Release -f "net7.0" -r "osx-x64" /p:VersionSuffix=$version /p:PublishSingleFile=true --self-contained
56+
57+
Write-Host " Building Cpp2IL - Windows, .NET Framework"
58+
59+
$null = dotnet publish -c Release -f "net472" -r "win-x64" /p:VersionSuffix=$version
60+
61+
function CopyAndRename($rid, $platform, $releasePlatformString, $extension)
62+
{
63+
$ridDir = Join-Path $ReleaseBuildDir $rid
64+
$platformDir = Join-Path $ridDir $platform
65+
$publishDir = Join-Path $platformDir "publish"
66+
$file = Join-Path $publishDir "Cpp2IL$extension"
67+
68+
if(Test-Path $file)
69+
{
70+
# Cpp2IL-2022.1.0.pre-release-17-Windows.exe
71+
$destFileName = "Cpp2IL-$fullVersionString-$releasePlatformString$extension"
72+
Write-Host " Copying $destFileName..."
73+
$newFile = Join-Path $ArtifactsDir $destFileName
74+
Copy-Item $file $newFile
75+
}
76+
}
77+
78+
function ZipAndRename($rid, $platform, $releasePlatformString, $extension)
79+
{
80+
$ridDir = Join-Path $ReleaseBuildDir $rid
81+
$platformDir = Join-Path $ridDir $platform
82+
$publishDir = Join-Path $platformDir "publish"
83+
84+
# Zip all files in the publish directory
85+
$zipFileName = "Cpp2IL-$fullVersionString-$releasePlatformString.zip"
86+
Write-Host " Zipping $zipFileName..."
87+
$zipFile = Join-Path $ArtifactsDir $zipFileName
88+
$null = Compress-Archive -Path $publishDir\* -DestinationPath $zipFile
89+
}
90+
91+
Write-Host "Moving files to artifacts directory"
92+
93+
$null = New-Item -ItemType Directory -Force -Path $ArtifactsDir
94+
95+
CopyAndRename "net7.0" "win-x64" "Windows" ".exe"
96+
CopyAndRename "net7.0" "linux-x64" "Linux" ""
97+
CopyAndRename "net7.0" "osx-x64" "OSX" ""
98+
ZipAndRename "net472" "win-x64" "Windows-Netframework472" ".exe"
99+
100+
Write-Host "Done!"
101+
Set-Location $ProjectRoot

0 commit comments

Comments
 (0)
Please sign in to comment.