61 lines
2.6 KiB
PowerShell
61 lines
2.6 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
$projectRoot = Split-Path -Parent $PSScriptRoot
|
|
$testRoot = Join-Path $projectRoot ('build/release-script-test-' + [guid]::NewGuid().ToString('N'))
|
|
$testScripts = Join-Path $testRoot 'scripts'
|
|
New-Item -ItemType Directory -Path $testScripts -Force | Out-Null
|
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'build_release.ps1') -Destination $testScripts
|
|
$pubspecPath = Join-Path $testRoot 'pubspec.yaml'
|
|
$original = "name: test_app`r`nversion: 1.2.9+41`r`n"
|
|
[System.IO.File]::WriteAllText($pubspecPath, $original)
|
|
$fakeFlutter = Join-Path $testRoot 'fake_flutter.ps1'
|
|
@'
|
|
param([Parameter(ValueFromRemainingArguments = $true)][string[]]$BuildArguments)
|
|
if (($BuildArguments -join ' ') -notmatch '^build (apk|windows) --release') {
|
|
throw 'Unexpected Flutter arguments.'
|
|
}
|
|
Copy-Item -LiteralPath './pubspec.yaml' -Destination './built-version.yaml' -Force
|
|
if (Test-Path './fail-build') { $global:LASTEXITCODE = 1 } else { $global:LASTEXITCODE = 0 }
|
|
'@ | Set-Content -LiteralPath $fakeFlutter
|
|
$releaseScript = Join-Path $testScripts 'build_release.ps1'
|
|
|
|
function Assert-Version([string]$Expected) {
|
|
$pubspec = [System.IO.File]::ReadAllText($pubspecPath)
|
|
if ($pubspec -ne "name: test_app`r`nversion: $Expected`r`n") {
|
|
throw "Unexpected pubspec: $pubspec"
|
|
}
|
|
}
|
|
|
|
& $releaseScript -FlutterCommand $fakeFlutter
|
|
Assert-Version '1.2.10+42'
|
|
if ([System.IO.File]::ReadAllText((Join-Path $testRoot 'built-version.yaml')) -notmatch '1\.2\.10\+42') {
|
|
throw 'The build did not receive the new version.'
|
|
}
|
|
& $releaseScript -Target windows -FlutterCommand $fakeFlutter
|
|
Assert-Version '1.2.11+43'
|
|
|
|
New-Item -ItemType File -Path (Join-Path $testRoot 'fail-build') | Out-Null
|
|
$failureCaught = $false
|
|
try { & $releaseScript -FlutterCommand $fakeFlutter } catch { $failureCaught = $true }
|
|
if (-not $failureCaught) { throw 'Build failure was not reported.' }
|
|
Assert-Version '1.2.11+43'
|
|
|
|
$invalidCaught = $false
|
|
try {
|
|
& $releaseScript -FlutterCommand $fakeFlutter -FlutterArguments '--build-number=99'
|
|
} catch { $invalidCaught = $true }
|
|
if (-not $invalidCaught) { throw 'Manual version override was accepted.' }
|
|
Assert-Version '1.2.11+43'
|
|
|
|
$lock = [System.IO.File]::Open(
|
|
(Join-Path $testRoot '.release-build.lock'),
|
|
[System.IO.FileMode]::OpenOrCreate, [System.IO.FileAccess]::ReadWrite,
|
|
[System.IO.FileShare]::None
|
|
)
|
|
$lockCaught = $false
|
|
try {
|
|
try { & $releaseScript -FlutterCommand $fakeFlutter } catch { $lockCaught = $true }
|
|
} finally { $lock.Dispose() }
|
|
if (-not $lockCaught) { throw 'Concurrent release was not blocked.' }
|
|
Assert-Version '1.2.11+43'
|
|
Write-Host 'All release-script checks passed (success, repeat build, rollback, overrides, lock).'
|