param( [Parameter(Mandatory = $true)][string]$VCRedist, [string]$Iscc, [switch]$UseCurrentVersion ) $ErrorActionPreference = 'Stop' $root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path $pubspec = Join-Path $root 'flutter_sender/pubspec.yaml' $versionText = Get-Content -LiteralPath $pubspec -Raw $match = [regex]::Match($versionText, '(?m)^version:\s*(\d+)\.(\d+)\.(\d+)\+(\d+)') if (-not $match.Success) { throw 'Flutter version must be major.minor.patch+build' } $version = "$($match.Groups[1]).$($match.Groups[2]).$($match.Groups[3])" $build = [int]$match.Groups[4].Value if (-not $UseCurrentVersion) { $version = "$($match.Groups[1]).$($match.Groups[2]).$([int]$match.Groups[3].Value + 1)" $build++ $utf8 = [Text.UTF8Encoding]::new($false) [IO.File]::WriteAllText($pubspec, [regex]::Replace($versionText, '(?m)^version:.*$', "version: $version+$build"), $utf8) $android = Join-Path $root 'android_receiver/app/build.gradle.kts' $text = Get-Content -LiteralPath $android -Raw $text = [regex]::Replace($text, 'versionCode = \d+', "versionCode = $build") $text = [regex]::Replace($text, 'versionName = "[^"]+"', "versionName = `"$version`"") [IO.File]::WriteAllText($android, $text, $utf8) $cargo = Join-Path $root 'rust_core/Cargo.toml' $text = Get-Content -LiteralPath $cargo -Raw [IO.File]::WriteAllText($cargo, [regex]::Replace($text, '(?m)^version = "[^"]+"', "version = `"$version`""), $utf8) } function Invoke-Checked([string]$Directory, [string]$Command, [string[]]$Arguments) { Push-Location $Directory try { & $Command @Arguments; if ($LASTEXITCODE -ne 0) { throw "$Command failed ($LASTEXITCODE)" } } finally { Pop-Location } } $android = Join-Path $root 'android_receiver' Invoke-Checked $android './gradlew.bat' @(':app:compileNeutralDebugKotlin', ':app:compileAospDebugKotlin', ':app:assembleNeutralRelease', ':app:assembleAospRelease', ':app:assembleZhanxunRelease', '--offline') Invoke-Checked "$root/flutter_sender" flutter @('pub', 'get', '--offline') Invoke-Checked "$root/flutter_sender" flutter @('test') & "$PSScriptRoot/windows/setup.ps1" -VCRedist $VCRedist -Iscc $Iscc -Version $version # setup.ps1 throws on a failed build; do not remove previous packages until all outputs exist. $release = Join-Path $root "dist/releases/v$version" New-Item -ItemType Directory -Force -Path $release | Out-Null Copy-Item -LiteralPath "$root/dist/windows/TTSTDConnect-$version-windows-x64-setup.exe" -Destination $release foreach ($flavor in @('neutral', 'aosp', 'zhanxun')) { Copy-Item -LiteralPath "$android/app/build/outputs/apk/$flavor/release/app-$flavor-release.apk" -Destination "$release/TTSTDConnect-Receiver-$version-$flavor.apk" } Get-ChildItem -LiteralPath $release -File | Where-Object { $_.Extension -in '.apk', '.exe' } | ForEach-Object { '{0} {1}' -f (Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256).Hash.ToLowerInvariant(), $_.Name } | Set-Content -LiteralPath "$release/SHA256SUMS" -Encoding ascii @{ version = $version; build = $build; baseCommit = (git -C $root rev-parse HEAD); workingTreeModified = [bool](git -C $root status --porcelain); builtAt = [DateTimeOffset]::Now.ToString('o') } | ConvertTo-Json | Set-Content -LiteralPath "$release/BUILD-INFO.json" -Encoding utf8 & "$PSScriptRoot/prune-artifacts.ps1" -KeepVersion $version Write-Output "Release ready: $release"