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: add ci-gate aggregate check and merge_group support for required checks

injaneity9bd1d8b76e55
diff --git a/.github/scripts/tests/test_ci_gate_workflow.py b/.github/scripts/tests/test_ci_gate_workflow.py
new file mode 100644
index 0000000000..aaaa6f5066
--- /dev/null
+++ b/.github/scripts/tests/test_ci_gate_workflow.py
@@ -0,0 +1,94 @@
+import os
+from pathlib import Path
+import subprocess
+
+import pytest
+import yaml
+
+
+ROOT = Path(__file__).resolve().parents[3]
+WORKFLOWS = ROOT / '.github/workflows'
+GATE = yaml.safe_load((WORKFLOWS / 'ci-gate.yml').read_text())
+SCRIPT = GATE['jobs']['ci-gate']['steps'][0]['run']
+
+
[email protected]('filename', [
+ 'ci-contributor-attribution.yml',
+ 'ci-release-metadata.yml',
+ 'fleet-mirror-guard.yml',
+])
+def test_required_workflow_queue_wiring(filename):
+ workflow = yaml.safe_load((WORKFLOWS / filename).read_text())
+ assert 'merge_group' in workflow[True]
+ for job in workflow['jobs'].values():
+ assert job['if'] in (
+ "github.event_name != 'merge_group'",
+ "always() && github.event_name != 'merge_group'",
+ )
+
+
+def test_gate_wiring():
+ assert set(GATE[True]) == {'pull_request', 'merge_group'}
+ assert GATE[True]['pull_request']['types'] == [
+ 'opened', 'synchronize', 'reopened', 'ready_for_review',
+ 'edited', 'labeled', 'unlabeled',
+ ]
+ assert 'concurrency' not in GATE
+ assert GATE['jobs']['ci-gate']['timeout-minutes'] == 360
+ assert '.workflow_id != $GITHUB_WORKFLOW_ID' in SCRIPT
+ assert '(.event == \\"pull_request\\" or .event == \\"pull_request_target\\")' in SCRIPT
+ assert 'claude-auto-fix|ci-release-reminder|review-cua-perception-candidates' in SCRIPT
+
+
+def run_gate(rows, jobs='test\tsuccess', older_jobs=None):
+ mock = '''
+set -uo pipefail
+api() {
+ case "$*" in
+ *'/jobs?'*)
+ if [[ "$*" == *'/10/jobs?'* ]]; then
+ printf '%s' "$OLDER_JOBS"
+ else
+ printf '%s' "$JOBS"
+ fi ;;
+ *'head_sha='*) printf '%s' "$ROWS" ;;
+ *) printf '999' ;;
+ esac
+}
+sleeps=0
+sleep() {
+ sleeps=$((sleeps + 1))
+ if (( sleeps > 4 )); then exit 124; fi
+}
+'''
+ return subprocess.run(
+ ['bash', '-c', mock + SCRIPT[SCRIPT.index('sha=$PR_SHA'):]],
+ env={**os.environ, 'PR_SHA': 'abc', 'QUEUE_REF': '',
+ 'GITHUB_REPOSITORY': 'test/repo', 'GITHUB_RUN_ID': '99',
+ 'ROWS': rows, 'JOBS': jobs,
+ 'OLDER_JOBS': jobs if older_jobs is None else older_jobs},
+ capture_output=True, text=True, timeout=5,
+ )
+
+
[email protected](('rows', 'jobs', 'older_jobs', 'code', 'result'), [
+ ('1\t11\tbuild\tsuccess\tcompleted\n1\t10\tbuild\tfailure\tcompleted', 'test\tsuccess', None, 0, 'build: pass'),
+ ('1\t11\tbuild\tsuccess\tcompleted\n1\t10\tbuild\tcancelled\tcompleted', '', 'test\tcancelled', 0, 'build: skipped'),
+ ('1\t11\tbuild\tcancelled\tcompleted\n1\t10\tbuild\tsuccess\tcompleted', 'test\tcancelled', None, 1, 'build: fail'),
+ ('1\t11\tbuild\tsuccess\tcompleted\n1\t10\tbuild\tfailure\tcompleted', '', 'test\tfailure', 1, 'build: fail'),
+ ('1\t11\tbuild\tskipped\tcompleted', '', None, 0, 'build: skipped'),
+ ('1\t11\tbuild\tsuccess\tcompleted', 'distro-smoke\tfailure', None, 0, 'build: pass'),
+ ('1\t11\tbuild\tfailure\tcompleted', 'test\tfailure', None, 1, 'build: fail'),
+ ('1\t11\tbuild\tneutral\tcompleted', 'test\tneutral', None, 0, 'build: pass'),
+])
+def test_gate_results(rows, jobs, older_jobs, code, result):
+ completed = run_gate(rows, jobs, older_jobs)
+ assert completed.returncode == code, completed.stderr
+ assert result in completed.stdout
+
+
[email protected]('rows', ['', '1\t11\tbuild\t\tin_progress'])
+def test_gate_waits_until_timeout_without_completed_runs(rows):
+ completed = run_gate(rows)
+ assert completed.returncode == 124
+ assert 'build: pass' not in completed.stdout
diff --git a/.github/workflows/ci-contributor-attribution.yml b/.github/workflows/ci-contributor-attribution.yml
index 267fe78894..3a6efa3e73 100644
--- a/.github/workflows/ci-contributor-attribution.yml
+++ b/.github/workflows/ci-contributor-attribution.yml
@@ -3,6 +3,7 @@ name: "CI: Contributor attribution"
on:
pull_request_target:
types: [opened, edited, synchronize, reopened]
+ merge_group:
permissions:
contents: read
@@ -11,6 +12,7 @@ permissions:
jobs:
contributor-attribution:
name: contributor-attribution
+ if: github.event_name != 'merge_group'
runs-on: ubuntu-latest
steps:
# For pull_request_target, github.sha is the current commit on the trusted
diff --git a/.github/workflows/ci-gate.yml b/.github/workflows/ci-gate.yml
new file mode 100644
index 0000000000..9257d6a7a7
--- /dev/null
+++ b/.github/workflows/ci-gate.yml
@@ -0,0 +1,71 @@
+name: "CI: gate"
+
+on:
+ pull_request:
+ types: [opened, synchronize, reopened, ready_for_review, edited, labeled, unlabeled]
+ merge_group:
+
+permissions:
+ actions: read
+ contents: read
+ pull-requests: read
+
+jobs:
+ ci-gate:
+ name: ci-gate
+ runs-on: ubuntu-latest
+ timeout-minutes: 360
+ steps:
+ - name: Wait for every other workflow on the pull request head
+ env:
+ GH_TOKEN: ${{ github.token }}
+ PR_SHA: ${{ github.event.pull_request.head.sha }}
+ QUEUE_REF: ${{ github.event.merge_group.head_ref }}
+ run: |
+ set -uo pipefail
+ api() { local out; for _ in 1 2 3 4 5 6; do out=$(gh api "$@") && { printf '%s\n' "$out"; return; }; sleep 120; done; return 1; }
+ sha=$PR_SHA
+ if [[ -n "$QUEUE_REF" ]]; then
+ pr=$(grep -oP '/pr-\K[0-9]+' <<<"$QUEUE_REF") || exit 1
+ sha=$(api "repos/$GITHUB_REPOSITORY/pulls/$pr" --jq .head.sha) || exit 1
+ fi
+ runs() {
+ api --paginate "repos/$GITHUB_REPOSITORY/actions/runs?head_sha=$sha&per_page=100" \
+ --jq ".workflow_runs[] | select(.workflow_id != $GITHUB_WORKFLOW_ID and (.event == \"pull_request\" or .event == \"pull_request_target\") and (.path | test(\"claude-auto-fix|ci-release-reminder|review-cua-perception-candidates\") | not)) | [.workflow_id, .id, .name, .conclusion // \"\", .status] | @tsv"
+ }
+ GITHUB_WORKFLOW_ID=$(api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" --jq .workflow_id) || exit 1
+ sleep 90
+ previous=
+ while :; do
+ current=$(runs) || exit 1
+ if [[ -n "$current" && "$current" == "$previous" ]] && ! grep -qvP '\tcompleted$' <<<"$current"; then
+ break
+ fi
+ previous=$current
+ sleep 120
+ done
+ failed=0
+ for workflow in $(cut -f1 <<<"$current" | sort -u); do
+ verdict=skipped
+ name=$(awk -F'\t' -v w="$workflow" '$1 == w {print $3; exit}' <<<"$current")
+ newest=1
+ for run in $(awk -F'\t' -v w="$workflow" '$1 == w {print $2}' <<<"$current" | sort -rn); do
+ conclusion=$(awk -F'\t' -v r="$run" '$2 == r {print $4}' <<<"$current")
+ (( newest )) || [[ "$conclusion" != cancelled ]] || continue
+ newest=0
+ jobs=$(api --paginate "repos/$GITHUB_REPOSITORY/actions/runs/$run/jobs?filter=latest&per_page=100" \
+ --jq '.jobs[] | select(.conclusion != "skipped") | "\(.name)\t\(.conclusion)"') || exit 1
+ if [[ -z "$jobs" ]]; then
+ [[ "$conclusion" =~ ^(success|skipped|neutral)$ ]] && continue
+ jobs="run"$'\t'"$conclusion"
+ fi
+ verdict=pass
+ if [[ ! "$conclusion" =~ ^(success|neutral)$ ]]; then
+ verdict=fail
+ failed=1
+ fi
+ break
+ done
+ echo "$name: $verdict"
+ done
+ exit $failed
diff --git a/.github/workflows/ci-release-metadata.yml b/.github/workflows/ci-release-metadata.yml
index 3a56d9d964..1102b36204 100644
--- a/.github/workflows/ci-release-metadata.yml
+++ b/.github/workflows/ci-release-metadata.yml
@@ -3,6 +3,7 @@ name: "CI: Release metadata"
on:
pull_request:
types: [opened, edited, synchronize, reopened, labeled, unlabeled]
+ merge_group:
permissions:
contents: read
@@ -11,6 +12,7 @@ permissions:
jobs:
installer-compatibility:
+ if: github.event_name != 'merge_group'
uses: ./.github/workflows/ci-cua-driver-installer-compat.yml
permissions:
contents: read
@@ -18,7 +20,7 @@ jobs:
validate:
needs: installer-compatibility
- if: always()
+ if: always() && github.event_name != 'merge_group'
runs-on: ubuntu-latest
steps:
- name: Require successful installer certification
diff --git a/.github/workflows/fleet-mirror-guard.yml b/.github/workflows/fleet-mirror-guard.yml
index f98b2be011..28bc920c05 100644
--- a/.github/workflows/fleet-mirror-guard.yml
+++ b/.github/workflows/fleet-mirror-guard.yml
@@ -12,17 +12,19 @@ name: Fleet Mirror Guard
on:
pull_request:
types: [opened, synchronize, reopened]
+ merge_group:
permissions:
contents: read
pull-requests: write
concurrency:
- group: fleet-mirror-guard-${{ github.event.pull_request.number }}
+ group: fleet-mirror-guard-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
fleet-mirror-guard:
+ if: github.event_name != 'merge_group'
runs-on: ubuntu-latest
timeout-minutes: 5
steps: