Step 4 installed the APK on the first emulator adb listed. Another project's emulator (a Pixel_9a AVD) runs beside this one at times, and was running when 1.0.7 was about to be built: had it come first, the release would have been installed and started there. The step now picks the emulator named Flexera_Launcher_A17, or the only emulator running, and stops when there are several and none has that name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
457 lines
25 KiB
PowerShell
457 lines
25 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Builds a signed release of Flexera Launcher and publishes it to the public release repository.
|
|
|
|
.DESCRIPTION
|
|
One command per release. It
|
|
1. writes the new version to flexera/version.properties and commits it,
|
|
2. builds the signed release APK, compiling the Kotlin code from scratch, and records the
|
|
commit it was built from (source edited while it builds counts as uncommitted changes),
|
|
3. checks that the APK carries the release certificate, the one every installed copy has,
|
|
4. installs the APK on the running Android emulator, starts it and looks for a crash,
|
|
5. creates the release "v<version>" in https://git.mariosem.es/msemes/Flexera-Launcher-Releases
|
|
as a draft, which only you can see,
|
|
6. attaches the APK to it and then publishes it, and
|
|
7. tags the source commit it was built from. A tag of that version already on another
|
|
commit stops the script before anything is published, and -BuildOnly warns of it.
|
|
|
|
Installed copies of the app look at that repository once a day (app.flexera.update.FlexeraUpdater)
|
|
and offer the new version. A release that crashes at start would therefore reach the phone on
|
|
its own, which is why step 4 exists and why nothing is published when it fails.
|
|
|
|
Needs: keystore.properties and the keystore it names in the project root (both are git-ignored;
|
|
without them the script stops), the git login for git.mariosem.es that git already has stored,
|
|
and a running emulator for step 4 (start it with: emulator.exe -avd Flexera_Launcher_A17).
|
|
|
|
.PARAMETER Version
|
|
The new version, as major.minor.patch (for example 0.2.0). Must be higher than the last release.
|
|
|
|
.PARAMETER Notes
|
|
What changed, in plain words. Shown in the app under "What's new" and on the release page.
|
|
|
|
.PARAMETER NotesFile
|
|
A text file with the notes, as an alternative to -Notes.
|
|
|
|
.PARAMETER BuildOnly
|
|
Stop after step 4, without publishing. Try the APK by hand, then run the script again with
|
|
-SkipBuild to publish that same file.
|
|
|
|
.PARAMETER SkipBuild
|
|
Use the APK that is already in build\outputs instead of building again. Every build of this
|
|
script records, in a file next to the APK, the commit it was built from and the APK's SHA-256,
|
|
and step 7 tags that commit. -SkipBuild stops when that record is missing (the APK was built
|
|
some other way, or by an older copy of this script) or describes another file (the APK was
|
|
built again since), and when the commits since the build change anything but this script and
|
|
WEBSITE\: the APK would be published without those changes. An APK built with uncommitted
|
|
changes (with -AllowDirty, or edited while it built) is published only with -AllowDirty again.
|
|
|
|
.PARAMETER NoSmokeTest
|
|
Skip step 4. Only for a machine without an emulator; try the APK on a phone yourself first.
|
|
|
|
.PARAMETER AllowDirty
|
|
Release even though there are uncommitted changes. The APK then matches no commit exactly.
|
|
|
|
.PARAMETER PushSource
|
|
Also push the source branch and the version tag to origin.
|
|
|
|
.EXAMPLE
|
|
.\flexera\release.ps1 -Version 0.2.0 -Notes "The alphabet follows the finger more closely."
|
|
|
|
.EXAMPLE
|
|
.\flexera\release.ps1 -Version 0.2.0 -BuildOnly
|
|
.\flexera\release.ps1 -Version 0.2.0 -SkipBuild -Notes "The alphabet follows the finger more closely."
|
|
#>
|
|
param(
|
|
[Parameter(Mandatory = $true)][string]$Version,
|
|
[string]$Notes = "",
|
|
[string]$NotesFile,
|
|
[switch]$BuildOnly,
|
|
[switch]$SkipBuild,
|
|
[switch]$NoSmokeTest,
|
|
[switch]$AllowDirty,
|
|
[switch]$PushSource
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$Server = 'https://git.mariosem.es'
|
|
$GitHost = 'git.mariosem.es'
|
|
$ReleaseRepository = 'msemes/Flexera-Launcher-Releases'
|
|
$Api = "$Server/api/v1/repos/$ReleaseRepository"
|
|
$VariantDir = 'lawnWithQuickstepGithubRelease'
|
|
$Variant = 'LawnWithQuickstepGithubRelease'
|
|
$AppId = 'com.sema.flexeralauncher'
|
|
$HomeActivity = "$AppId/app.lawnchair.LawnchairLauncher"
|
|
$JavaHome = 'C:\Program Files\Android\Android Studio\jbr'
|
|
$Adb = Join-Path $env:LOCALAPPDATA 'Android\Sdk\platform-tools\adb.exe'
|
|
$SmokeTestSeconds = 25
|
|
# The certificate every release is signed with, as the "certificate SHA-256 digest" that apksigner
|
|
# prints. Android installs an update only when it is signed with the same certificate as the copy
|
|
# already installed, so an APK signed with any other key, a keystore made anew under the same name
|
|
# included, could not update a single installed copy. It is no secret: every published APK carries it.
|
|
$ReleaseCertificateDigest = 'c5584f64eae90ba27f9b39dad2baa7ed6f60d248175578acd8cf1f178facfc70'
|
|
|
|
$Root = Split-Path -Parent $PSScriptRoot
|
|
Set-Location $Root
|
|
|
|
function Step([string]$text) { Write-Host "`n== $text" -ForegroundColor Cyan }
|
|
|
|
function Get-ApiClient {
|
|
# The login comes from git's own credential store and stays inside this process.
|
|
$query = Join-Path $env:TEMP "flexera-credential-$PID.txt"
|
|
[IO.File]::WriteAllText($query, "protocol=https`nhost=$GitHost`n`n")
|
|
try { $answer = cmd /c "git credential fill < `"$query`"" } finally { Remove-Item $query -Force }
|
|
$user = ($answer | Where-Object { $_ -like 'username=*' }) -replace '^username=', ''
|
|
$pass = ($answer | Where-Object { $_ -like 'password=*' }) -replace '^password=', ''
|
|
if (-not $user -or -not $pass) { throw "git has no stored login for $GitHost. Run a 'git push' to origin once, then try again." }
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
Add-Type -AssemblyName System.Net.Http
|
|
$client = New-Object System.Net.Http.HttpClient
|
|
$client.Timeout = [TimeSpan]::FromMinutes(15)
|
|
$token = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("${user}:${pass}"))
|
|
$client.DefaultRequestHeaders.Authorization = New-Object System.Net.Http.Headers.AuthenticationHeaderValue('Basic', $token)
|
|
return $client
|
|
}
|
|
|
|
function Read-Response($response, [string]$what) {
|
|
# A request that got no answer at all (no connection, a time-out) arrives here as nothing:
|
|
# Windows PowerShell gives $null for the result of a failed request instead of an error.
|
|
if (-not $response) { throw "$what failed: no answer from $Server" }
|
|
$text = $response.Content.ReadAsStringAsync().Result
|
|
if (-not $response.IsSuccessStatusCode) {
|
|
throw "$what failed: HTTP $([int]$response.StatusCode) $text"
|
|
}
|
|
if ($text) { return $text | ConvertFrom-Json }
|
|
}
|
|
|
|
function Remove-Draft($release) {
|
|
Read-Response ($client.DeleteAsync("$Api/releases/$($release.id)").Result) "Removing the draft $($release.tag_name)" | Out-Null
|
|
# Gitea keeps the name of a removed release on record as a tag, even for a draft, which never
|
|
# had a git tag. That record goes too.
|
|
$response = $client.DeleteAsync("$Api/tags/$($release.tag_name)").Result
|
|
if (-not ($response -and ($response.IsSuccessStatusCode -or [int]$response.StatusCode -eq 404))) {
|
|
Write-Warning "The draft $($release.tag_name) is gone, but Gitea still keeps its name on record. That does no harm: the next release of that version reuses it."
|
|
}
|
|
}
|
|
|
|
# --- 1. Version ----------------------------------------------------------------------------------
|
|
|
|
Step "1/7 Version $Version"
|
|
|
|
if ($Version -notmatch '^\d+\.\d{1,2}\.\d{1,2}$') {
|
|
throw "Version must look like 0.2.0 (major.minor.patch, minor and patch below 100), got '$Version'."
|
|
}
|
|
if ($NotesFile) { $Notes = [IO.File]::ReadAllText((Resolve-Path $NotesFile)) }
|
|
|
|
$client = Get-ApiClient
|
|
|
|
$latestResponse = $client.GetAsync("$Api/releases/latest").Result
|
|
if ($latestResponse.IsSuccessStatusCode) {
|
|
$latest = (Read-Response $latestResponse 'Reading the latest release').tag_name -replace '^v', ''
|
|
if ([version]$Version -le [version]$latest) {
|
|
throw "Version $Version is not higher than the published version $latest."
|
|
}
|
|
Write-Host "Last published version: $latest"
|
|
} elseif ([int]$latestResponse.StatusCode -eq 404) {
|
|
Write-Host "Nothing published yet; this is the first release."
|
|
} else {
|
|
Read-Response $latestResponse 'Reading the latest release' | Out-Null
|
|
}
|
|
|
|
$versionFile = Join-Path $Root 'flexera\version.properties'
|
|
$versionText = [IO.File]::ReadAllText($versionFile)
|
|
$current = ([regex]::Match($versionText, '(?m)^versionName=(.+)$')).Groups[1].Value.Trim()
|
|
|
|
$dirty = git status --porcelain
|
|
if ($dirty -and -not $AllowDirty) {
|
|
throw "There are uncommitted changes. Commit them first, or pass -AllowDirty.`n$($dirty -join "`n")"
|
|
}
|
|
|
|
if ($current -ne $Version) {
|
|
$versionText = [regex]::Replace($versionText, '(?m)^versionName=.+$', "versionName=$Version")
|
|
[IO.File]::WriteAllText($versionFile, $versionText, (New-Object Text.UTF8Encoding($false)))
|
|
git add -- flexera/version.properties
|
|
git commit --quiet -m "Release $Version"
|
|
if ($LASTEXITCODE -ne 0) { throw "Could not commit the version change." }
|
|
Write-Host "Version raised from $current to $Version and committed."
|
|
} else {
|
|
Write-Host "flexera/version.properties already says $Version."
|
|
}
|
|
|
|
# --- 2. Build ------------------------------------------------------------------------------------
|
|
|
|
$apk = Join-Path $Root "build\outputs\apk\lawnWithQuickstepGithub\release\FlexeraLauncher.$Version.github.release.apk"
|
|
# A file in build\outputs says nothing about the source it came from, so each build records its
|
|
# commit next to it, with the APK's SHA-256 to tie the record to that very file. -SkipBuild
|
|
# publishes an APK only on that record's word, and step 7 tags the commit it names.
|
|
$buildRecord = [IO.Path]::ChangeExtension($apk, '.build.json')
|
|
# The files that never go into the APK, as git pathspecs. A commit that changes only these, such
|
|
# as a fix to this script between -BuildOnly and -SkipBuild, leaves the APK as current as it was.
|
|
$notInApk = @(':(exclude)flexera/release.ps1', ':(exclude)WEBSITE')
|
|
|
|
if ($SkipBuild) {
|
|
Step "2/7 Build skipped"
|
|
} else {
|
|
Step "2/7 Building the release APK (about 15 minutes)"
|
|
if (-not (Test-Path (Join-Path $Root 'keystore.properties'))) {
|
|
throw "keystore.properties is missing, so the APK would be signed with the debug key and could not update an installed copy."
|
|
}
|
|
# Read before Gradle starts, because that is when Gradle takes the commit it builds into the
|
|
# app: the About screen shows it after the version number.
|
|
$builtCommit = git rev-parse HEAD
|
|
$builtDirty = [bool](git status --porcelain -- . $notInApk)
|
|
# A release compiles its Kotlin code from scratch. Compiled output reused from an earlier
|
|
# build has produced an APK that crashed at start after a preference class had changed
|
|
# (NoSuchFieldError: $stable), so nothing compiled earlier is trusted here.
|
|
Remove-Item -Recurse -Force (Join-Path $Root "build\intermediates\built_in_kotlinc\$VariantDir") -ErrorAction SilentlyContinue
|
|
Get-ChildItem (Join-Path $Root 'build\kotlin') -Directory -Filter "compile${Variant}Kotlin*" -ErrorAction SilentlyContinue |
|
|
Remove-Item -Recurse -Force
|
|
$env:JAVA_HOME = $JavaHome
|
|
# "2>&1" inside cmd: Gradle prints compiler warnings on its error stream. If this script's
|
|
# output is piped or sent to a file, PowerShell would otherwise take the first such line
|
|
# for an error and stop the build. Only the exit code says whether the build failed.
|
|
cmd /c ".\gradlew.bat assemble$Variant --no-build-cache --console=plain 2>&1"
|
|
if ($LASTEXITCODE -ne 0) { throw "The build failed." }
|
|
}
|
|
if (-not (Test-Path $apk)) { throw "Expected the APK at $apk, but it is not there." }
|
|
|
|
$apkSha256 = (Get-FileHash -Algorithm SHA256 -LiteralPath $apk).Hash
|
|
if ($SkipBuild) {
|
|
# A record that is missing or cannot be read counts as none.
|
|
$record = $null
|
|
try { $record = [IO.File]::ReadAllText($buildRecord) | ConvertFrom-Json } catch { }
|
|
if (-not $record -or $record.commit -notmatch '^[0-9a-f]{40}$' -or $record.sha256 -ne $apkSha256) {
|
|
throw "Nothing records which commit $(Split-Path $apk -Leaf) was built from, or the APK was built again outside this script since. -SkipBuild publishes only an APK that this script built: run it again without -SkipBuild."
|
|
}
|
|
$builtCommit = $record.commit
|
|
$builtDirty = $record.dirty
|
|
} else {
|
|
# Gradle compiles each file when it gets to it, so an edit made while it builds may be in the
|
|
# APK, whole or in part, though no commit has it. The APK then counts as one built with
|
|
# uncommitted changes.
|
|
$edited = git status --porcelain -- . $notInApk
|
|
if ($edited -and -not $builtDirty) {
|
|
Write-Warning "The source was changed while the APK was being built, so the APK may hold changes that no commit has:`n$($edited -join "`n")"
|
|
$builtDirty = $true
|
|
}
|
|
}
|
|
$changed = git diff --name-only $builtCommit HEAD -- . $notInApk
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Commit $builtCommit, which the APK was built from, is not in this repository. Build the APK again (run the script without -SkipBuild)."
|
|
}
|
|
if ($changed) {
|
|
throw "The APK was built from commit $builtCommit, but the commits after it change the app, which the APK may not have. Nothing was published; build it again from the current commit (run the script without -SkipBuild).`n$($changed -join "`n")"
|
|
}
|
|
if (-not $SkipBuild) {
|
|
[IO.File]::WriteAllText($buildRecord, ([ordered]@{ commit = $builtCommit; sha256 = $apkSha256; dirty = $builtDirty } | ConvertTo-Json))
|
|
}
|
|
# Step 1 needs -AllowDirty for any uncommitted edit, the website's included, so the flag says
|
|
# nothing about the APK itself. Whether the APK holds uncommitted changes is said here, in the
|
|
# run that publishes it too.
|
|
if ($builtDirty) {
|
|
Write-Warning "Built from commit $builtCommit, but with uncommitted changes: the APK may hold changes that no commit has."
|
|
} else {
|
|
Write-Host "Built from commit $builtCommit."
|
|
}
|
|
if ($builtDirty -and -not $AllowDirty -and -not $BuildOnly) {
|
|
throw "The APK was built while the source had uncommitted changes, so it matches no commit. Nothing was published. Commit them and build again, or publish this APK as it is with -SkipBuild -AllowDirty."
|
|
}
|
|
|
|
# Step 7 puts the tag v<version> on that commit. A tag of that name already on another commit, left
|
|
# from a withdrawn release of this version, would go on marking the wrong source. -BuildOnly
|
|
# publishes nothing, so it only warns, in time to remove the tag before the run that publishes.
|
|
$tagged = git rev-parse -q --verify "refs/tags/v$Version^{commit}"
|
|
if ($tagged -and $tagged -ne $builtCommit) {
|
|
$staleTag = "The tag v$Version is already on commit $tagged, but the APK was built from $builtCommit, and the script publishes nothing while that tag is there. If it marks a release that was withdrawn, remove it (git tag -d v$Version, and if it was pushed, git push origin :refs/tags/v$Version too) and run the script again with -SkipBuild."
|
|
if ($BuildOnly) { Write-Warning $staleTag } else { throw $staleTag }
|
|
}
|
|
|
|
# --- 3. Signature --------------------------------------------------------------------------------
|
|
|
|
Step "3/7 Checking the signature"
|
|
|
|
$apksigner = Get-ChildItem (Join-Path $env:LOCALAPPDATA 'Android\Sdk\build-tools') -Recurse -Filter 'apksigner.bat' |
|
|
Sort-Object FullName | Select-Object -Last 1
|
|
if (-not $apksigner) { throw "apksigner was not found in the Android SDK's build-tools." }
|
|
$env:JAVA_HOME = $JavaHome
|
|
$certificate = & $apksigner.FullName verify --print-certs $apk
|
|
if ($LASTEXITCODE -ne 0) { throw "The APK's signature does not verify." }
|
|
$signer = ($certificate | Where-Object { $_ -match 'certificate DN' }) -join '; '
|
|
if ($signer -match 'Android Debug') { throw "The APK is signed with the debug key ($signer). Check keystore.properties." }
|
|
# apksigner writes "Signer #1 certificate SHA-256 digest: ..." and, from build-tools 37 on,
|
|
# "V2 Signer: certificate SHA-256 digest: ...".
|
|
$digests = @($certificate | ForEach-Object { if ($_ -match 'certificate SHA-256 digest: ([0-9a-f]+)') { $Matches[1] } } | Sort-Object -Unique)
|
|
if ($digests.Count -ne 1 -or $digests[0] -ne $ReleaseCertificateDigest) {
|
|
$certificate | ForEach-Object { Write-Host $_ }
|
|
throw "The APK is not signed with the release certificate (SHA-256 $ReleaseCertificateDigest), so it could not update any installed copy. keystore.properties must name the original flexera-release.jks; a keystore made anew cannot sign updates."
|
|
}
|
|
Write-Host $signer
|
|
Write-Host ("APK: {0} ({1:N1} MB)" -f (Split-Path $apk -Leaf), ((Get-Item $apk).Length / 1MB))
|
|
|
|
# --- 4. Start it once ----------------------------------------------------------------------------
|
|
|
|
if ($NoSmokeTest) {
|
|
Step "4/7 Start-up check skipped"
|
|
Write-Warning "This APK has not been started anywhere. Try it on a phone before publishing."
|
|
} else {
|
|
Step "4/7 Starting the APK on the emulator"
|
|
|
|
$emulators = @(& $Adb devices | Where-Object { $_ -match '^(emulator-\d+)\s+device$' } |
|
|
ForEach-Object { $Matches[1] })
|
|
# Another project's emulator may run beside this one: the APK goes only to the one of this
|
|
# project, known by its name, or to the only emulator there is.
|
|
$named = @($emulators | Where-Object {
|
|
((& $Adb -s $_ emu avd name) | Select-Object -First 1).Trim() -eq 'Flexera_Launcher_A17'
|
|
})
|
|
if ($named.Count -gt 0) {
|
|
$emulator = $named[0]
|
|
} elseif ($emulators.Count -eq 1) {
|
|
$emulator = $emulators[0]
|
|
} elseif ($emulators.Count -gt 1) {
|
|
throw "Several emulators are running ($($emulators -join ', ')) and none is Flexera_Launcher_A17, so the APK would go to one that may belong to something else. Start Flexera_Launcher_A17, or close the others, and run this again with -SkipBuild."
|
|
} else {
|
|
$emulator = $null
|
|
}
|
|
if (-not $emulator) {
|
|
throw "No running emulator found. Start one (emulator.exe -avd Flexera_Launcher_A17) and run this again with -SkipBuild, or pass -NoSmokeTest."
|
|
}
|
|
|
|
$install = & $Adb -s $emulator install -r $apk
|
|
if ($LASTEXITCODE -ne 0 -or -not ($install -match 'Success')) {
|
|
throw "Could not install the APK on $emulator. If an older build signed with another key is installed there, uninstall it first: adb uninstall $AppId"
|
|
}
|
|
# When this app is the emulator's home app, Android restarts it the moment the old copy is
|
|
# gone, and that first start can die inside Android itself while the files are still being
|
|
# swapped (a NullPointerException in ActivityThread.handleBindApplication, with no line of
|
|
# this app in it). That is not the new build crashing: let the swap settle, then start
|
|
# from a clean slate and judge what happens from there.
|
|
Start-Sleep -Seconds 6
|
|
& $Adb -s $emulator shell am force-stop $AppId
|
|
& $Adb -s $emulator logcat -b crash -c
|
|
& $Adb -s $emulator shell am start -n $HomeActivity | Out-Null
|
|
Write-Host "Installed on $emulator and started; watching for $SmokeTestSeconds seconds..."
|
|
Start-Sleep -Seconds $SmokeTestSeconds
|
|
|
|
$crashes = & $Adb -s $emulator logcat -b crash -d
|
|
$ours = $crashes | Where-Object { $_ -match "Process: $([regex]::Escape($AppId))(,|\s|$)" }
|
|
$alive = & $Adb -s $emulator shell pidof $AppId
|
|
if ($ours -or -not $alive) {
|
|
$crashes | Select-Object -First 12 | ForEach-Object { Write-Host $_ }
|
|
throw "The app crashed or is not running after start. Nothing was published."
|
|
}
|
|
Write-Host "No crash, and the app is running."
|
|
}
|
|
|
|
if ($BuildOnly) {
|
|
Write-Host "`nBuilt and checked, not published: $apk" -ForegroundColor Green
|
|
Write-Host "Publish this file with: .\flexera\release.ps1 -Version $Version -SkipBuild -Notes `"...`""
|
|
return
|
|
}
|
|
|
|
# --- 5. Release ----------------------------------------------------------------------------------
|
|
|
|
Step "5/7 Creating release v$Version in $ReleaseRepository"
|
|
|
|
# The release starts as a draft, which neither the app's update check nor the QR code's address
|
|
# sees, and is published in step 6 once both APKs are attached to it. A run that was stopped in
|
|
# between (Ctrl+C, a closed window, a lost connection) leaves its draft behind, and the server
|
|
# would not take a second release of the same version.
|
|
$drafts = Read-Response ($client.GetAsync("$Api/releases?draft=true&limit=50").Result) 'Looking for an unfinished draft'
|
|
foreach ($draft in $drafts) {
|
|
if ($draft.draft -and $draft.tag_name -eq "v$Version") {
|
|
Remove-Draft $draft
|
|
Write-Host "Removed the unfinished draft of v$Version that an earlier run left behind."
|
|
}
|
|
}
|
|
|
|
# The release is made on the release repository's default branch. Gitea would pick that branch by
|
|
# itself, except for a version whose name it still keeps on record, as it does after a draft was
|
|
# removed by hand in Gitea: then it takes the branch from this request alone, and publishing a
|
|
# release without one fails.
|
|
$branch = (Read-Response ($client.GetAsync($Api).Result) 'Reading the release repository').default_branch
|
|
$body = @{ tag_name = "v$Version"; target_commitish = $branch; name = "Flexera Launcher $Version"; body = $Notes; draft = $true; prerelease = $false } | ConvertTo-Json
|
|
$content = New-Object System.Net.Http.StringContent($body, [Text.Encoding]::UTF8, 'application/json')
|
|
$release = Read-Response ($client.PostAsync("$Api/releases", $content).Result) 'Creating the release'
|
|
|
|
# --- 6. APK --------------------------------------------------------------------------------------
|
|
|
|
Step "6/7 Uploading the APK and publishing the release"
|
|
|
|
# The APK goes up twice. Once under a name with its version, which is what a person looking at
|
|
# the release sees and what the app's updater downloads. And once under a name that never
|
|
# changes, so that <server>/<repo>/releases/download/latest/FlexeraLauncher.apk always leads to
|
|
# the newest APK: the address in the QR code on the app's About screen (FlexeraUpdater.LATEST_APK_URL).
|
|
# The versioned one goes first, because the updater takes the first .apk it finds.
|
|
$assetNames = @("FlexeraLauncher-$Version.apk", 'FlexeraLauncher.apk')
|
|
$uploaded = @()
|
|
$publishing = $false
|
|
try {
|
|
foreach ($assetName in $assetNames) {
|
|
$stream = [IO.File]::OpenRead($apk)
|
|
try {
|
|
$file = New-Object System.Net.Http.StreamContent($stream)
|
|
$file.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse('application/vnd.android.package-archive')
|
|
$form = New-Object System.Net.Http.MultipartFormDataContent
|
|
$form.Add($file, 'attachment', $assetName)
|
|
$uploaded += Read-Response ($client.PostAsync("$Api/releases/$($release.id)/assets?name=$assetName", $form).Result) "Uploading $assetName"
|
|
} finally {
|
|
$stream.Dispose()
|
|
}
|
|
}
|
|
# Only now, with both APKs attached, does the release become the one that the app's update
|
|
# check and the QR code's address find.
|
|
$publish = New-Object System.Net.Http.HttpRequestMessage((New-Object System.Net.Http.HttpMethod 'PATCH'), "$Api/releases/$($release.id)")
|
|
$publish.Content = New-Object System.Net.Http.StringContent('{"draft": false}', [Text.Encoding]::UTF8, 'application/json')
|
|
$publishing = $true
|
|
if ((Read-Response ($client.SendAsync($publish).Result) 'Publishing the release').draft) {
|
|
throw "Publishing the release failed: the server kept it as a draft."
|
|
}
|
|
} catch {
|
|
# The app does not see the draft, but it would stand in the next run's way. A release whose
|
|
# publishing went through with only the answer lost stays, though: it has both APKs.
|
|
$failure = $_
|
|
$state = $null
|
|
try {
|
|
$state = Read-Response ($client.GetAsync("$Api/releases/$($release.id)").Result) 'Reading the draft'
|
|
if ($state.draft) {
|
|
Remove-Draft $state
|
|
Write-Host "The draft v$Version was removed again; nothing was published."
|
|
} else {
|
|
Write-Warning "v$Version was published after all, with both APKs. Only the source tag is missing: git tag -a v$Version -m `"Flexera Launcher $Version`" $builtCommit"
|
|
}
|
|
} catch {
|
|
# Once the request to publish has gone out, a release that cannot be read back may be live.
|
|
if ($publishing -and -not $state) {
|
|
Write-Warning "Whether v$Version was published could not be checked ($($_.Exception.Message)). If $Api/releases/latest names v$Version, it was, with both APKs, and only the source tag is missing: git tag -a v$Version -m `"Flexera Launcher $Version`" $builtCommit. If not, the next run removes the draft."
|
|
} else {
|
|
Write-Warning "The draft v$Version could not be removed ($($_.Exception.Message)). Only you can see it, and the next run removes it."
|
|
}
|
|
}
|
|
throw $failure
|
|
}
|
|
$uploaded | ForEach-Object { Write-Host "Uploaded: $($_.browser_download_url)" }
|
|
|
|
# --- 7. Source tag -------------------------------------------------------------------------------
|
|
|
|
Step "7/7 Tagging the source"
|
|
|
|
# The commit the APK was built from, which need not be HEAD: a fix to this script may have been
|
|
# committed after it, and the branch may have moved on while the APK went up.
|
|
if ($tagged) {
|
|
Write-Host "The tag v$Version is already on $builtCommit."
|
|
} else {
|
|
git tag -a "v$Version" -m "Flexera Launcher $Version" $builtCommit
|
|
if ($LASTEXITCODE -ne 0) { Write-Warning "Could not create the tag v$Version. Create it with: git tag -a v$Version -m `"Flexera Launcher $Version`" $builtCommit" }
|
|
}
|
|
|
|
if ($PushSource) {
|
|
git push origin HEAD "v$Version"
|
|
if ($LASTEXITCODE -ne 0) { Write-Warning "Pushing the source failed; the release itself is published." }
|
|
} else {
|
|
Write-Host "The source commit and tag are local only. Push them with: git push origin main v$Version"
|
|
}
|
|
|
|
Write-Host "`nPublished Flexera Launcher $Version" -ForegroundColor Green
|
|
Write-Host "$Server/$ReleaseRepository/releases/tag/v$Version"
|