Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release next #739

Merged
merged 16 commits into from
Oct 18, 2024
Merged
Prev Previous commit
Next Next commit
build script improvements
  • Loading branch information
dovholuknf committed Oct 18, 2024
commit aa4410737a871ae00cce4978dec9dd20efa1f67e
73 changes: 54 additions & 19 deletions Installer/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function verifyFile($path) {
}
}

echo ""
echo "========================== build.ps1 begins =========================="
$invocation = (Get-Variable MyInvocation).Value
$scriptPath = Split-Path $invocation.MyCommand.Path
Expand All @@ -35,35 +36,67 @@ mkdir "${buildPath}" -ErrorAction Ignore > $null

$global:ProgressPreference = "SilentlyContinue"
$destination="${scriptPath}\zet.zip"

$unzip = $true
if($null -eq $env:ZITI_EDGE_TUNNEL_BUILD) {
if($null -eq $env:ZITI_EDGE_TUNNEL_VERSION) {
# use the default $ZITI_EDGE_TUNNEL_VERSION
} else {
$ZITI_EDGE_TUNNEL_VERSION=$env:ZITI_EDGE_TUNNEL_VERSION
}
echo "========================== fetching ziti-edge-tunnel =========================="
$zet_dl="https://github.com/openziti/ziti-tunnel-sdk-c/releases/download/${ZITI_EDGE_TUNNEL_VERSION}/ziti-edge-tunnel-Windows_x86_64.zip"
echo "Beginning to download ziti-edge-tunnel from ${zet_dl} to ${destination}"
echo ""
$response = Invoke-WebRequest $zet_dl -OutFile "${destination}"
if (Test-Path ${destination} -PathType Container) {
echo "========================== fetching ziti-edge-tunnel =========================="
$zet_dl="https://github.com/openziti/ziti-tunnel-sdk-c/releases/download/${ZITI_EDGE_TUNNEL_VERSION}/ziti-edge-tunnel-Windows_x86_64.zip"
echo "Beginning to download ziti-edge-tunnel from ${zet_dl} to ${destination}"
echo ""
$response = Invoke-WebRequest $zet_dl -OutFile "${destination}"
} else {
Write-Host -ForegroundColor Yellow "ziti-edge-tunnel.zip exists and won't be downloaded again: ${destination}"
}
} else {
echo "========================== using locally defined ziti-edge-tunnel =========================="
$zet_dl="${env:ZITI_EDGE_TUNNEL_BUILD}"

echo "Sourcing ziti-edge-tunnel from ${zet_dl}"
echo "Using ziti-edge-tunnel declared from ${zet_dl}"
echo ""
if ($SourcePath -match "^https?://") {
$response = Invoke-WebRequest -Uri "${zet_dl}" -OutFile "${destination}"
} else {
$response = Copy-Item -Path "${zet_dl}" -Destination "${destination}" -ErrorAction Stop
echo "Determining if the location is a directory or zip file"
if (Test-Path $zet_dl -PathType Container) {
$unzip = $false
} elseif ($zet_dl -match '\.zip$') {
echo "Copying zip file to destination"
echo " FROM: ${zet_dl}"
echo " TO: ${destination}"
$response = Copy-Item -Path "${zet_dl}" -Destination "${destination}" -ErrorAction Stop
} else {
Write-Host -ForegroundColor Red "Unknown type. Expected either a .zip file or a directory:"
Write-Host -ForegroundColor Red " - ${zet_dl}"
exit 1
}
}
}

verifyFile("${destination}")
echo "Expanding downloaded file..."
Expand-Archive -Path "${destination}" -Force -DestinationPath "${buildPath}\service"
echo "expanded ${destination} file to ${buildPath}\service"
if($unzip) {
verifyFile("${destination}")
echo "Expanding downloaded file..."
Expand-Archive -Path "${destination}" -Force -DestinationPath "${buildPath}\service"
echo "expanded ${destination} file to ${buildPath}\service"
} else {
if (Test-Path -Path "${buildPath}\service") {
echo "removing old service folder at: ${buildPath}\service"
Remove-Item -Path "${buildPath}\service" -Recurse -Force -ErrorAction SilentlyContinue
}

echo "creating new service directory: ${buildPath}\service"
New-Item -Path "${buildPath}\service" -ItemType Directory | Out-Null

echo "Copying files from directory to destination"
echo " FROM: ${zet_dl}\*"
echo " TO: ${buildPath}\service\"
$response = Copy-Item -Path "${zet_dl}\wintun.dll" -Destination "${buildPath}\service\wintun.dll" -ErrorAction Stop -Force
$response = Copy-Item -Path "${zet_dl}\ziti-edge-tunnel.exe" -Destination "${buildPath}\service\ziti-edge-tunnel.exe" -ErrorAction Stop -Force
}

echo "========================== building and moving the custom signing tool =========================="
dotnet build -c Release "${checkoutRoot}/AWSSigner.NET\AWSSigner.NET.csproj"
Expand All @@ -75,8 +108,12 @@ $env:SIGNTOOL_PATH="${SIGNTOOL}"

Push-Location ${checkoutRoot}

if ($version -eq "") {
$version=(Get-Content -Path ${checkoutRoot}\version)
}

echo "Updating the version for UI and Installer"
.\update-versions.ps1
.\update-versions.ps1 $version

echo "Restoring the .NET project"
nuget restore .\ZitiDesktopEdge.sln
Expand All @@ -86,10 +123,6 @@ msbuild ZitiDesktopEdge.sln /property:Configuration=Release

Pop-Location

if ($version -eq "") {
$version=(Get-Content -Path ${checkoutRoot}\version)
}

echo "Building VERSION $version"

if($null -ne $env:ZITI_DESKTOP_EDGE_VERSION) {
Expand Down Expand Up @@ -122,7 +155,7 @@ $exeAbsPath="${outputPath}\${exeName}"

if($null -eq $env:AWS_KEY_ID) {
echo ""
echo "AWS_KEY_ID not set. __THE BINARY WILL NOT BE SIGNED!__"
echo "AWS_KEY_ID not set. __THE BINARY WILL NOT BE SIGNED!__"
echo ""
}

Expand All @@ -137,7 +170,6 @@ if($null -eq $env:OPENZITI_P12_PASS_2024) {
}

(Get-FileHash "${exeAbsPath}").Hash > "${scriptPath}\Output\Ziti Desktop Edge Client-${version}.exe.sha256"
echo "========================== build.ps1 completed =========================="

$outputPath = "${scriptPath}\Output\Ziti Desktop Edge Client-${version}.exe.json"
& .\Installer\output-build-json.ps1 -version $version -url $url -stream $stream -published_at $published_at -outputPath $outputPath -versionQualifier $versionQualifier
Expand All @@ -152,3 +184,6 @@ copy $outputPath "$checkoutRoot\release-streams\beta.json"
if($revertGitAfter) {
git checkout DesktopEdge/Properties/AssemblyInfo.cs ZitiUpdateService/Properties/AssemblyInfo.cs Installer/ZitiDesktopEdge.aip
}


echo "========================== build.ps1 completed =========================="
44 changes: 41 additions & 3 deletions build-test-release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# .\build-test-release.ps1 -version 1.2.3 -url https://lnxiskqx49x4.share.zrok.io/local -stream "dev" -published_at (Get-Date)
# .\build-test-release.ps1 -version 1.2.3 -url https://lnxiskqx49x4.share.zrok.io/local -stream "dev" -published_at "2023-11-02T14:30:00"
param(
[Parameter(Mandatory = $true)]
[string]$version,
[string]$url = "http://localhost:8000/release-streams/local",
[string]$stream = "local",
Expand All @@ -18,6 +17,44 @@ param(
echo ""
$scriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Path -Parent

$version = $version.Trim()
if (-not $version) {
if (Test-Path -Path "version") {
$version = (Get-Content -Path "version" -Raw).Trim()
Write-Host -NoNewline "Version not supplied. Using version from file and incrementing: "
Write-Host -ForegroundColor Yellow "${version}"

# Increment the last tuple
$versionWithoutPrefix = $version -replace '^v', ''
$segments = $versionWithoutPrefix -split '\.'
$segments[-1] = [int]$segments[-1] + 1
$version = ($segments -join '.')

Write-Host -NoNewline "New Version: "
Write-Host -ForegroundColor Green "$version"
# Check if the 'version' file has changes in git
$gitStatus = git status --porcelain "version"

if (-not $gitStatus) {
# File has not been modified in git, proceed to update it
Set-Content -Path "version" -Value $version -NoNewline
} else {
Write-Host "The version file has changes in git. Update skipped." -ForegroundColor Yellow
}
} else {
Write-Host "Version file not found" -ForegroundColor Red
exit 1
}
} else {
# Regex to match semantic versioning pattern
if ($version -notmatch '^v?\d+(\.\d+){0,3}$') {
Write-Host -ForegroundColor Red "Invalid version format [${version}]. Expected a semantic version (e.g., 1.0.0)."
exit 1
}
Write-Host -NoNewline "Version: "
Write-Host -ForegroundColor Green "$version"
}

$outputPath = "$scriptDirectory\release-streams\${version}.json"
& .\Installer\output-build-json.ps1 -version $version -url $url -stream $stream -published_at $published_at -outputPath $outputPath

Expand All @@ -28,7 +65,8 @@ if(! $jsonOnly) {
& .\Installer\build.ps1 -version $version -url $url -stream $stream -published_at $published_at -jsonOnly $jsonOnly -revertGitAfter $revertGitAfter -versionQualifier $versionQualifier
$exitCode = $LASTEXITCODE
if($exitCode -gt 0) {
Write-Host "build.ps1 failed!"
Write-Host -ForegroundColor Red "ERROR:"
Write-Host -ForegroundColor Red " - build.ps1 failed!"
exit $exitCode
}

Expand Down Expand Up @@ -56,4 +94,4 @@ Write-Host ""
Write-Host " python -m http.server 8000"
Write-Host ""
Write-Host "Set the automatic upgrade url to http://localhost:8000/release-streams/local.json"
Write-Host ""
Write-Host ""
22 changes: 15 additions & 7 deletions update-versions.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
param(
[string]$version
)

function NormalizeVersion([System.Version] $v) {
$major = $v.Major
$minor = $v.Minor
Expand All @@ -15,13 +19,17 @@ function NormalizeVersion([System.Version] $v) {
}

echo "==================================== update-versions.ps1 begins ===================================="
echo "Obtaining version information from .\version"
#$rawVersion=(Get-Content -Path .\version)
$installerVersion=(Get-Content -Path ${scriptPath}\..\version)
if($null -ne $env:ZITI_DESKTOP_EDGE_VERSION) {
echo "ZITI_DESKTOP_EDGE_VERSION is set. Using that: ${env:ZITI_DESKTOP_EDGE_VERSION} instead of version found in file ${installerVersion}"
$installerVersion=$env:ZITI_DESKTOP_EDGE_VERSION
echo "Version set to: ${installerVersion}"
if(-not $version.Trim()) {
echo "Obtaining version information from .\version"
#$rawVersion=(Get-Content -Path .\version)
$installerVersion=(Get-Content -Path ${scriptPath}\..\version)
if($null -ne $env:ZITI_DESKTOP_EDGE_VERSION) {
echo "ZITI_DESKTOP_EDGE_VERSION is set. Using that: ${env:ZITI_DESKTOP_EDGE_VERSION} instead of version found in file ${installerVersion}"
$installerVersion=$env:ZITI_DESKTOP_EDGE_VERSION
echo "Version set to: ${installerVersion}"
}
} else {
$installerVersion = $version
}

$v=NormalizeVersion($installerVersion)
Expand Down