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: Latest is cosmetic; pin it to Cua Spaces, others opt out (CUA-3128) (#6357)

cua-agents[bot]2ea88d4e594d
diff --git a/.github/scripts/pin_latest_release.py b/.github/scripts/pin_latest_release.py
new file mode 100644
index 0000000000..155d0113e4
--- /dev/null
+++ b/.github/scripts/pin_latest_release.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+"""Keep the repo-wide GitHub "Latest" release on the newest Cua Spaces release.
+
+Only Cua Spaces may be Latest; every other component opts out when it
+publishes. This guard runs after any release publishes (and on a schedule,
+because releases created with GITHUB_TOKEN do not trigger `release` events) and
+puts Latest back when another component took it. It never deletes or edits
+anything else.
+"""
+
+from __future__ import annotations
+
+import json
+import os
+import re
+import subprocess
+import sys
+
+OWNER_PREFIX = "cua-spaces-v"
+STABLE = re.compile(r"^cua-spaces-v(\d+)\.(\d+)\.(\d+)$")
+
+
+def gh(*args: str) -> str:
+ return subprocess.run(["gh", *args], check=True, capture_output=True, text=True).stdout
+
+
+def newest_spaces_release(releases: list[dict]) -> dict | None:
+ stable = [
+ r
+ for r in releases
+ if not r.get("draft") and not r.get("prerelease") and STABLE.match(r.get("tag_name", ""))
+ ]
+ return max(stable, key=lambda r: tuple(map(int, STABLE.match(r["tag_name"]).groups())), default=None)
+
+
+def main() -> int:
+ repo = os.environ.get("GITHUB_REPOSITORY", "trycua/cua")
+ listing = json.loads(gh("release", "list", "--repo", repo, "--limit", "30", "--json", "tagName,isLatest"))
+ current = next((r["tagName"] for r in listing if r["isLatest"]), None)
+ if current and current.startswith(OWNER_PREFIX):
+ print(f"Latest is {current}; nothing to do")
+ return 0
+ releases = json.loads(gh("api", "--paginate", "--slurp", f"repos/{repo}/releases?per_page=100"))
+ flat = [r for page in releases for r in page]
+ target = newest_spaces_release(flat)
+ if target is None:
+ print("::warning::no published Cua Spaces release to pin Latest to")
+ return 0
+ print(f"::warning::Latest was {current}; resetting it to {target['tag_name']}")
+ gh("api", "-X", "PATCH", f"repos/{repo}/releases/{target['id']}", "-f", "make_latest=true")
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/.github/scripts/tests/test_cua_sdk_release_repository.py b/.github/scripts/tests/test_cua_sdk_release_repository.py
index c355690a54..7a38e0ef4b 100644
--- a/.github/scripts/tests/test_cua_sdk_release_repository.py
+++ b/.github/scripts/tests/test_cua_sdk_release_repository.py
@@ -205,7 +205,7 @@ def test_spaces_sparkle_cutover_is_off_and_guarded() -> None:
def test_spaces_prereleases_never_become_latest_or_move_canonical_feeds() -> None:
publish = step("cd-cua-spaces.yml", "installer-manifest", "Publish the release")["run"]
- assert "--prerelease --latest=false" in publish
+ assert "--latest=false" in publish and "--prerelease" in publish
assert "UNSIGNED" in publish
feeds = step("cd-cua-spaces.yml", "installer-manifest", "Update the rolling feeds")
assert feeds["if"] == "needs.electron-plan.outputs.prerelease != 'true' || github.repository != 'trycua/cua'"
diff --git a/.github/scripts/tests/test_no_latest_consumers.py b/.github/scripts/tests/test_no_latest_consumers.py
index 15538f7e9b..7f3d84c8a8 100644
--- a/.github/scripts/tests/test_no_latest_consumers.py
+++ b/.github/scripts/tests/test_no_latest_consumers.py
@@ -13,6 +13,8 @@ from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[3]
THIS = Path(__file__).resolve()
+# The guard reads Latest only to put it back on Cua Spaces; it is not a consumer.
+GUARD = ".github/scripts/pin_latest_release.py"
# A lookup of the repo-wide Latest on trycua/cua, however it is spelled.
CONSUMERS = [
@@ -33,6 +35,7 @@ def _files():
path = REPO_ROOT / rel
if (
path == THIS
+ or rel == GUARD
or rel.startswith((".github/release-backfill/", "blog/", "libs/spaces-sdk-swift/"))
or rel.endswith(("CHANGELOG.md", ".lock", ".lockb"))
or "/tests/" in rel
diff --git a/.github/scripts/tests/test_release_latest_policy.py b/.github/scripts/tests/test_release_latest_policy.py
new file mode 100644
index 0000000000..943631715f
--- /dev/null
+++ b/.github/scripts/tests/test_release_latest_policy.py
@@ -0,0 +1,92 @@
+"""GitHub has one repo-wide "Latest" release and trycua/cua publishes many
+packages. Nothing depends on it (test_no_latest_consumers.py guards that), so
+which release carries the badge is cosmetic. We pin it to Cua Spaces, the app
+people browsing the repository expect; every other release workflow opts out
+explicitly so the badge does not flip between packages."""
+
+import re
+import subprocess
+from pathlib import Path
+
+REPO_ROOT = Path(__file__).resolve().parents[3]
+WORKFLOWS = REPO_ROOT / ".github" / "workflows"
+LATEST_OWNER = "cd-cua-spaces.yml"
+THIS = Path(__file__).resolve()
+
+
+def _tracked_text_files():
+ out = subprocess.run(
+ ["git", "ls-files", "-z"], cwd=REPO_ROOT, check=True, capture_output=True, text=True
+ ).stdout
+ for rel in filter(None, out.split("\0")):
+ path = REPO_ROOT / rel
+ if (
+ path == THIS
+ or rel.startswith(".github/release-backfill/")
+ or rel.endswith((".md", ".mdx", ".lock", ".json"))
+ or "/tests/" in rel
+ or rel == ".github/scripts/github_release.py" # verifies only on --make-latest, which no workflow passes
+ or not path.is_file()
+ ):
+ continue
+ try:
+ yield rel, path.read_text()
+ except (UnicodeDecodeError, OSError):
+ continue
+
+
+def test_publishing_workflows_set_latest_explicitly():
+ problems = []
+ for wf in sorted(WORKFLOWS.glob("*.yml")):
+ text = wf.read_text()
+ publishes = (
+ re.search(r"gh release edit[^\n]*--draft=false", text)
+ or re.search(r'gh release edit[^\n]*"\$\{(flags|FLAGS)\[@\]\}"', text)
+ or "softprops/action-gh-release" in text
+ )
+ if publishes and not re.search(r"--latest|make_latest", text):
+ problems.append(f"{wf.name}: publishes a release without --latest/make_latest")
+ if "github_release.py" in text and "--make-latest" in text:
+ problems.append(f"{wf.name}: passes --make-latest")
+ if wf.name != LATEST_OWNER:
+ for m in re.finditer(r"(?:gh release|flags\+=|FLAGS\+=|--draft=false)[^\n]*--latest(?!=false)\b", text):
+ problems.append(f"{wf.name}: --latest without =false (only {LATEST_OWNER} may)")
+ for m in re.finditer(r"make_latest:\s*[\"']?(\w+)", text):
+ if m.group(1) != "false":
+ problems.append(f"{wf.name}: make_latest must be false")
+ assert not problems, "\n".join(problems)
+
+
+def test_cua_spaces_is_the_only_latest_owner():
+ text = (WORKFLOWS / LATEST_OWNER).read_text()
+ assert "flags+=(--latest)" in text
+
+
+def test_no_repo_wide_latest_lookup_for_trycua_cua():
+ bad = []
+ pattern = re.compile(
+ r"(trycua/cua|\$GITHUB_REPO\b|\$\{GITHUB_REPO\}|\{repository\}|GITHUB_REPOSITORY)[^\n]*releases/latest"
+ r"|releases/latest[^\n]*(trycua/cua)"
+ )
+ for rel, text in _tracked_text_files():
+ for n, line in enumerate(text.splitlines(), 1):
+ if pattern.search(line) or re.search(r"gh release view\s*(--|$)", line):
+ bad.append(f"{rel}:{n}: {line.strip()[:120]}")
+ assert not bad, "repo-wide Latest lookups; filter by tag prefix instead:\n" + "\n".join(bad)
+
+
+def test_publishing_workflows_run_the_latest_pin_after_publishing():
+ # --latest=false is not enough: publishing a draft handed cua-spacesd 0.12.1
+ # and 0.12.2 the repo-wide Latest anyway. Every workflow that publishes a
+ # release draft re-pins Latest right after.
+ missing = []
+ for wf in sorted(WORKFLOWS.glob("*.yml")):
+ text = wf.read_text()
+ if wf.name == LATEST_OWNER or wf.name == "release-latest-guard.yml":
+ continue
+ if re.search(r"gh release edit[^\n]*--draft=false", text) or re.search(
+ r'gh release edit[^\n]*"\$\{(flags|FLAGS)\[@\]\}"', text
+ ):
+ if "pin_latest_release.py" not in text:
+ missing.append(wf.name)
+ assert not missing, f"publish without re-pinning Latest: {missing}"
diff --git a/.github/workflows/cd-cua-perception.yml b/.github/workflows/cd-cua-perception.yml
index 8167319f0d..dae7e424d4 100644
--- a/.github/workflows/cd-cua-perception.yml
+++ b/.github/workflows/cd-cua-perception.yml
@@ -685,3 +685,15 @@ jobs:
gh release edit "$TAG" --notes-file release-notes.md --draft=false --latest=false
gh release view "$TAG" --json isDraft,assets \
--jq '"draft=\(.isDraft) assets=\(.assets | length)"'
+ # Publishing a draft can still hand this component the repo-wide "Latest"
+ # (cua-spacesd 0.12.1 and 0.12.2 did, despite --latest=false). Put it back
+ # on Cua Spaces; the release-latest-guard schedule is the backstop.
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
+ if: always() && github.repository == 'trycua/cua'
+ with:
+ sparse-checkout: .github/scripts/pin_latest_release.py
+ - name: Keep Latest on Cua Spaces
+ if: always() && github.repository == 'trycua/cua'
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: python3 .github/scripts/pin_latest_release.py
diff --git a/.github/workflows/cd-cua-sdk.yml b/.github/workflows/cd-cua-sdk.yml
index 2fae9e3317..9b4a2f7bfd 100644
--- a/.github/workflows/cd-cua-sdk.yml
+++ b/.github/workflows/cd-cua-sdk.yml
@@ -758,9 +758,10 @@ jobs:
PRERELEASE: ${{ needs.version.outputs.prerelease }}
run: |
set -euo pipefail
- flags=(--draft=false)
- # Staging builds and X.Y.Z-suffix versions are prereleases, never latest.
- [ "$PRERELEASE" = true ] && flags+=(--prerelease --latest=false)
+ # Never the repo-wide "Latest": only Cua Spaces is (release-latest-policy test).
+ flags=(--draft=false --latest=false)
+ # Staging builds and X.Y.Z-suffix versions are prereleases.
+ [ "$PRERELEASE" = true ] && flags+=(--prerelease)
if [ "$CANONICAL" != true ] || grep -q UNSIGNED dist/signing-*/*.txt; then
label="staging"; [ "$CANONICAL" = true ] && label="test"
# Name the unsigned platforms: "UNSIGNED: windows-x64".
@@ -779,6 +780,18 @@ jobs:
flags+=(--title "cua SDK $VERSION ($label)" --notes-file notes.md)
fi
gh release edit "$TAG" "${flags[@]}" --repo "$GITHUB_REPOSITORY"
+ # Publishing a draft can still hand this component the repo-wide "Latest"
+ # (cua-spacesd 0.12.1 and 0.12.2 did, despite --latest=false). Put it back
+ # on Cua Spaces; the release-latest-guard schedule is the backstop.
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
+ if: always() && github.repository == 'trycua/cua'
+ with:
+ sparse-checkout: .github/scripts/pin_latest_release.py
+ - name: Keep Latest on Cua Spaces
+ if: always() && github.repository == 'trycua/cua'
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: python3 .github/scripts/pin_latest_release.py
# A prerelease on trycua/cua stays off the rolling feed; on any other
# repository the feed is that repository's own and follows every release.
- name: Update the rolling installer manifest (cua-install-latest)
diff --git a/.github/workflows/cd-cua-spaces.yml b/.github/workflows/cd-cua-spaces.yml
index 1259c5c832..b1d4c0fbb7 100644
--- a/.github/workflows/cd-cua-spaces.yml
+++ b/.github/workflows/cd-cua-spaces.yml
@@ -2398,7 +2398,10 @@ jobs:
if [ "$PRERELEASE" = true ]; then
flags+=(--prerelease --latest=false)
else
+ # Cua Spaces is the one package allowed to be the repo-wide "Latest".
+ # Every other release workflow passes --latest=false (release-latest-policy test).
flags+=(--prerelease=false)
+ [ "$GITHUB_REPOSITORY" = trycua/cua ] && flags+=(--latest)
fi
if [ "$GITHUB_REPOSITORY" != trycua/cua ] || grep -q UNSIGNED signing/*.txt; then
label="staging"; [ "$GITHUB_REPOSITORY" = trycua/cua ] && label="test"
diff --git a/.github/workflows/cd-cua-spacesd.yml b/.github/workflows/cd-cua-spacesd.yml
index d817fcbb7f..77be6110c2 100644
--- a/.github/workflows/cd-cua-spacesd.yml
+++ b/.github/workflows/cd-cua-spacesd.yml
@@ -534,3 +534,15 @@ jobs:
FLAGS+=(--title "cua-spacesd $VERSION ($label)" --notes-file notes.md)
fi
gh release edit "$TAG" "${FLAGS[@]}" --repo "$GITHUB_REPOSITORY"
+ # Publishing a draft can still hand this component the repo-wide "Latest"
+ # (cua-spacesd 0.12.1 and 0.12.2 did, despite --latest=false). Put it back
+ # on Cua Spaces; the release-latest-guard schedule is the backstop.
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
+ if: always() && github.repository == 'trycua/cua'
+ with:
+ sparse-checkout: .github/scripts/pin_latest_release.py
+ - name: Keep Latest on Cua Spaces
+ if: always() && github.repository == 'trycua/cua'
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: python3 .github/scripts/pin_latest_release.py
diff --git a/.github/workflows/release-github-reusable.yml b/.github/workflows/release-github-reusable.yml
index 51e9af1eec..2551c343d1 100644
--- a/.github/workflows/release-github-reusable.yml
+++ b/.github/workflows/release-github-reusable.yml
@@ -204,9 +204,19 @@ jobs:
body: ${{ steps.prepare-body.outputs.BODY }}
draft: ${{ inputs.draft }}
prerelease: ${{ inputs.prerelease }}
+ # Only Cua Spaces is the repo-wide "Latest" (release-latest-policy test).
+ make_latest: "false"
# Only use GitHub auto-generated notes if module_path is not specified
generate_release_notes: ${{ inputs.module_path == '' && inputs.generate_notes }}
files: |
release-assets/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
+ # Safety net: if anything above left another component as the repo-wide
+ # "Latest", put it back on the newest Cua Spaces release.
+ - name: Keep Latest on Cua Spaces
+ if: always() && github.repository == 'trycua/cua'
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: python3 .github/scripts/pin_latest_release.py
diff --git a/.github/workflows/release-latest-guard.yml b/.github/workflows/release-latest-guard.yml
new file mode 100644
index 0000000000..b2a34301bb
--- /dev/null
+++ b/.github/workflows/release-latest-guard.yml
@@ -0,0 +1,33 @@
+name: "Release: Keep Latest on Cua Spaces"
+
+# Only Cua Spaces may be the repo-wide GitHub "Latest" release. Component
+# workflows opt out when they publish; this is the backstop that resets Latest
+# if one slips through. Releases created with GITHUB_TOKEN do not fire
+# `release` events, so the schedule is the reliable trigger.
+on:
+ release:
+ types: [published, released, edited]
+ schedule:
+ - cron: "*/15 * * * *"
+ workflow_dispatch:
+
+permissions:
+ contents: write
+
+concurrency:
+ group: release-latest-guard
+ cancel-in-progress: false
+
+jobs:
+ pin-latest:
+ if: github.repository == 'trycua/cua'
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ sparse-checkout: .github/scripts/pin_latest_release.py
+ - name: Keep Latest on Cua Spaces
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: python3 .github/scripts/pin_latest_release.py