Automate patch release versions and standardize Linux deb packages

This commit is contained in:
tongtong committed 2026-11-13 12:01:35 +08:00
1 parent 0d269f3ded
commit 69a951f6d0
5 files changed
+67 -10

No files matched your search

+11 -3
View File
@@ -1,7 +1,8 @@
param(
[ValidateSet('All','Avalonia','Flutter')][string]$Edition='All',
[string]$Compiler,
[switch]$SkipBuild
[switch]$SkipBuild,
[switch]$ReuseVersion
)
$ErrorActionPreference='Stop'
$root=Split-Path $PSScriptRoot -Parent
@@ -10,8 +11,15 @@ if (-not $Compiler) {
$Compiler=$candidates | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1
}
if (-not $Compiler) { throw 'Install Inno Setup 6/7 or specify -Compiler path/to/ISCC.exe' }
$version=[regex]::Match((Get-Content (Join-Path $root 'Cargo.toml') -Raw),'(?m)^version = "([0-9.]+)"').Groups[1].Value
if (-not $version) { throw 'Workspace version missing' }
if ($SkipBuild -and -not $ReuseVersion) { throw 'SkipBuild requires ReuseVersion; new releases must rebuild their binaries' }
$versionArgs=@((Join-Path $PSScriptRoot 'release-version.py'))
if ($ReuseVersion) { $versionArgs+='--reuse' }
$version=(& python @versionArgs).Trim()
if ($LASTEXITCODE) { throw 'Release version update failed' }
if (-not $SkipBuild) {
& (Join-Path $PSScriptRoot 'build.ps1')
if ($LASTEXITCODE) { throw 'Backend build failed' }
}
$output=Join-Path $root 'bin/installers'
New-Item -ItemType Directory -Force -Path $output | Out-Null
foreach ($name in @('Avalonia','Flutter')) {
+11 -7
View File
@@ -4,9 +4,14 @@ root=$(cd -- "$(dirname -- "$0")/.." && pwd)
mode=${1:-all}
case "$mode" in all|avalonia|agent|server|flutter) ;; *) echo 'Usage: build-linux-packages.sh [all|avalonia|agent|server|flutter]' >&2; exit 2;; esac
case "$(uname -m)" in x86_64) arch=amd64; rid=linux-x64;; aarch64) arch=arm64; rid=linux-arm64;; *) echo 'Unsupported architecture' >&2; exit 1;; esac
version=$(sed -n 's/^version = "\([0-9.]*\)"/\1/p' "$root/Cargo.toml" | head -1 | tr -d '\r')
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit 1
command -v dpkg-deb >/dev/null
# One patch increment per release; use ADS_REUSE_VERSION=1 for its other platform.
version_args=()
if [[ "${ADS_REUSE_VERSION:-0}" == 1 ]]; then version_args+=(--reuse); fi
version=$(python3 "$root/scripts/release-version.py" "${version_args[@]}")
if [[ "${ADS_REUSE_VERSION:-0}" != 1 ]]; then
(cd "$root" && cargo build --release --locked -p ads-agent -p ads-client -p adsctl -p ads-usb)
fi
output="$root/bin/installers/linux"; mkdir -p "$output"
stage=$(mktemp -d)
trap 'rm -rf -- "$stage"' EXIT
@@ -28,7 +33,7 @@ package() {
find "$payload" -type d -exec chmod 755 {} +
find "$payload" -type f -exec chmod 644 {} +
check_elf "$payload/$exe"; chmod 755 "$payload/$exe"
for tool in ads-agent ads-client adsctl ads-server ads-relay; do
for tool in ads-agent ads-client adsctl ads-usb ads-server ads-relay; do
if [[ -f "$payload/$tool" ]]; then check_elf "$payload/$tool"; chmod 755 "$payload/$tool"; fi
done
printf '#!/bin/sh\nexec /opt/ttstd/%s/%s "$@"\n' "$name" "$exe" > "$tree/usr/bin/$name"
@@ -43,7 +48,6 @@ package() {
printf 'Package: %s\nVersion: %s\nArchitecture: %s\nMaintainer: TongTong Studio\nDepends: %s\nDescription: ADS %s remote Android management\n' "$name" "$version" "$arch" "$deps" "$kind" > "$tree/DEBIAN/control"
chmod 755 "$tree/DEBIAN"; chmod 644 "$tree/DEBIAN/control"
dpkg-deb --root-owner-group --build "$tree" "$output/${name}_${version}_${arch}.deb"
tar -czf "$output/${name}-${version}-${rid}.tar.gz" -C "$payload" .
}
if [[ "$mode" == all || "$mode" == agent ]]; then
mkdir -p "$stage/agent-source"
@@ -61,14 +65,14 @@ if [[ "$mode" == all || "$mode" == avalonia ]]; then
(cd "$root/desktop" && dotnet publish Ads.Desktop -c Release -r "$rid" --self-contained true -o "$source" --nologo)
fi
mkdir -p "$stage/avalonia-source"; cp -a "$source/." "$stage/avalonia-source/"
for tool in ads-agent adsctl ads-client; do cp "$backend/$tool" "$stage/avalonia-source/"; done
for tool in ads-agent adsctl ads-client ads-usb; do cp "$backend/$tool" "$stage/avalonia-source/"; done
package avalonia Ads.Desktop "$stage/avalonia-source" 'libc6 (>= 2.31), libgcc-s1, libstdc++6, libx11-6, libice6, libsm6, libfontconfig1, libfreetype6, libicu76 | libicu74 | libicu72 | libicu70, libssl3t64 | libssl3, zlib1g, adb, scrcpy'
fi
if [[ "$mode" == flutter ]]; then
: "${ADS_FLUTTER_BUNDLE:?Provide a native Linux Flutter release bundle}"
mkdir -p "$stage/flutter-source"; cp -a "$ADS_FLUTTER_BUNDLE/." "$stage/flutter-source/"
for tool in ads-agent adsctl ads-client; do cp "$backend/$tool" "$stage/flutter-source/"; done
for tool in ads-agent adsctl ads-client ads-usb; do cp "$backend/$tool" "$stage/flutter-source/"; done
package flutter ads_manager "$stage/flutter-source" 'libc6 (>= 2.31), libstdc++6, libgtk-3-0, libayatana-appindicator3-1, adb, scrcpy'
fi
(cd "$output" && sha256sum ./*.deb ./*.tar.gz > SHA256SUMS)
(cd "$output" && sha256sum ./*.deb > SHA256SUMS)
echo "Linux packages: $output"
+33
View File
@@ -0,0 +1,33 @@
"""Advance the shared release version once, or read it for another platform."""
import argparse
import re
from pathlib import Path
def update(root, reuse=False):
cargo = root / "Cargo.toml"
content = cargo.read_text(encoding="utf-8")
old = re.search(r'^version = "(\d+\.\d+\.\d+)"', content, re.M)[1]
if reuse:
return old
major, minor, patch = map(int, old.split("."))
version = f"{major}.{minor}.{patch + 1}"
changes = {cargo: content.replace(f'version = "{old}"', f'version = "{version}"', 1)}
lock = root / "Cargo.lock"
changes[lock] = re.sub(r'(name = "ads-[^"\n]+"\nversion = ")[^"]+("\n)', lambda m: m[1] + version + m[2], lock.read_text(encoding="utf-8"))
pub = root / "flutter_manager/pubspec.yaml"
changes[pub] = re.sub(r'^version: ([^\n]+)', lambda m: f"version: {version}+{int(m[1].split('+')[1]) + 1}", pub.read_text(encoding="utf-8"), flags=re.M)
project = root / "desktop/Ads.Desktop/Ads.Desktop.csproj"
text = project.read_text(encoding="utf-8")
text = re.sub(r'<Version>[^<]+</Version>', '', text)
changes[project] = text.replace('<PropertyGroup>', f'<PropertyGroup><Version>{version}</Version>', 1)
for path, text in changes.items():
path.write_text(text, encoding="utf-8", newline="\n")
return version
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--reuse", action="store_true", help="Use the version already allocated to this cross-platform release")
args = parser.parse_args()
print(update(Path(__file__).resolve().parent.parent, args.reuse))