Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/scripts/release_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""Choose release tags and stamp both apps in the build checkout (no commits)."""

import argparse
from pathlib import Path
import re
import subprocess
import tomllib

ROOT = Path(__file__).resolve().parents[2]
VERSION = re.compile(r"v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)")


def parse_version(value):
match = VERSION.fullmatch(value)
if not match:
raise ValueError(f"Expected a stable version such as v0.1.5, got {value!r}")
return tuple(map(int, match.groups()))


def choose_version(tags, minimum, current_tags=(), requested=""):
if requested:
version = parse_version(requested)
else:
# Rerunning the same commit repairs its release instead of consuming a patch.
floor = parse_version(minimum)
existing = [parse_version(t) for t in current_tags if t.startswith("v") and VERSION.fullmatch(t) and parse_version(t) >= floor]
if existing:
version = max(existing)
else:
stable = [parse_version(t) for t in tags if t.startswith("v") and VERSION.fullmatch(t)]
latest = max(stable, default=(0, 0, 0))
version = max(floor, (*latest[:2], latest[2] + 1))
return ".".join(map(str, version))


def version_code(version):
major, minor, patch = parse_version(version)
code = major * 1_000_000 + minor * 1_000 + patch
if minor >= 1000 or patch >= 1000 or not 1 <= code <= 2_100_000_000:
raise ValueError("Version exceeds the Android versionCode range")
return code


def stamp(version, root=ROOT):
code = version_code(version)
changes = {
"linux/Cargo.toml": [(r'(?m)^version = "[^"]+"$', f'version = "{version}"')],
"linux/Cargo.lock": [(r'(?m)(^name = "airbridge"\nversion = ")[^"]+("$)', rf'\g<1>{version}\2')],
"android/app/build.gradle.kts": [
(r'(?m)^(\s*versionName = ")[^"]+("$)', rf'\g<1>{version}\2'),
(r'(?m)^(\s*versionCode = )\d+$', rf'\g<1>{code}'),
],
}
for name, replacements in changes.items():
path = root / name
text = path.read_text()
for pattern, replacement in replacements:
text, count = re.subn(pattern, replacement, text)
if count != 1:
raise ValueError(f"Expected one version field in {name}, found {count}")
path.write_text(text)


def git(*args):
return subprocess.check_output(["git", *args], cwd=ROOT, text=True).strip()


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("command", choices=("select", "stamp"))
parser.add_argument("version", nargs="?", default="")
parser.add_argument("--automatic", action="store_true")
args = parser.parse_args()
if args.command == "stamp":
stamp(".".join(map(str, parse_version(args.version))))
return
tags = git("tag", "--list").splitlines()
current = git("tag", "--points-at", "HEAD").splitlines() if args.automatic else []
minimum = tomllib.loads((ROOT / "linux/Cargo.toml").read_text())["package"]["version"]
version = choose_version(tags, minimum, current, args.version)
version_code(version)
tag = f"v{version}"
sha = git("rev-parse", "HEAD")
if tag in tags and git("rev-parse", f"refs/tags/{tag}^{{commit}}") != sha:
raise ValueError(f"{tag} already belongs to another commit; choose a new version")
print(f"version={version}\ntag={tag}\nsha={sha}")


if __name__ == "__main__":
main()
48 changes: 48 additions & 0 deletions .github/scripts/test_release_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from pathlib import Path
import tempfile
import unittest

from release_version import ROOT, choose_version, parse_version, stamp, version_code


class ReleaseVersionTest(unittest.TestCase):
def test_starts_at_015_ignoring_old_main_builds(self):
self.assertEqual(choose_version(["v0.1.0", "main-45"], "0.1.5"), "0.1.5")
self.assertEqual(choose_version([], "0.1.5"), "0.1.5")
self.assertEqual(choose_version(["v0.1.0"], "0.1.5", ["v0.1.0"]), "0.1.5")

def test_increments_numerically_and_reuses_a_tag_on_retry(self):
tags = ["v0.1.5", "v0.1.9", "v0.1.10", "v1.0.0-rc.1", "main-999"]
self.assertEqual(choose_version(tags, "0.1.5"), "0.1.11")
self.assertEqual(choose_version(tags, "0.1.5", ["v0.1.5"]), "0.1.5")
self.assertEqual(choose_version(tags + ["v0.2.0"], "0.1.5"), "0.2.1")
self.assertEqual(choose_version(tags, "0.2.0"), "0.2.0")

def test_explicit_versions_are_validated(self):
self.assertEqual(choose_version([], "0.1.5", requested="v0.1.6"), "0.1.6")
for value in ["main-45", "0.01.5", "0.1.5\nsha=bad", "0.1.5; echo bad", "0.1.5-rc.1"]:
with self.subTest(value=value), self.assertRaises(ValueError):
parse_version(value)
self.assertLess(version_code("0.1.5"), version_code("0.1.6"))
self.assertLess(version_code("0.1.999"), version_code("0.2.0"))
with self.assertRaises(ValueError):
version_code("0.1.1000")

def test_stamps_both_apps_and_the_lockfile(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
names = ["linux/Cargo.toml", "linux/Cargo.lock", "android/app/build.gradle.kts"]
for name in names:
target = root / name
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text((ROOT / name).read_text())
stamp("0.1.6", root)
self.assertIn('version = "0.1.6"', (root / names[0]).read_text())
self.assertIn('name = "airbridge"\nversion = "0.1.6"', (root / names[1]).read_text())
android = (root / names[2]).read_text()
self.assertIn('versionName = "0.1.6"', android)
self.assertIn('versionCode = 1006', android)


if __name__ == "__main__":
unittest.main()
63 changes: 2 additions & 61 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
workspaces: linux
- name: Release version tests
run: python3 -m unittest discover -s ../.github/scripts -p 'test_*.py'
- run: cargo fmt --check
- run: node tools/test-desktop-drop.js
- run: cargo clippy --all-targets --locked -- -D warnings
Expand All @@ -36,9 +38,6 @@ jobs:
# The drop zone's pure logic and its offscreen renders (snapshots are uploaded).
- run: "cargo test --locked --features edge edge::"
- run: cargo build --release --locked --features webview,edge
env:
# Lets the in-app updater tell which main build this is.
AIRBRIDGE_BUILD: ${{ github.run_number }}
- run: packaging/appimage.sh target/release/airbridge
- uses: actions/upload-artifact@v6
with:
Expand Down Expand Up @@ -89,61 +88,3 @@ jobs:
path: |
android/app/build/reports
android/app/build/linux-interop.log

release:
name: Publish main release build
needs: [linux, android]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: write
steps:
# Reuse the release binaries from this run, after all tests have passed.
- uses: actions/download-artifact@v8
with:
name: airbridge-linux-x86_64
path: release
- uses: actions/download-artifact@v8
with:
name: airbridge-android-apk
path: release
- name: Package and sign release assets
env:
UPDATE_SIGNING_KEY: ${{ secrets.UPDATE_SIGNING_KEY }}
TAG: main-${{ github.run_number }}
run: |
test -s release/airbridge-x86_64.AppImage
test -s release/app-release.apk
[ -n "$UPDATE_SIGNING_KEY" ] || { echo "UPDATE_SIGNING_KEY secret is missing; refusing to publish an unsigned build"; exit 1; }
# Artifact downloads do not preserve the Linux executable bit.
install -m755 release/airbridge-x86_64.AppImage airbridge-x86_64.AppImage
cp release/app-release.apk airbridge-android.apk
# The in-app updater checks this: the AppImage, a newline, then its tag.
umask 077
printf '%s\n' "$UPDATE_SIGNING_KEY" > "$RUNNER_TEMP/key.pem"
{ cat airbridge-x86_64.AppImage; printf '\n%s' "$TAG"; } > "$RUNNER_TEMP/message"
openssl pkeyutl -sign -rawin -inkey "$RUNNER_TEMP/key.pem" -in "$RUNNER_TEMP/message" -out airbridge-x86_64.AppImage.sig
rm -f "$RUNNER_TEMP/key.pem" "$RUNNER_TEMP/message"
test "$(stat -c %s airbridge-x86_64.AppImage.sig)" -eq 64
- uses: softprops/action-gh-release@v3
with:
tag_name: main-${{ github.run_number }}
name: "Main build #${{ github.run_number }}"
target_commitish: ${{ github.sha }}
prerelease: true
make_latest: false
fail_on_unmatched_files: true
body: |
Automatic prerelease from a successful main-branch CI run.
Commit: `${{ github.sha }}`

**Downloads**
- `airbridge-android.apk`: Android 10 or newer.
- `airbridge-x86_64.AppImage`: make it executable and run it. It updates itself from the app's Update button.

The APK uses a debug signing key; Android may require uninstalling the previous build before installation.
files: |
airbridge-x86_64.AppImage
airbridge-x86_64.AppImage.sig
airbridge-android.apk
94 changes: 67 additions & 27 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
name: Release

on:
workflow_run:
workflows: ["CI"]
types: [completed]
branches: [main]
push:
tags: ["v*"]
# Or run it from the Actions tab: it builds the chosen commit and creates the tag.
workflow_dispatch:
inputs:
version:
description: "Version to release, like v0.1.0"
required: true
description: "Stable version, e.g. v0.1.5 (leave empty for the next patch)"
required: false

permissions:
contents: read

env:
VERSION: ${{ inputs.version || github.ref_name }}

# Runs for one version wait for each other, so the tag check below cannot race.
# Serialize selection through publication: two main builds cannot choose the same patch.
concurrency:
group: release-${{ inputs.version || github.ref_name }}
group: airbridge-release
queue: max

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the unsupported concurrency queue key

GitHub Actions rejects this workflow because queue is not a supported property of the concurrency map; the documented keys are only group and cancel-in-progress. Consequently none of the automatic, tag, or manual release paths can run until this field is removed or serialization is implemented differently. See GitHub's concurrency syntax.

Useful? React with 👍 / 👎.

cancel-in-progress: false

jobs:
prepare:
name: Validate release
# workflow_run also fires for failed runs and pull requests. Only a successful
# push to this repository's main branch may trigger an automatic release.
if: >-
github.event_name != 'workflow_run' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_repository.full_name == github.repository)
Comment on lines +31 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject stale main workflow reruns before assigning a version

When an older failed or cancelled CI run is rerun after newer main releases exist, its completed workflow_run still passes this condition because only the original event and repository are checked. Line 45 then checks out that run's old head_sha, while the version selector assigns the next patch, publishing stale code as the newest semantic version and causing current installations to offer a downgrade. Verify that head_sha is still the tip of main before creating an automatic release.

Useful? React with 👍 / 👎.

runs-on: ubuntu-24.04
timeout-minutes: 5
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
sha: ${{ steps.version.outputs.sha }}
steps:
- name: Check the version
if: github.event_name == 'workflow_dispatch'
run: |
[[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]] && git check-ref-format "refs/tags/$VERSION" ||
{ echo "Version must look like v1.2.3 or v1.2.3-rc.1, got $VERSION"; exit 1; }
- uses: actions/checkout@v5
- name: Check the tag is free or already here
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
fetch-depth: 0
persist-credentials: false
- name: Choose the release version
id: version
env:
REQUESTED_VERSION: ${{ inputs.version || (github.event_name == 'push' && github.ref_name) || '' }}
run: |
# A tag that exists stays where it is, so never attach these builds to another commit's tag.
tagged=$(git ls-remote origin "refs/tags/$VERSION^{}" | cut -f1)
tagged=${tagged:-$(git ls-remote origin "refs/tags/$VERSION" | cut -f1)}
if [ -n "$tagged" ] && [ "$tagged" != "$GITHUB_SHA" ]; then
echo "$VERSION is already tagged at $tagged, not at $GITHUB_SHA. Pick a new version."
exit 1
fi
args=()
if [ "$GITHUB_EVENT_NAME" = workflow_run ]; then args+=(--automatic); fi
python3 .github/scripts/release_version.py select "$REQUESTED_VERSION" "${args[@]}" >> "$GITHUB_OUTPUT"

linux:
name: Linux release
Expand All @@ -50,6 +61,13 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v5
with:
ref: ${{ needs.prepare.outputs.sha }}
persist-credentials: false
- name: Stamp app versions
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: python3 .github/scripts/release_version.py stamp "$VERSION"
- name: System libraries (native window feature)
timeout-minutes: 5
run: bash .github/scripts/install-system-deps.sh libwebkit2gtk-4.1-dev libgtk-3-dev libxdo-dev libgtk-layer-shell-dev
Expand All @@ -76,6 +94,13 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v5
with:
ref: ${{ needs.prepare.outputs.sha }}
persist-credentials: false
- name: Stamp app versions
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: python3 .github/scripts/release_version.py stamp "$VERSION"
- uses: actions/setup-java@v5
with:
distribution: temurin
Expand All @@ -94,7 +119,7 @@ jobs:

publish:
name: Publish release
needs: [linux, android]
needs: [prepare, linux, android]
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
Expand All @@ -104,23 +129,38 @@ jobs:
with:
pattern: release-*
merge-multiple: true
- name: Check release assets
- name: Check and sign release assets
env:
UPDATE_SIGNING_KEY: ${{ secrets.UPDATE_SIGNING_KEY }}
TAG: ${{ needs.prepare.outputs.tag }}
run: |
test -s airbridge-x86_64.AppImage
chmod +x airbridge-x86_64.AppImage
test -s airbridge-android.apk
[ -n "$UPDATE_SIGNING_KEY" ] || { echo "UPDATE_SIGNING_KEY secret is missing; refusing to publish an unsigned build"; exit 1; }
umask 077
printf '%s\n' "$UPDATE_SIGNING_KEY" > "$RUNNER_TEMP/key.pem"
trap 'rm -f "$RUNNER_TEMP/key.pem" "$RUNNER_TEMP/message"' EXIT
# The signature binds the AppImage to its version tag.
{ cat airbridge-x86_64.AppImage; printf '\n%s' "$TAG"; } > "$RUNNER_TEMP/message"
openssl pkeyutl -sign -rawin -inkey "$RUNNER_TEMP/key.pem" -in "$RUNNER_TEMP/message" -out airbridge-x86_64.AppImage.sig
test "$(stat -c %s airbridge-x86_64.AppImage.sig)" -eq 64
- uses: softprops/action-gh-release@v3
with:
tag_name: ${{ env.VERSION }}
target_commitish: ${{ github.sha }}
prerelease: ${{ contains(env.VERSION, '-') }}
tag_name: ${{ needs.prepare.outputs.tag }}
name: ${{ needs.prepare.outputs.tag }}
target_commitish: ${{ needs.prepare.outputs.sha }}
prerelease: false
make_latest: legacy
fail_on_unmatched_files: true
body: |
**Downloads**
- `airbridge-android.apk`: the Android app (Android 10 or newer). Allow installs from your browser or file manager when asked.
- `airbridge-x86_64.AppImage`: the Linux app. Make it executable and run it (needs GTK 3 and WebKitGTK 4.1, present on most desktops).
- `airbridge-x86_64.AppImage`: the Linux app. Make it executable and run it (needs GTK 3 and WebKitGTK 4.1, present on most desktops). Updates itself from the app's Update button.

The APK is signed with a debug key made for this build, not a private release key, so a newer release may need the old app uninstalled first. See [SECURITY.md](https://github.com/${{ github.repository }}/blob/${{ env.VERSION }}/docs/SECURITY.md).
The APK is signed with a debug key made for this build, not a private release key, so a newer release may need the old app uninstalled first. See [SECURITY.md](https://github.com/${{ github.repository }}/blob/${{ needs.prepare.outputs.tag }}/docs/SECURITY.md).
files: |
airbridge-x86_64.AppImage
airbridge-x86_64.AppImage.sig
airbridge-android.apk
generate_release_notes: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ android/captures/
android/.kotlin/

# Editors / OS
__pycache__/
.DS_Store
*.swp
.vscode/
Loading