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: auto-merge release-please PRs behind ci-gate and hold, alert when one sits green (CUA-3559) (#6589)

Francesco Bonacci3de762e82f06
diff --git a/.github/scripts/release_pr_automerge.py b/.github/scripts/release_pr_automerge.py
new file mode 100644
index 0000000000..f599842bcf
--- /dev/null
+++ b/.github/scripts/release_pr_automerge.py
@@ -0,0 +1,200 @@
+#!/usr/bin/env python3
+"""Auto-merge release-please pull requests, and alert when one sits green (CUA-3559).
+
+Every release-please PR (branch release-please--branches--*, opened by the release
+App from this repository) gets `gh pr merge --auto --squash`. It then merges only
+when the required checks (ci-gate and the rest of the ruleset) are green. The `hold`
+label stops it: a held PR has auto-merge switched off, and ci-gate fails while the
+label is on (ci-gate.yml), so a hold also wins a race with this script.
+
+ release_pr_automerge.py --repo trycua/cua # all open release PRs
+ release_pr_automerge.py --repo trycua/cua --pr 123 # one PR (pull_request_target)
+ release_pr_automerge.py --repo trycua/cua --alert # also alert on stale green PRs
+ release_pr_automerge.py --repo trycua/cua --guard .github/scripts/release_please_tag_guard.cjs
+
+--guard checks each PR body with the pinned release-please engine before auto-merge is
+switched on (NODE_PATH must hold [email protected]). Release Please tags from the
+merged body; text above the version heading makes it tag every component (#6350, 15 stray
+v0.20.0 releases). A body that fails is repaired when the fix is only moving the heading
+back to the top; otherwise auto-merge is switched off and the run fails.
+
+--alert posts one ReleasePRStuck alert to Alertmanager (same path as
+workflow_alerts.py) for each release PR whose ci-gate has been green for more than
+--stale-hours (6) and that is still open and not on hold. The alert expires in
+an hour unless the next sweep refreshes it, so it clears itself once the PR merges.
+Needs the `gh` CLI with GH_TOKEN set. Standard library only.
+"""
+
+from __future__ import annotations
+
+import argparse
+import datetime as dt
+import json
+import os
+import subprocess
+import sys
+import tempfile
+
+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+import workflow_alerts # noqa: E402
+
+BRANCH_PREFIX = "release-please--branches--"
+HOLD_LABEL = "hold"
+GATE_CHECK = "ci-gate"
+ALERTNAME = "ReleasePRStuck"
+
+
+class BadReleaseBody(Exception):
+ pass
+
+
+def is_release_pr(pr: dict, repo: str) -> bool:
+ owner = repo.split("/")[0]
+ head_owner = (pr.get("headRepositoryOwner") or {}).get("login")
+ return str(pr.get("headRefName", "")).startswith(BRANCH_PREFIX) and head_owner == owner and not pr.get("isDraft")
+
+
+def on_hold(pr: dict) -> bool:
+ return any(label.get("name") == HOLD_LABEL for label in pr.get("labels", []))
+
+
+def parse_time(text: str) -> dt.datetime:
+ return dt.datetime.fromisoformat(text.replace("Z", "+00:00"))
+
+
+def gate_green_since(check_runs: list[dict]) -> dt.datetime | None:
+ """When the latest ci-gate run on the head commit went green, or None if it is not green."""
+ gates = [run for run in check_runs if run.get("name") == GATE_CHECK and run.get("completed_at")]
+ if not gates:
+ return None
+ latest = max(gates, key=lambda run: run["completed_at"])
+ return parse_time(latest["completed_at"]) if latest.get("conclusion") == "success" else None
+
+
+def build_alert(pr: dict, repo: str, green_since: dt.datetime, now: dt.datetime, stale_hours: float) -> dict:
+ hours = (now - green_since).total_seconds() / 3600
+ url = "https://github.com/%s/pull/%s" % (repo, pr["number"])
+ return {
+ "labels": {
+ "alertname": ALERTNAME,
+ "source": "github-actions",
+ "severity": "warning",
+ "environment": "release",
+ "repo": repo,
+ "pr": str(pr["number"]),
+ },
+ "annotations": {
+ "summary": "Release PR #%s has been green for %.0f h without merging in %s" % (pr["number"], hours, repo),
+ "description": "%s (%s) passed ci-gate more than %g h ago and is still open and not on hold. "
+ "Check that auto-merge is on and which required check is missing." % (pr.get("title", ""), url, stale_hours),
+ "pr_url": url,
+ },
+ "startsAt": workflow_alerts.iso(green_since + dt.timedelta(hours=stale_hours)),
+ "endsAt": workflow_alerts.iso(now + dt.timedelta(hours=1)),
+ }
+
+
+def gh(*args: str) -> str:
+ done = subprocess.run(["gh", *args], capture_output=True, text=True)
+ if done.returncode != 0:
+ raise SystemExit("gh %s failed: %s" % (" ".join(args[:3]), done.stderr.strip()))
+ return done.stdout
+
+
+def body_guard(pr: dict, repo: str, guard: str) -> str | None:
+ """None when the PR body tags only its own component; otherwise why not.
+
+ Repairs the body in place when moving the version heading to the top is enough.
+ """
+ n = str(pr["number"])
+ view = gh("pr", "view", n, "--repo", repo, "--json", "number,title,headRefName,body,mergeCommit")
+ with tempfile.TemporaryDirectory() as tmp:
+ src = os.path.join(tmp, "pr.json")
+ with open(src, "w") as fh:
+ fh.write(view)
+ if subprocess.run(["node", guard, "check", src], capture_output=True).returncode == 0:
+ return None
+ fixed = subprocess.run(["node", guard, "repair", src], capture_output=True, text=True)
+ if fixed.returncode != 0:
+ return "#%s: body would tag other components and cannot be repaired" % n
+ out = os.path.join(tmp, "body.md")
+ with open(out, "w") as fh:
+ fh.write(fixed.stdout)
+ gh("pr", "edit", n, "--repo", repo, "--body-file", out)
+ print("#%s: moved the version heading back to the top of the body" % n)
+ return None
+
+
+FIELDS = "number,title,headRefName,headRepositoryOwner,isDraft,labels,autoMergeRequest,headRefOid"
+
+
+def open_release_prs(repo: str, only: int | None) -> list[dict]:
+ if only is not None:
+ prs = [json.loads(gh("pr", "view", str(only), "--repo", repo, "--json", FIELDS))]
+ else:
+ prs = json.loads(gh("pr", "list", "--repo", repo, "--state", "open", "--base", "main", "--limit", "100", "--json", FIELDS))
+ return [pr for pr in prs if is_release_pr(pr, repo)]
+
+
+def reconcile(pr: dict, repo: str, guard: str | None = None) -> str:
+ n = str(pr["number"])
+ if guard and not on_hold(pr):
+ problem = body_guard(pr, repo, guard)
+ if problem:
+ if pr.get("autoMergeRequest"):
+ gh("pr", "merge", n, "--repo", repo, "--disable-auto")
+ raise BadReleaseBody(problem)
+ if on_hold(pr):
+ if pr.get("autoMergeRequest"):
+ gh("pr", "merge", n, "--repo", repo, "--disable-auto")
+ return "#%s: hold label, auto-merge disabled" % n
+ return "#%s: hold label, left alone" % n
+ if pr.get("autoMergeRequest"):
+ return "#%s: auto-merge already on" % n
+ gh("pr", "merge", n, "--repo", repo, "--auto", "--squash")
+ return "#%s: auto-merge (squash) enabled" % n
+
+
+def stale_alerts(prs: list[dict], repo: str, stale_hours: float, now: dt.datetime) -> list[dict]:
+ alerts = []
+ for pr in prs:
+ if on_hold(pr):
+ continue
+ path = "repos/%s/commits/%s/check-runs?check_name=%s&per_page=100" % (repo, pr["headRefOid"], GATE_CHECK)
+ green = gate_green_since(json.loads(gh("api", path))["check_runs"])
+ if green is not None and now - green > dt.timedelta(hours=stale_hours):
+ alerts.append(build_alert(pr, repo, green, now, stale_hours))
+ return alerts
+
+
+def main(argv: list[str] | None = None) -> int:
+ ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
+ ap.add_argument("--repo", required=True)
+ ap.add_argument("--pr", type=int)
+ ap.add_argument("--alert", action="store_true", help="post ReleasePRStuck alerts for stale green release PRs")
+ ap.add_argument("--guard", help="release_please_tag_guard.cjs: check each body before enabling auto-merge")
+ ap.add_argument("--stale-hours", type=float, default=6.0)
+ ap.add_argument("--dry-run", action="store_true", help="print the alerts instead of posting them")
+ args = ap.parse_args(argv)
+ now = dt.datetime.now(dt.timezone.utc)
+ prs = open_release_prs(args.repo, args.pr)
+ failed = False
+ for pr in prs:
+ try:
+ print(reconcile(pr, args.repo, args.guard))
+ except BadReleaseBody as bad:
+ print("::error::%s. Keep the version heading (## [x.y.z](...)) first after '---'; put added notes below it." % bad)
+ failed = True
+ if not prs:
+ print("no open release PRs")
+ if args.alert:
+ alerts = stale_alerts(prs, args.repo, args.stale_hours, now)
+ for alert in alerts:
+ print("ALERT " + alert["annotations"]["summary"])
+ if not args.dry_run:
+ workflow_alerts.post(alerts, workflow_alerts.ALERTMANAGER_URL)
+ return 1 if failed else 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/.github/scripts/tests/test_ci_gate_scope.py b/.github/scripts/tests/test_ci_gate_scope.py
index 0727d0501b..54a874d356 100644
--- a/.github/scripts/tests/test_ci_gate_scope.py
+++ b/.github/scripts/tests/test_ci_gate_scope.py
@@ -263,7 +263,10 @@ def test_urgent_label_with_reference_uses_the_same_path_scope(tmp_path):
def test_gate_runs_the_scope_step_first_and_passes_its_output_to_the_wait_step():
gate = yaml.safe_load((scope.WORKFLOWS / 'ci-gate.yml').read_text())
steps = gate['jobs']['ci-gate']['steps']
- assert steps[2]['id'] == 'scope'
+ # The scope step runs right after the two selector checkouts; the hold-label step may sit before them.
+ names = [st.get('name') for st in steps]
+ assert names.index('Scope the gate to the changed areas') == names.index("Check out the pull request's manifests") + 1
+ assert next(st for st in steps if st.get('name') == 'Scope the gate to the changed areas')['id'] == 'scope'
wait = next(st for st in steps if st.get('name', '').startswith('Wait for every other'))
assert wait['env']['IGNORE_RE'] == '${{ steps.scope.outputs.ignore_re }}'
assert 'labeled' in gate[True]['pull_request']['types']
@@ -272,7 +275,8 @@ def test_gate_runs_the_scope_step_first_and_passes_its_output_to_the_wait_step()
def test_gate_run_filter_drops_only_ignored_workflows():
- script = yaml.safe_load((scope.WORKFLOWS / 'ci-gate.yml').read_text())['jobs']['ci-gate']['steps'][4]['run']
+ script = yaml.safe_load((scope.WORKFLOWS / 'ci-gate.yml').read_text())['jobs']['ci-gate']['steps']
+ script = next(st for st in script if st.get('name', '').startswith('Wait for every other'))['run']
jq_filter = next(line.split("='", 1)[1].rsplit("'", 1)[0]
for line in script.splitlines() if line.strip().startswith('scope_jq='))
runs = [{'path': '.github/workflows/cd-image-linux.yml@refs/pull/1/merge'},
@@ -289,7 +293,11 @@ def test_gate_run_filter_drops_only_ignored_workflows():
def test_gate_runs_the_selector_from_the_base_commit_not_the_pull_request():
"""A PR that edits the map, the scripts or its manifests cannot narrow its own gate."""
steps = yaml.safe_load((scope.WORKFLOWS / 'ci-gate.yml').read_text())['jobs']['ci-gate']['steps']
- base, head, run = steps[0]['with'], steps[1]['with'], steps[2]['run']
+ by_name = {st.get('name'): st for st in steps}
+ scope_step = by_name['Scope the gate to the changed areas']
+ base = by_name['Check out the selector from the base commit']['with']
+ head = by_name["Check out the pull request's manifests"]['with']
+ run = scope_step['run']
assert base['ref'] == '${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}'
assert base['path'] == 'base'
for f in ('/.github/ci-areas.json', '/.github/scripts/ci_gate_scope.py', '/.github/scripts/ci_graph.py'):
@@ -297,4 +305,4 @@ def test_gate_runs_the_selector_from_the_base_commit_not_the_pull_request():
assert f not in head['sparse-checkout'].split()
assert 'ref' not in head and head['path'] == 'head'
assert 'python3 base/.github/scripts/ci_gate_scope.py' in run
- assert steps[2]['env']['CI_GATE_HEAD_ROOT'].endswith('/head')
+ assert scope_step['env']['CI_GATE_HEAD_ROOT'].endswith('/head')
diff --git a/.github/scripts/tests/test_ci_gate_workflow.py b/.github/scripts/tests/test_ci_gate_workflow.py
index 68eeab128c..f6bcf792c4 100644
--- a/.github/scripts/tests/test_ci_gate_workflow.py
+++ b/.github/scripts/tests/test_ci_gate_workflow.py
@@ -285,8 +285,7 @@ def test_gate_fails_a_failure_that_is_not_quarantined(tmp_path):
def test_gate_reads_the_quarantine_list_from_the_base_commit():
- steps = GATE['jobs']['ci-gate']['steps']
- base = steps[0]['with']['sparse-checkout'].split()
+ base = STEPS['Check out the selector from the base commit']['with']['sparse-checkout'].split()
assert '/.github/flaky/quarantine.json' in base and '/.github/scripts/flaky/flaky.py' in base
env = STEPS['Wait for every other workflow on the pull request head']['env']
assert env['FLAKY_PY'].startswith('base/') and env['QUARANTINE_FILE'].startswith('base/')
diff --git a/.github/scripts/tests/test_release_pr_automerge.py b/.github/scripts/tests/test_release_pr_automerge.py
new file mode 100644
index 0000000000..1ef343cd1f
--- /dev/null
+++ b/.github/scripts/tests/test_release_pr_automerge.py
@@ -0,0 +1,153 @@
+"""Unit tests for .github/scripts/release_pr_automerge.py (CUA-3559). Offline: gh is mocked."""
+
+import datetime as dt
+import importlib.util
+import sys
+import unittest
+from pathlib import Path
+from unittest import mock
+
+ROOT = Path(__file__).resolve().parents[3]
+sys.path.insert(0, str(ROOT / ".github/scripts"))
+SPEC = importlib.util.spec_from_file_location("release_pr_automerge", ROOT / ".github/scripts/release_pr_automerge.py")
+rp = importlib.util.module_from_spec(SPEC)
+SPEC.loader.exec_module(rp)
+
+NOW = dt.datetime(2026, 11, 5, 20, 0, tzinfo=dt.timezone.utc)
+
+
+def pr(number=1, ref="release-please--branches--main--components--cua-sdk", owner="trycua", labels=(), auto=None, draft=False):
+ return {
+ "number": number,
+ "title": "chore(main): release cua-sdk 1.0.0",
+ "headRefName": ref,
+ "headRepositoryOwner": {"login": owner},
+ "isDraft": draft,
+ "labels": [{"name": name} for name in labels],
+ "autoMergeRequest": auto,
+ "headRefOid": "a" * 40,
+ }
+
+
+def gate(conclusion, completed):
+ return {"name": "ci-gate", "conclusion": conclusion, "completed_at": completed}
+
+
+class WhichPrsCount(unittest.TestCase):
+ def test_release_branch_from_this_repo(self):
+ self.assertTrue(rp.is_release_pr(pr(), "trycua/cua"))
+
+ def test_fork_branch_with_the_same_name_is_ignored(self):
+ self.assertFalse(rp.is_release_pr(pr(owner="someone"), "trycua/cua"))
+
+ def test_ordinary_branch_and_draft_are_ignored(self):
+ self.assertFalse(rp.is_release_pr(pr(ref="fix/thing"), "trycua/cua"))
+ self.assertFalse(rp.is_release_pr(pr(draft=True), "trycua/cua"))
+
+
+class Reconcile(unittest.TestCase):
+ def test_enables_squash_auto_merge(self):
+ with mock.patch.object(rp, "gh") as gh:
+ rp.reconcile(pr(7), "trycua/cua")
+ gh.assert_called_once_with("pr", "merge", "7", "--repo", "trycua/cua", "--auto", "--squash")
+
+ def test_already_on_is_left_alone(self):
+ with mock.patch.object(rp, "gh") as gh:
+ rp.reconcile(pr(auto={"mergeMethod": "SQUASH"}), "trycua/cua")
+ gh.assert_not_called()
+
+ def test_hold_never_enables_and_switches_off(self):
+ with mock.patch.object(rp, "gh") as gh:
+ rp.reconcile(pr(labels=["hold"]), "trycua/cua")
+ gh.assert_not_called()
+ rp.reconcile(pr(5, labels=["hold"], auto={"mergeMethod": "SQUASH"}), "trycua/cua")
+ gh.assert_called_once_with("pr", "merge", "5", "--repo", "trycua/cua", "--disable-auto")
+
+
+class StaleGreen(unittest.TestCase):
+ def test_green_for_more_than_six_hours_alerts(self):
+ with mock.patch.object(rp, "gh", return_value='{"check_runs": [{"name": "ci-gate", "conclusion": "success", "completed_at": "2026-11-05T13:00:00Z"}]}'):
+ alerts = rp.stale_alerts([pr(9)], "trycua/cua", 6, NOW)
+ self.assertEqual(len(alerts), 1)
+ self.assertEqual(alerts[0]["labels"]["alertname"], "ReleasePRStuck")
+ self.assertEqual(alerts[0]["labels"]["pr"], "9")
+ self.assertEqual(alerts[0]["startsAt"], "2026-11-05T19:00:00Z")
+
+ def test_recent_red_or_held_does_not_alert(self):
+ recent = '{"check_runs": [{"name": "ci-gate", "conclusion": "success", "completed_at": "2026-11-05T18:00:00Z"}]}'
+ red = '{"check_runs": [{"name": "ci-gate", "conclusion": "failure", "completed_at": "2026-11-05T01:00:00Z"}]}'
+ old = '{"check_runs": [{"name": "ci-gate", "conclusion": "success", "completed_at": "2026-11-05T01:00:00Z"}]}'
+ for body in (recent, red):
+ with mock.patch.object(rp, "gh", return_value=body):
+ self.assertEqual(rp.stale_alerts([pr()], "trycua/cua", 6, NOW), [])
+ with mock.patch.object(rp, "gh", return_value=old):
+ self.assertEqual(rp.stale_alerts([pr(labels=["hold"])], "trycua/cua", 6, NOW), [])
+
+ def test_latest_gate_run_wins(self):
+ runs = [gate("success", "2026-11-05T01:00:00Z"), gate("failure", "2026-11-05T05:00:00Z")]
+ self.assertIsNone(rp.gate_green_since(runs))
+
+
+class BodyGuard(unittest.TestCase):
+ def run_guard(self, check_rc, repair_rc, pr_obj=None):
+ calls = []
+
+ def fake_run(cmd, **kw):
+ calls.append(cmd[2])
+ rc = check_rc if cmd[2] == "check" else repair_rc
+ return mock.Mock(returncode=rc, stdout="fixed body")
+
+ with mock.patch.object(rp, "gh", return_value="{}") as gh, mock.patch.object(rp.subprocess, "run", fake_run):
+ try:
+ out = rp.reconcile(pr_obj or pr(3), "trycua/cua", "guard.cjs")
+ except rp.BadReleaseBody as bad:
+ out = bad
+ return out, calls, gh
+
+ def test_good_body_goes_on_to_auto_merge(self):
+ out, calls, gh = self.run_guard(0, 1)
+ self.assertEqual(calls, ["check"])
+ gh.assert_called_with("pr", "merge", "3", "--repo", "trycua/cua", "--auto", "--squash")
+
+ def test_misplaced_heading_is_repaired_then_merged(self):
+ out, calls, gh = self.run_guard(1, 0)
+ self.assertEqual(calls, ["check", "repair"])
+ edits = [c.args for c in gh.call_args_list if c.args[:2] == ("pr", "edit")]
+ self.assertEqual(len(edits), 1)
+ gh.assert_called_with("pr", "merge", "3", "--repo", "trycua/cua", "--auto", "--squash")
+
+ def test_unrepairable_body_never_auto_merges_and_switches_it_off(self):
+ out, calls, gh = self.run_guard(1, 1, pr(3, auto={"mergeMethod": "SQUASH"}))
+ self.assertIsInstance(out, rp.BadReleaseBody)
+ gh.assert_called_with("pr", "merge", "3", "--repo", "trycua/cua", "--disable-auto")
+ self.assertNotIn("--auto", gh.call_args.args)
+
+ def test_unrepairable_body_fails_the_run(self):
+ with mock.patch.object(rp, "open_release_prs", return_value=[pr(3)]), mock.patch.object(
+ rp, "reconcile", side_effect=rp.BadReleaseBody("bad")
+ ):
+ self.assertEqual(rp.main(["--repo", "trycua/cua", "--guard", "g.cjs"]), 1)
+
+ def test_hold_skips_the_guard(self):
+ with mock.patch.object(rp, "gh"), mock.patch.object(rp, "body_guard") as bg:
+ rp.reconcile(pr(labels=["hold"]), "trycua/cua", "guard.cjs")
+ bg.assert_not_called()
+
+
+class Wiring(unittest.TestCase):
+ def test_workflow_checks_bodies_on_every_edit(self):
+ text = (ROOT / ".github/workflows/release-pr-auto-merge.yml").read_text()
+ self.assertIn("synchronize, edited,", text)
+ self.assertIn("--guard .github/scripts/release_please_tag_guard.cjs", text)
+ self.assertIn("[email protected]", text)
+ self.assertIn("release-please-config.json", text)
+
+
+ def test_ci_gate_fails_on_hold(self):
+ text = (ROOT / ".github/workflows/ci-gate.yml").read_text()
+ self.assertIn("contains(github.event.pull_request.labels.*.name, 'hold')", text)
+ self.assertIn("labeled, unlabeled", text)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/.github/workflows/ci-gate.yml b/.github/workflows/ci-gate.yml
index 36440599a8..eb1aab576a 100644
--- a/.github/workflows/ci-gate.yml
+++ b/.github/workflows/ci-gate.yml
@@ -20,6 +20,13 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 180
steps:
+ # A pull request labelled `hold` never merges, auto-merge or not (CUA-3559). The gate
+ # reruns when the label is added or removed (labeled/unlabeled above).
+ - name: Fail while the pull request is on hold
+ if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'hold') }}
+ run: |
+ echo "::error::This pull request has the hold label. Remove it to let the gate pass."
+ exit 1
# Which workflows this gate may ignore, from the paths the PR changes, the area map
# (.github/ci-areas.json) and the package graph (.github/scripts/ci_graph.py); see
# docs/contributing/CI.md. The map and both scripts come from the base commit, never
diff --git a/.github/workflows/release-pr-auto-merge.yml b/.github/workflows/release-pr-auto-merge.yml
new file mode 100644
index 0000000000..7fc1a026a2
--- /dev/null
+++ b/.github/workflows/release-pr-auto-merge.yml
@@ -0,0 +1,88 @@
+name: "Release: Auto-merge release PRs"
+
+# CUA-3559. Release-please PRs wait for a human to merge them (median 8 h, p90 36 h; the
+# driver and SDK PRs waited 15 days and 2 days). This turns on auto-merge (squash) for each
+# one as it is opened or updated. It still merges only behind the required checks (ci-gate and
+# the rest of the main-safety-gates ruleset). The `hold` label stops it: a held PR gets
+# auto-merge switched off, and ci-gate fails while the label is on.
+#
+# A merge made with the release App token starts the release pipeline (release-on-merge.yml);
+# one made with GITHUB_TOKEN would not. Same App as release-please.yml.
+#
+# The sweep also posts a ReleasePRStuck alert (Alertmanager, same path as
+# workflow-failure-alerts.yml) when a release PR has been green for more than 6 h and is
+# still open and not on hold.
+#
+# pull_request_target runs this file from main and never checks out the PR's code.
+
+on:
+ pull_request_target:
+ types: [opened, reopened, synchronize, edited, labeled, unlabeled, ready_for_review]
+ branches: [main]
+ schedule:
+ - cron: "17,47 * * * *"
+ workflow_dispatch: {}
+
+permissions:
+ contents: read
+
+concurrency:
+ group: release-pr-auto-merge-${{ github.event.pull_request.number || 'sweep' }}
+ cancel-in-progress: false
+
+jobs:
+ auto-merge:
+ if: >-
+ github.repository == 'trycua/cua' &&
+ (github.event_name != 'pull_request_target' ||
+ (startsWith(github.event.pull_request.head.ref, 'release-please--branches--') &&
+ github.event.pull_request.head.repo.full_name == github.repository))
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
+ - name: Generate release GitHub App token
+ id: app-token
+ uses: actions/create-github-app-token@v1
+ with:
+ app-id: ${{ secrets.RELEASE_APP_ID }}
+ private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
+ owner: ${{ github.repository_owner }}
+ repositories: ${{ github.event.repository.name }}
+
+ - uses: actions/checkout@v4
+ with:
+ ref: ${{ github.event.repository.default_branch }}
+ sparse-checkout: |
+ .github/scripts
+ release-please-config.json
+ .release-please-manifest.json
+ persist-credentials: false
+
+ # Release Please tags from the merged PR body. A body edit (an agent adding
+ # user-impact notes above the version heading) made #6350 tag 15 stray
+ # components. Install the pinned engine so the script can check each body.
+ - name: Install the pinned Release Please engine
+ env:
+ NPM_CONFIG_IGNORE_SCRIPTS: "true"
+ run: |
+ set -euo pipefail
+ EXPECTED_INTEGRITY='sha512-dB7HsFUpAvU1Wj9RGCINUz8Zi2qQDZiGbDEEVnJ7baNfJmk5XdYhuUFL6RcuDGjReGhp1gzY8Tc2g7vHlM4zpg='
+ test "$(npm view [email protected] dist.integrity)" = "$EXPECTED_INTEGRITY"
+ npm install --prefix "$RUNNER_TEMP/release-please-engine" --ignore-scripts --no-audit --no-fund [email protected] > /dev/null
+
+ - name: Enable or disable auto-merge, and alert on stale green release PRs
+ env:
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
+ ALERTMANAGER_INTAKE_TOKEN: ${{ secrets.ALERTMANAGER_INTAKE_TOKEN }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ run: |
+ set -euo pipefail
+ export NODE_PATH="$RUNNER_TEMP/release-please-engine/node_modules"
+ args=(--repo "$GITHUB_REPOSITORY" --guard .github/scripts/release_please_tag_guard.cjs)
+ if [ -n "$PR_NUMBER" ]; then
+ args+=(--pr "$PR_NUMBER")
+ fi
+ if [ "$GITHUB_EVENT_NAME" != pull_request_target ]; then
+ args+=(--alert)
+ fi
+ python3 .github/scripts/release_pr_automerge.py "${args[@]}"
diff --git a/.github/workflows/workflow-failure-alerts.yml b/.github/workflows/workflow-failure-alerts.yml
index 43be74106f..69fcc8426b 100644
--- a/.github/workflows/workflow-failure-alerts.yml
+++ b/.github/workflows/workflow-failure-alerts.yml
@@ -32,6 +32,7 @@ on:
- "CD: cua-spacesd"
- "CD: Lume (macOS)"
- "Release: Prepare component releases"
+ - "Release: Auto-merge release PRs"
- "Release: installer scripts feed"
types: [completed]
schedule:
@@ -67,6 +68,7 @@ jobs:
CD: cua-spacesd=release
CD: Lume (macOS)=release
Release: Prepare component releases=release
+ Release: Auto-merge release PRs=release
Release: installer scripts feed=release
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GH_TOKEN: ${{ github.token }}