price per item is printed
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
param(
|
||||
[ValidateSet('apk', 'appbundle', 'windows', 'web', 'ios', 'ipa', 'macos', 'linux')]
|
||||
[string]$Target = 'apk',
|
||||
[string]$FlutterCommand = 'flutter',
|
||||
[string[]]$FlutterArguments = @()
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$projectRoot = Split-Path -Parent $PSScriptRoot
|
||||
$pubspecPath = Join-Path $projectRoot 'pubspec.yaml'
|
||||
$lockPath = Join-Path $projectRoot '.release-build.lock'
|
||||
$buildLock = $null
|
||||
$originalBytes = $null
|
||||
$updated = $false
|
||||
$succeeded = $false
|
||||
|
||||
try {
|
||||
# Hold an exclusive lock; the OS releases it even if PowerShell is closed.
|
||||
$buildLock = [System.IO.File]::Open(
|
||||
$lockPath, [System.IO.FileMode]::OpenOrCreate,
|
||||
[System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None
|
||||
)
|
||||
foreach ($argument in $FlutterArguments) {
|
||||
if ($argument -match '^--(build-name|build-number|debug|profile|config-only)(=|$)') {
|
||||
throw "Argument $argument ist im versionierten Release-Build nicht erlaubt."
|
||||
}
|
||||
}
|
||||
$originalBytes = [System.IO.File]::ReadAllBytes($pubspecPath)
|
||||
$source = [System.Text.Encoding]::UTF8.GetString($originalBytes)
|
||||
$versionMatch = [regex]::Match($source, '(?m)^version:\s*(\d+)\.(\d+)\.(\d+)\+(\d+)[ \t]*\r?$')
|
||||
if (-not $versionMatch.Success) {
|
||||
throw 'In pubspec.yaml wird eine Version wie 1.0.0+1 erwartet.'
|
||||
}
|
||||
$patch = [long]::Parse($versionMatch.Groups[3].Value) + 1
|
||||
$build = [long]::Parse($versionMatch.Groups[4].Value) + 1
|
||||
$nextVersion = '{0}.{1}.{2}+{3}' -f $versionMatch.Groups[1].Value, $versionMatch.Groups[2].Value, $patch, $build
|
||||
$replacement = "version: $nextVersion"
|
||||
if ($versionMatch.Value.EndsWith("`r")) { $replacement += "`r" }
|
||||
$nextSource = $source.Remove($versionMatch.Index, $versionMatch.Length).Insert($versionMatch.Index, $replacement)
|
||||
[System.IO.File]::WriteAllText($pubspecPath, $nextSource, [System.Text.UTF8Encoding]::new($false))
|
||||
$updated = $true
|
||||
|
||||
Push-Location $projectRoot
|
||||
try {
|
||||
Write-Host "Release $nextVersion ($Target) wird erstellt ..."
|
||||
$global:LASTEXITCODE = 0
|
||||
& $FlutterCommand build $Target --release @FlutterArguments
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Flutter-Build fehlgeschlagen (Exitcode $LASTEXITCODE)."
|
||||
}
|
||||
$succeeded = $true
|
||||
Write-Host "Release $nextVersion erfolgreich. Die Version wurde in pubspec.yaml gespeichert."
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
} finally {
|
||||
if ($updated -and -not $succeeded) {
|
||||
[System.IO.File]::WriteAllBytes($pubspecPath, $originalBytes)
|
||||
Write-Host 'Build nicht erfolgreich: Bisherige Version wiederhergestellt.'
|
||||
}
|
||||
if ($null -ne $buildLock) { $buildLock.Dispose() }
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
$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).'
|
||||
Reference in New Issue
Block a user