-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
138 lines (122 loc) · 4.7 KB
/
build.ps1
File metadata and controls
138 lines (122 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env pwsh
# Shutter release builder.
# Bumps patch version in pubspec.yaml, builds split-per-ABI release APKs,
# renames arm64-v8a as shutter-<ver>.apk, archives prior v8a builds,
# stores other ABIs alongside.
#
# Usage:
# .\build.ps1 # bump patch, build, archive
# .\build.ps1 -NoBump # rebuild current version (overwrites)
# .\build.ps1 -Bump minor # bump minor (resets patch)
# .\build.ps1 -Bump major # bump major (resets minor + patch)
[CmdletBinding()]
param(
[ValidateSet('patch', 'minor', 'major')]
[string]$Bump = 'patch',
[switch]$NoBump
)
$ErrorActionPreference = 'Stop'
Set-Location -LiteralPath $PSScriptRoot
$pubspec = Join-Path $PSScriptRoot 'pubspec.yaml'
if (-not (Test-Path $pubspec)) { throw "pubspec.yaml not found at $pubspec" }
# --- Read current version ---
$content = Get-Content $pubspec -Raw
if ($content -notmatch '(?m)^version:\s*(\d+)\.(\d+)\.(\d+)(?:\+(\d+))?\s*$') {
throw "Could not find 'version: X.Y.Z' in pubspec.yaml"
}
$major = [int]$Matches[1]
$minor = [int]$Matches[2]
$patch = [int]$Matches[3]
$buildNum = if ($Matches[4]) { [int]$Matches[4] } else { $null }
$current = "$major.$minor.$patch"
# --- Compute next version ---
if ($NoBump) {
$next = $current
} else {
switch ($Bump) {
'patch' { $patch++ }
'minor' { $minor++; $patch = 0 }
'major' { $major++; $minor = 0; $patch = 0 }
}
$next = "$major.$minor.$patch"
}
# Auto-increment build number if pubspec had +N suffix, else just X.Y.Z
$newVersionLine = if ($buildNum -ne $null) {
$nextBuild = if ($NoBump) { $buildNum } else { $buildNum + 1 }
"version: $next+$nextBuild"
} else {
"version: $next"
}
Write-Host "Version: $current -> $next" -ForegroundColor Cyan
# --- Write pubspec.yaml back ---
if (-not $NoBump) {
$updated = [regex]::Replace(
$content,
'(?m)^version:\s*\d+\.\d+\.\d+(?:\+\d+)?\s*$',
$newVersionLine
)
Set-Content -Path $pubspec -Value $updated -NoNewline:$false
}
# --- Sync lib/utils/app_info.dart ---
# AppInfo.version is what the in-app Settings screen renders. Keep it in lock-
# step with pubspec so users always see the version they're actually running.
$appInfo = Join-Path $PSScriptRoot 'lib/utils/app_info.dart'
if (Test-Path $appInfo) {
$infoContent = Get-Content $appInfo -Raw
$patched = [regex]::Replace(
$infoContent,
"(static const String version = ')[^']*(';)",
"`${1}$next`$2"
)
if ($patched -ne $infoContent) {
Set-Content -Path $appInfo -Value $patched -NoNewline:$false
Write-Host " app_info.dart -> $next" -ForegroundColor DarkGray
}
} else {
Write-Warning "app_info.dart not found; in-app version will drift."
}
# --- Prepare output dirs ---
$releases = Join-Path $PSScriptRoot 'releases'
$archive = Join-Path $releases 'archive'
$abis = Join-Path $releases 'abis'
New-Item -ItemType Directory -Force -Path $releases, $archive, $abis | Out-Null
# --- Archive existing v8a builds (top-level shutter-*.apk) ---
Get-ChildItem -Path $releases -Filter 'shutter-*.apk' -File -ErrorAction SilentlyContinue |
ForEach-Object {
$dest = Join-Path $archive $_.Name
if (Test-Path $dest) { Remove-Item $dest -Force }
Move-Item $_.FullName $dest
Write-Host " archived $($_.Name)" -ForegroundColor DarkGray
}
# --- Build ---
Write-Host "Running flutter build apk --split-per-abi --release" -ForegroundColor Cyan
& flutter build apk --split-per-abi --release
if ($LASTEXITCODE -ne 0) { throw "flutter build failed (exit $LASTEXITCODE)" }
# --- Rename + copy outputs ---
$out = Join-Path $PSScriptRoot 'build\app\outputs\flutter-apk'
$map = @{
'app-arm64-v8a-release.apk' = Join-Path $releases "shutter-$next.apk"
'app-armeabi-v7a-release.apk' = Join-Path $abis "shutter-$next-armeabi-v7a.apk"
'app-x86_64-release.apk' = Join-Path $abis "shutter-$next-x86_64.apk"
}
foreach ($src in $map.Keys) {
$srcPath = Join-Path $out $src
if (-not (Test-Path $srcPath)) {
Write-Warning "Missing expected output: $src"
continue
}
Copy-Item $srcPath $map[$src] -Force
$size = [math]::Round((Get-Item $map[$src]).Length / 1MB, 1)
Write-Host " $(Split-Path $map[$src] -Leaf) ($size MB)" -ForegroundColor Green
}
Write-Host ""
Write-Host "Done. shutter-$next.apk in $releases" -ForegroundColor Green
# --- Push to phone ---
$targetApk = Join-Path $releases "shutter-$next.apk"
if (Test-Path $targetApk) {
Write-Host "Pushing $(Split-Path $targetApk -Leaf) to phone..." -ForegroundColor Cyan
& push-apk $targetApk
if ($LASTEXITCODE -ne 0) { Write-Warning "push-apk exit $LASTEXITCODE (build ok)" }
} else {
Write-Warning "No APK at $targetApk; skipping push."
}