Skip to content

Commit 5a12f29

Browse files
committed
Add Create-DMG ci script
1 parent dc2351d commit 5a12f29

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

scripts/ci/Create-DMG.ps1

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
param (
2+
[Parameter(Mandatory)]
3+
[string]$AppPath,
4+
5+
[Parameter(Mandatory)]
6+
[string]$Semver,
7+
8+
[Parameter(Mandatory)]
9+
[string]$ApplicationDisplayName,
10+
11+
[Parameter(Mandatory)]
12+
[string]$InstallerFileBase
13+
)
14+
15+
$BackgroundSrcDir = "src/app/share/dmg"
16+
17+
$Bg1x = Join-Path $BackgroundSrcDir "dmg_background.png"
18+
$Bg2x = Join-Path $BackgroundSrcDir "dmg_background@2x.png"
19+
20+
if (!(Test-Path $Bg1x) -or !(Test-Path $Bg2x)) {
21+
throw "dmg_background.png and dmg_background@2x.png do not exist in $BackgroundSrcDir"
22+
}
23+
24+
if (!(Test-Path $AppPath)) {
25+
throw "App bundle not exist: $AppPath"
26+
}
27+
28+
# Temporary directory
29+
$TempDir = Join-Path ([System.IO.Path]::GetTempPath()) ("dmg-build-" + [System.Guid]::NewGuid())
30+
New-Item -ItemType Directory -Path $TempDir | Out-Null
31+
32+
$Bg1xOut = Join-Path $TempDir "dmg_background.png"
33+
$Bg2xOut = Join-Path $TempDir "dmg_background@2x.png"
34+
$BgTiff = Join-Path $TempDir "dmg_background.tiff"
35+
36+
$VersionText = "Version $Semver"
37+
38+
try {
39+
# -----------------------------
40+
# Step 1: Preprocess background
41+
# -----------------------------
42+
43+
# 1x image
44+
& magick `
45+
"$Bg1x" `
46+
-gravity south `
47+
-pointsize 12 `
48+
-fill "rgba(37,37,37,0.25)" `
49+
-annotate +0+8 "$VersionText" `
50+
"$Bg1xOut" | Write-Host
51+
52+
if ($LASTEXITCODE -ne 0) {
53+
throw "ImageMagick failed to process dmg_background.png"
54+
}
55+
56+
# 2x image (scaled)
57+
& magick `
58+
"$Bg2x" `
59+
-gravity south `
60+
-pointsize 24 `
61+
-fill "rgba(37,37,37,0.25)" `
62+
-annotate +0+16 "$VersionText" `
63+
"$Bg2xOut" | Write-Host
64+
65+
if ($LASTEXITCODE -ne 0) {
66+
throw "ImageMagick failed to process dmg_background@2x.png"
67+
}
68+
69+
# Combine into TIFF
70+
& tiffutil `
71+
-cathidpicheck `
72+
"$Bg1xOut" `
73+
"$Bg2xOut" `
74+
-out "$BgTiff" | Write-Host
75+
76+
if ($LASTEXITCODE -ne 0) {
77+
throw "tiffutil failed to create TIFF"
78+
}
79+
80+
# -----------------------------
81+
# Step 2: Build DMG
82+
# -----------------------------
83+
$DmgName = "$InstallerFileBase.dmg"
84+
$DmgPath = Join-Path (Get-Location) $DmgName
85+
86+
if (Test-Path $DmgPath) {
87+
Remove-Item $DmgPath -Force
88+
}
89+
90+
<# TODO: create-dmg currently places hidden .background file to the right of the visible area, so we have to leave some space for the horizontal scroll bar #>
91+
& create-dmg `
92+
--volname "$ApplicationDisplayName" `
93+
--background "$BgTiff" `
94+
--window-size 600 448 `
95+
--icon-size 128 `
96+
--icon "$(Split-Path $AppPath -Leaf)" 132 280 `
97+
--app-drop-link 468 280 `
98+
"$DmgPath" `
99+
"$AppPath" | Write-Host
100+
101+
if ($LASTEXITCODE -ne 0) {
102+
throw "create-dmg failed"
103+
}
104+
105+
Write-Output $DmgPath
106+
}
107+
finally {
108+
# Cleanup temp files
109+
if (Test-Path $TempDir) {
110+
Remove-Item $TempDir -Recurse -Force
111+
}
112+
}
32.7 KB
Loading
83.4 KB
Loading

0 commit comments

Comments
 (0)