-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdeploy.ps1
More file actions
131 lines (108 loc) Β· 4.38 KB
/
deploy.ps1
File metadata and controls
131 lines (108 loc) Β· 4.38 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
#!/usr/bin/env pwsh
$ErrorActionPreference = "Stop"
$PSNativeCommandErrorActionPreference = "Stop"
Set-PSDebug -Trace 1
# Calculate new version
$currentVersion = yq e '.version' pubspec.yaml
$parts = $currentVersion -split '[+\.]'
$major, $minor, $patch, $buildNumber = $parts[0], $parts[1], [int]$parts[2], [int]$parts[3]
$newPatch = $patch + 1
$newBuildNumber = $buildNumber + 1
$changelogNumber = $newBuildNumber * 10 + 3
$newFlutterVersion = "$major.$minor.$newPatch+$newBuildNumber"
$newVersion = "$major.$minor.$newPatch"
$mp = (yq e '.msix_config.msix_version' pubspec.yaml) -split '\.'
$newMsixVersion = "$($mp[0]).$($mp[1]).$([int]$mp[2] + 1).$($mp[3])"
Write-Host "New version: $newFlutterVersion, MSIX: $newMsixVersion, Changelog: $changelogNumber"
# Generate changelog
$changelogFile = "fastlane/metadata/android/en-US/changelogs/$changelogNumber.txt"
if (-not (Test-Path $changelogFile)) {
New-Item -ItemType Directory -Force -Path (Split-Path $changelogFile) | Out-Null
$PSNativeCommandErrorActionPreference = "Continue"
$lastTag = git describe --tags --abbrev=0 2>$null
$PSNativeCommandErrorActionPreference = "Stop"
$range = if ($LASTEXITCODE -eq 0 -and $lastTag) { "$lastTag..HEAD" } else { "HEAD" }
git --no-pager log --pretty=format:'%s' $range |
Sort-Object -Unique |
Where-Object { $_ -notmatch '^(Merge |Release |Bump |Update |\d+\.\d+\.\d+)' } |
Select-Object -First 10 |
ForEach-Object { "β’ $_" } |
Set-Content $changelogFile -Encoding UTF8
nvim $changelogFile
}
New-Item -ItemType Directory -Force -Path "fastlane/metadata/en-AU" | Out-Null
Get-Content $changelogFile | Set-Content "fastlane/metadata/en-AU/release_notes.txt" -Encoding UTF8
# Setup Flutter
git submodule update --init --recursive flutter
$env:PATH = "$(Join-Path $PWD 'flutter' 'bin')$([IO.Path]::PathSeparator)$env:PATH"
# Tests and analysis
flutter test
dart analyze lib
dart format --set-exit-if-changed lib
# Update versions
yq e ".version |= `"$newFlutterVersion`"" -i pubspec.yaml
yq e ".msix_config.msix_version |= `"$newMsixVersion`"" -i pubspec.yaml
# Copy changelogs with timestamps
New-Item -ItemType Directory -Force -Path "assets/changelogs" | Out-Null
foreach ($file in Get-ChildItem "fastlane/metadata/android/en-US/changelogs/*.txt") {
if ($IsMacOS) {
$timestamp = stat -f "%B" $file.FullName
} elseif ($IsWindows) {
$epoch = [datetime]'1970-01-01T00:00:00Z'
$timestamp = [int64]($file.CreationTimeUtc - $epoch).TotalSeconds
} else {
$timestamp = stat --format="%W" $file.FullName
}
Copy-Item $file.FullName "assets/changelogs/$timestamp.txt"
}
function Invoke-Screenshots([string]$AvdName) {
$proc = Start-Process emulator -ArgumentList @(
"-avd", $AvdName, "-no-window", "-gpu", "swiftshader_indirect",
"-noaudio", "-no-boot-anim", "-camera-back", "none"
) -PassThru
$timeout = 300
$elapsed = 0
$emulatorId = $null
while ($elapsed -lt $timeout) {
$emulatorId = adb devices |
Where-Object { $_ -match 'emulator-' -and $_ -match 'device$' } |
ForEach-Object { ($_ -split '\s+')[0] } |
Select-Object -First 1
if ($emulatorId) { break }
if ($proc.HasExited) { exit 1 }
Start-Sleep 5
$elapsed += 5
}
if (-not $emulatorId) { $proc.Kill(); exit 1 }
Start-Sleep 15
flutter drive --profile --driver=test_driver/integration_test.dart `
--dart-define=QUITTER_DEVICE_TYPE=$AvdName `
--target=integration_test/screenshot_test.dart -d $emulatorId
adb -s $emulatorId emu kill 2>$null
Start-Sleep 5
}
if ($args -contains "-n") {
Write-Host "Skipping screenshots"
} else {
Invoke-Screenshots "phoneScreenshots"
Invoke-Screenshots "sevenInchScreenshots"
Invoke-Screenshots "tenInchScreenshots"
}
# Commit and tag
$PSNativeCommandErrorActionPreference = "Continue"
git diff --quiet HEAD -- pubspec.yaml fastlane/metadata pubspec.lock assets
$hasChanges = $LASTEXITCODE -ne 0
$PSNativeCommandErrorActionPreference = "Stop"
if ($hasChanges) {
git add pubspec.yaml fastlane/metadata pubspec.lock assets
git commit -m "Release $newVersion"
git tag $newVersion
}
# Build
if ($IsMacOS) { flutter build macos }
if ($IsLinux) { flutter build linux }
if ($IsWindows) { flutter build windows }
flutter config --enable-web
flutter build web --release
git push
git push --tags