Skip to content

Commit

Permalink
chore: Add automated do-release script to build files for github release
Browse files Browse the repository at this point in the history
  • Loading branch information
SamboyCoding committed Sep 1, 2024
1 parent 11302ac commit adebee7
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ obj/
*.user

launchsettings.json

artifacts/
1 change: 1 addition & 0 deletions Cpp2IL.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
LibCpp2Il\README.md = LibCpp2Il\README.md
Cpp2IL.Core\README_CORE.md = Cpp2IL.Core\README_CORE.md
global.json = global.json
do-release.ps1 = do-release.ps1
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibCpp2ILTests", "LibCpp2ILTests\LibCpp2ILTests.csproj", "{EB3CFC80-2125-48D2-AA2F-548F5AA58342}"
Expand Down
101 changes: 101 additions & 0 deletions do-release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
param (
[switch]$help,
[string]$version
)

$ErrorActionPreference = "Stop"

if ($help) {
Write-Host "Usage: do-release.ps1 [-help] [-version <version>]"
Write-Host " -help: Display this help message"
Write-Host " -version: The version to build"
exit
}

if (-not $version) {
Write-Host "You must specify a version to build"
exit
}

Write-Host "===CPP2IL RELEASE SCRIPT==="

$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$MainCommandLineAppDir = Join-Path $ProjectRoot "Cpp2IL"
$ArtifactsDir = Join-Path $ProjectRoot "artifacts"
$BuildDir = Join-Path $MainCommandLineAppDir "bin"
$ReleaseBuildDir = Join-Path $BuildDir "release"

Write-Host "Cleaning up old build and artifacts directories"
if(Test-Path $ReleaseBuildDir)
{
Remove-Item -Recurse -Force $ReleaseBuildDir
}

if(Test-Path $ArtifactsDir)
{
Remove-Item -Recurse -Force $ArtifactsDir
}

cd $MainCommandLineAppDir

$baseVersion = (Select-Xml -XPath "//Project/PropertyGroup/VersionPrefix" -Path ".\Cpp2IL.csproj").Node.InnerText
$fullVersionString = "$baseVersion-$version"
Write-Host "Building Cpp2IL release version $fullVersionString"

Write-Host " Building Cpp2IL - Windows, Standalone .NET"

$null = dotnet publish -c Release -f "net7.0" -r "win-x64" /p:VersionSuffix=$version /p:PublishSingleFile=true --self-contained

Write-Host " Building Cpp2IL - Linux, Standalone .NET"

$null = dotnet publish -c Release -f "net7.0" -r "linux-x64" /p:VersionSuffix=$version /p:PublishSingleFile=true --self-contained

Write-Host " Building Cpp2IL - MacOS, Standalone .NET"

$null = dotnet publish -c Release -f "net7.0" -r "osx-x64" /p:VersionSuffix=$version /p:PublishSingleFile=true --self-contained

Write-Host " Building Cpp2IL - Windows, .NET Framework"

$null = dotnet publish -c Release -f "net472" -r "win-x64" /p:VersionSuffix=$version

function CopyAndRename($rid, $platform, $releasePlatformString, $extension)
{
$ridDir = Join-Path $ReleaseBuildDir $rid
$platformDir = Join-Path $ridDir $platform
$publishDir = Join-Path $platformDir "publish"
$file = Join-Path $publishDir "Cpp2IL$extension"

if(Test-Path $file)
{
# Cpp2IL-2022.1.0.pre-release-17-Windows.exe
$destFileName = "Cpp2IL-$fullVersionString-$releasePlatformString$extension"
Write-Host " Copying $destFileName..."
$newFile = Join-Path $ArtifactsDir $destFileName
Copy-Item $file $newFile
}
}

function ZipAndRename($rid, $platform, $releasePlatformString, $extension)
{
$ridDir = Join-Path $ReleaseBuildDir $rid
$platformDir = Join-Path $ridDir $platform
$publishDir = Join-Path $platformDir "publish"

# Zip all files in the publish directory
$zipFileName = "Cpp2IL-$fullVersionString-$releasePlatformString.zip"
Write-Host " Zipping $zipFileName..."
$zipFile = Join-Path $ArtifactsDir $zipFileName
$null = Compress-Archive -Path $publishDir\* -DestinationPath $zipFile
}

Write-Host "Moving files to artifacts directory"

$null = New-Item -ItemType Directory -Force -Path $ArtifactsDir

CopyAndRename "net7.0" "win-x64" "Windows" ".exe"
CopyAndRename "net7.0" "linux-x64" "Linux" ""
CopyAndRename "net7.0" "osx-x64" "OSX" ""
ZipAndRename "net472" "win-x64" "Windows-Netframework472" ".exe"

Write-Host "Done!"
Set-Location $ProjectRoot

0 comments on commit adebee7

Please sign in to comment.