Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

ci: SwiftUI app bundle and XCUITest after merge, post-merge failure alert and issue (#6597)

Francesco Bonaccif47bfd3d1c54
diff --git a/.github/scripts/postmerge_issue.py b/.github/scripts/postmerge_issue.py
new file mode 100644
index 0000000000..1fe4f91e90
--- /dev/null
+++ b/.github/scripts/postmerge_issue.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python3
+"""Open or update ONE issue per workflow that fails on main after merge.
+
+Heavy suites run on main (and at release) instead of on every pull request, so a
+failure there lands on a commit that is already merged and is fixed forward. The
+alert goes out through workflow-failure-alerts.yml (Alertmanager). This script
+adds the tracking issue:
+
+ - first red run: opens "Post-merge CI failing on main: <workflow>" with the label ci-postmerge;
+ - later red runs: comment on that same issue (never a second one);
+ - a green run: comments and closes it.
+
+Only runs on the default branch from a push or a manual dispatch count; a pull
+request or feature-branch run says nothing about main. Standard library only,
+talks to GitHub through the gh CLI.
+
+ postmerge_issue.py --workflow "CI: Cua Spaces" --conclusion failure --event push \
+ --branch main --default-branch main --sha <sha> --run-url <url> --repo trycua/cua
+"""
+
+from __future__ import annotations
+
+import argparse
+import json
+import subprocess
+import sys
+
+LABEL = "ci-postmerge"
+FAILED = {"failure", "timed_out", "startup_failure"}
+EVENTS = {"push", "workflow_dispatch"}
+
+
+def gh(*args: str) -> str:
+ return subprocess.run(["gh", *args], check=True, capture_output=True, text=True).stdout
+
+
+def title_for(workflow: str) -> str:
+ return f"Post-merge CI failing on main: {workflow}"
+
+
+def find_open(workflow: str, repo: str, run=gh) -> int | None:
+ rows = json.loads(run("issue", "list", "--repo", repo, "--label", LABEL, "--state", "open",
+ "--limit", "100", "--json", "number,title"))
+ want = title_for(workflow)
+ for row in rows:
+ if row["title"] == want:
+ return int(row["number"])
+ return None
+
+
+def act(a, run=gh) -> str:
+ """Returns what it did: ignored, opened, commented, closed or nothing."""
+ if a.event not in EVENTS or a.branch != a.default_branch:
+ return "ignored"
+ short = (a.sha or "")[:10]
+ existing = find_open(a.workflow, a.repo, run)
+ if a.conclusion in FAILED:
+ why = {"failure": "a job failed", "timed_out": "the run timed out",
+ "startup_failure": "GitHub rejected the run before any job started"}[a.conclusion]
+ line = f"`{a.workflow}` failed on main at {short}: {why}. Run: {a.run_url}"
+ if existing is None:
+ body = (line + "\n\nThis suite runs after merge (and at release) instead of on every pull request, "
+ "so the break is already on main. Fix forward: open a PR against main that repairs it. "
+ "This issue is updated by each later failure and closed by the next green run. "
+ "Alert: Alertmanager, source github-actions.")
+ run("label", "create", LABEL, "--repo", a.repo, "--color", "B60205", "--force",
+ "--description", "A suite that runs after merge is red on main")
+ run("issue", "create", "--repo", a.repo, "--title", title_for(a.workflow), "--label", LABEL, "--body", body)
+ return "opened"
+ run("issue", "comment", str(existing), "--repo", a.repo, "--body", "Still failing. " + line)
+ return "commented"
+ if a.conclusion == "success" and existing is not None:
+ run("issue", "close", str(existing), "--repo", a.repo, "--comment",
+ f"Green again on main at {short}: {a.run_url}")
+ return "closed"
+ return "nothing"
+
+
+def main(argv: list[str] | None = None) -> int:
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
+ for name in ("workflow", "conclusion", "event", "branch", "default-branch", "sha", "run-url", "repo"):
+ ap.add_argument("--" + name, required=True)
+ a = ap.parse_args(argv)
+ print(act(a))
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/.github/scripts/tests/test_ci_cua_spaces_macos_workflow.py b/.github/scripts/tests/test_ci_cua_spaces_macos_workflow.py
index c3bcdc5090..437a4f74f9 100644
--- a/.github/scripts/tests/test_ci_cua_spaces_macos_workflow.py
+++ b/.github/scripts/tests/test_ci_cua_spaces_macos_workflow.py
@@ -56,7 +56,9 @@ def test_the_library_is_compiled_once_and_downloaded_by_the_rest():
assert [n for n in JOBS if "./.github/actions/spaces-rust-slice" in uses(n)] == ["ffi"]
for name in SWIFT_JOBS:
job = JOBS[name]
- assert job["needs"] == "ffi", name
+ needs = [job["needs"]] if isinstance(job["needs"], str) else job["needs"]
+ # Downloads the library from `ffi`; `changes` (the packaging-path filter) is the only other job it may wait for.
+ assert "ffi" in needs and set(needs) <= {"ffi", "changes"}, name
download = [s for s in job["steps"] if str(s.get("uses", "")).startswith("actions/download-artifact")]
assert len(download) == 1 and download[0]["with"]["name"] == ARTIFACT, name
assert download[0]["with"]["path"] == "libs/cua/target/release", name
diff --git a/.github/scripts/tests/test_postmerge_issue.py b/.github/scripts/tests/test_postmerge_issue.py
new file mode 100644
index 0000000000..336043ac36
--- /dev/null
+++ b/.github/scripts/tests/test_postmerge_issue.py
@@ -0,0 +1,71 @@
+"""Run: python3 .github/scripts/tests/test_postmerge_issue.py"""
+
+import argparse
+import json
+import sys
+import unittest
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
+import postmerge_issue as pm # noqa: E402
+
+WF = "CI: Cua Spaces for macOS (SwiftUI)"
+
+
+def a(conclusion="failure", event="push", branch="main"):
+ return argparse.Namespace(workflow=WF, conclusion=conclusion, event=event, branch=branch, default_branch="main",
+ sha="0123456789abcdef", run_url="https://example.invalid/run/1", repo="trycua/cua")
+
+
+def runner(open_issues):
+ calls = []
+
+ def run(*args):
+ calls.append(args)
+ if args[:2] == ("issue", "list"):
+ return json.dumps(open_issues)
+ return ""
+ return run, calls
+
+
+class PostMerge(unittest.TestCase):
+ def test_first_failure_opens_one_issue(self):
+ run, calls = runner([])
+ self.assertEqual(pm.act(a(), run), "opened")
+ create = [c for c in calls if c[:2] == ("issue", "create")]
+ self.assertEqual(len(create), 1)
+ self.assertIn(pm.title_for(WF), create[0])
+
+ def test_second_failure_comments_instead_of_a_second_issue(self):
+ run, calls = runner([{"number": 7, "title": pm.title_for(WF)}])
+ self.assertEqual(pm.act(a(), run), "commented")
+ self.assertFalse([c for c in calls if c[:2] == ("issue", "create")])
+ self.assertTrue([c for c in calls if c[:3] == ("issue", "comment", "7")])
+
+ def test_other_workflows_issue_is_not_reused(self):
+ run, _ = runner([{"number": 7, "title": pm.title_for("CI: Cua Spaces")}])
+ self.assertEqual(pm.act(a(), run), "opened")
+
+ def test_green_closes_the_open_issue(self):
+ run, calls = runner([{"number": 7, "title": pm.title_for(WF)}])
+ self.assertEqual(pm.act(a("success"), run), "closed")
+ self.assertTrue([c for c in calls if c[:3] == ("issue", "close", "7")])
+
+ def test_green_without_an_issue_does_nothing(self):
+ run, calls = runner([])
+ self.assertEqual(pm.act(a("success"), run), "nothing")
+ self.assertFalse([c for c in calls if c[0] == "issue" and c[1] != "list"])
+
+ def test_pull_requests_and_feature_branches_are_ignored(self):
+ run, calls = runner([])
+ self.assertEqual(pm.act(a(event="pull_request"), run), "ignored")
+ self.assertEqual(pm.act(a(branch="feature"), run), "ignored")
+ self.assertEqual(calls, [])
+
+ def test_cancelled_changes_nothing(self):
+ run, _ = runner([{"number": 7, "title": pm.title_for(WF)}])
+ self.assertEqual(pm.act(a("cancelled"), run), "nothing")
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/.github/workflows/ci-cua-spaces-macos.yml b/.github/workflows/ci-cua-spaces-macos.yml
index fefdddefa2..0fe955802f 100644
--- a/.github/workflows/ci-cua-spaces-macos.yml
+++ b/.github/workflows/ci-cua-spaces-macos.yml
@@ -7,7 +7,8 @@ name: "CI: Cua Spaces for macOS (SwiftUI)"
# (libs/spaces-app-swift: drift gate and tests), the notch package shared
# with the Electron app's notch helper (libs/spaces-notch-swift), the Swift package's unit,
# parity and snapshot tests, the app bundle (with Sparkle, and a launch
-# check), and the XCUITests. Unsigned; the only secret is the optional
+# check), and the XCUITests (the bundle and the XCUITests run on a pull request
+# only when it changes a packaging path, see `changes`; always on main). Unsigned; the only secret is the optional
# Sparkle key, for the appcast dry run. The Keyvault's live paths need a daemon and are not
# exercised here (the view models run against a fake broker).
#
@@ -93,6 +94,47 @@ jobs:
if: github.event_name == 'pull_request'
uses: ./.github/workflows/ci-quick.yml
+ # What the app bundle job (bundle, launch check, XCUITest; about an hour on a
+ # cold runner) must prove is packaging: the build scripts, the bundle's
+ # resources and plists, the XcodeGen project and the UI tests, the Swift
+ # package manifests and the pinned driver. A pull request runs that job only
+ # when it changes one of those paths. Every push to main and every manual run
+ # runs it, so any other change is checked after it merges, and a failure there
+ # alerts and opens an issue (ci-postmerge-issue.yml).
+ changes:
+ name: changes
+ needs: quick
+ if: ${{ !failure() && !cancelled() && (github.event_name != 'pull_request' || !github.event.pull_request.draft) }}
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions:
+ contents: read
+ pull-requests: read
+ defaults:
+ run:
+ working-directory: /tmp
+ outputs:
+ packaging: ${{ steps.scope.outputs.packaging }}
+ steps:
+ - id: scope
+ env:
+ GH_TOKEN: ${{ github.token }}
+ EVENT: ${{ github.event_name }}
+ REPO: ${{ github.repository }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ run: |
+ set -euo pipefail
+ packaging=true
+ if [[ "$EVENT" == pull_request ]]; then
+ files=$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files?per_page=100" --jq '.[].filename')
+ if grep -Eq '^(apps/cua-spaces-macos/(scripts/|Support/|UITests/|project\.yml$|Package\.swift$|Package\.resolved$|cua-driver\.release\.json$|BUNDLED_CUA_VERSION$|VERSION$)|libs/spaces-app-swift/scripts/|\.github/workflows/ci-cua-spaces-macos\.yml$)' <<<"$files"; then
+ packaging=true
+ else
+ packaging=false
+ fi
+ fi
+ echo "packaging=$packaging" | tee -a "$GITHUB_OUTPUT" "$GITHUB_STEP_SUMMARY"
+
core:
needs: quick
if: ${{ !failure() && !cancelled() && ((github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--'))) }}
@@ -293,9 +335,11 @@ jobs:
pnpm native -- --skip-build --check-bindings
app-bundle:
- if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) }}
+ # On a pull request only when it changes a packaging path (see `changes`);
+ # always on main and on a manual run.
+ if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (github.event_name != 'pull_request' || needs.changes.outputs.packaging == 'true') }}
name: SwiftUI app (bundle, launch check, XCUITest)
- needs: ffi
+ needs: [ffi, changes]
runs-on: macos-26
timeout-minutes: 45
steps:
diff --git a/.github/workflows/ci-postmerge-issue-bundles.yml b/.github/workflows/ci-postmerge-issue-bundles.yml
new file mode 100644
index 0000000000..490214ee84
--- /dev/null
+++ b/.github/workflows/ci-postmerge-issue-bundles.yml
@@ -0,0 +1,51 @@
+name: "Alerts: post-merge bundles and XCUITest issue"
+
+# The heavy installer bundles (Tauri NSIS, MSI, DMG, deb, AppImage) and the SwiftUI app
+# bundle with its XCUITests run after merge (a push to main), and on a pull request only
+# when it changes a packaging path. A red run on main is already merged, so it is fixed
+# forward. The alert goes out through workflow-failure-alerts.yml; this opens or updates ONE
+# issue per workflow (label ci-postmerge) and closes it on the next green run.
+# Script: .github/scripts/postmerge_issue.py. It reads only the finished run's metadata and
+# never checks out or runs a pull request's code.
+
+on:
+ workflow_run:
+ workflows:
+ - "CI: Cua Spaces"
+ - "CI: Cua Spaces for macOS (SwiftUI)"
+ types: [completed]
+
+permissions:
+ contents: read
+ issues: write
+
+concurrency:
+ group: ci-postmerge-issue-bundles-${{ github.event.workflow_run.name }}
+ cancel-in-progress: false
+
+jobs:
+ issue:
+ if: github.repository == 'trycua/cua' && github.event.workflow_run.head_branch == github.event.repository.default_branch && (github.event.workflow_run.event == 'push' || github.event.workflow_run.event == 'workflow_dispatch') && github.event.workflow_run.conclusion != 'cancelled' && github.event.workflow_run.conclusion != 'skipped'
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ steps:
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
+ with:
+ ref: ${{ github.event.repository.default_branch }}
+ sparse-checkout: .github/scripts/postmerge_issue.py
+ persist-credentials: false
+ - name: Open, update or close the tracking issue
+ env:
+ GH_TOKEN: ${{ github.token }}
+ RUN: ${{ toJSON(github.event.workflow_run) }}
+ run: |
+ set -euo pipefail
+ python3 .github/scripts/postmerge_issue.py \
+ --workflow "$(jq -r .name <<<"$RUN")" \
+ --conclusion "$(jq -r .conclusion <<<"$RUN")" \
+ --event "$(jq -r .event <<<"$RUN")" \
+ --branch "$(jq -r .head_branch <<<"$RUN")" \
+ --default-branch "${{ github.event.repository.default_branch }}" \
+ --sha "$(jq -r .head_sha <<<"$RUN")" \
+ --run-url "$(jq -r .html_url <<<"$RUN")" \
+ --repo "$GITHUB_REPOSITORY"
diff --git a/.github/workflows/workflow-failure-alerts.yml b/.github/workflows/workflow-failure-alerts.yml
index 9b6a2c66b9..0e592f684b 100644
--- a/.github/workflows/workflow-failure-alerts.yml
+++ b/.github/workflows/workflow-failure-alerts.yml
@@ -27,6 +27,8 @@ on:
- "E2E: Cua Driver release gate"
- "CI: Cua Driver installer compatibility"
- "Monitor branded installer endpoints"
+ - "CI: Cua Spaces"
+ - "CI: Cua Spaces for macOS (SwiftUI)"
- "Release: Pipeline guard"
- "Security: push watch"
- "CD: Cua Driver (cross-platform)"
@@ -67,6 +69,8 @@ jobs:
E2E: Cua Driver release gate=release
CI: Cua Driver installer compatibility=release
Monitor branded installer endpoints=release
+ CI: Cua Spaces=ci
+ CI: Cua Spaces for macOS (SwiftUI)=ci
Release: Pipeline guard=release
Security: push watch=ci
CD: Cua Driver (cross-platform)=release
diff --git a/docs/contributing/CI.md b/docs/contributing/CI.md
index ed670000c4..e58067c862 100644
--- a/docs/contributing/CI.md
+++ b/docs/contributing/CI.md
@@ -211,6 +211,26 @@ to a relay change. Every other area lists every workflow whose own `paths:` reac
or add a path to one, add it to the matching areas in `.github/ci-areas.json`. Changing the map or the gate
is a `.github/**` change, so it waits for every workflow, and it takes effect only once it is on `main`.
+## Heavy bundles run after merge
+
+The installer bundles take 55 to 100 minutes, so a pull request does not wait for them:
+
+- `CI: Cua Spaces` `bundle` (Tauri: Windows NSIS and MSI, macOS DMG, Linux deb and AppImage) builds on every push to
+ `main` that touches the app or `libs/cua`. A pull request builds it only when it changes a packaging path and
+ carries the `ci:full` label.
+- `CI: Cua Spaces for macOS (SwiftUI)` `SwiftUI app (bundle, launch check, XCUITest)` runs on every push to `main`
+ and on a manual run. A pull request runs it only when it changes a packaging path: `apps/cua-spaces-macos`
+ `scripts/`, `Support/`, `UITests/`, `project.yml`, the Swift package manifests, the pinned driver files, the
+ `libs/spaces-app-swift/scripts/` staging script, or the workflow itself (the `changes` job).
+- Pull requests keep the 2 to 5 minute installer smokes (`CI: Installers`, the desktop install smoke) and the
+ core, binding and Swift test jobs. A release still builds every bundle.
+- The gate waits only for runs and jobs that exist on the pull request, so a job that the pull request does not
+ start (a skipped `if`, or a trigger that is `push` only) is never waited for. No change to the area map is needed.
+
+A red run on `main` is already merged, so it is fixed forward. It alerts through `workflow-failure-alerts.yml`
+(Alertmanager, `#alerts-staging`) and `ci-postmerge-issue-bundles.yml` opens one issue per workflow, labelled
+`ci-postmerge`, comments on it for each later failure and closes it on the next green run.
+
## Flaky checks
Known flakes are listed in [`.github/flaky/quarantine.json`](../../.github/flaky/quarantine.json) and