Repository navigation
Fix Android edge-panel drops and publish versioned releases automatically #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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() |
| 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() |
| 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 | ||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an older failed or cancelled CI run is rerun after newer main releases exist, its completed 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 | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
@@ -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: | ||
|
|
@@ -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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ android/captures/ | |
| android/.kotlin/ | ||
|
|
||
| # Editors / OS | ||
| __pycache__/ | ||
| .DS_Store | ||
| *.swp | ||
| .vscode/ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub Actions rejects this workflow because
queueis not a supported property of theconcurrencymap; the documented keys are onlygroupandcancel-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 👍 / 👎.