diff --git a/.github/workflows/routed-rust.yml b/.github/workflows/routed-rust.yml new file mode 100644 index 00000000000..21b0aa462fb --- /dev/null +++ b/.github/workflows/routed-rust.yml @@ -0,0 +1,375 @@ +name: Routed Rust Small + +on: + pull_request: + types: [opened, synchronize, reopened, labeled, unlabeled] + push: + branches: [main, master] + workflow_dispatch: + +permissions: + actions: read + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' && github.event.action == 'synchronize' }} + +env: + CARGO_TERM_COLOR: always + +jobs: + route: + name: Route Ripr Rust Small + runs-on: ubuntu-latest + outputs: + router_target: ${{ steps.route.outputs.router_target }} + router_reason: ${{ steps.route.outputs.router_reason }} + repo: ${{ steps.route.outputs.repo }} + workflow: ${{ steps.route.outputs.workflow }} + run_id: ${{ steps.route.outputs.run_id }} + steps: + - name: Select runner + id: route + env: + GH_TOKEN: ${{ secrets.EM_RUNNER_READ_TOKEN || github.token }} + EVENT_NAME: ${{ github.event_name }} + HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name || '' }} + REPOSITORY: ${{ github.repository }} + RUN_ID: ${{ github.run_id }} + run: | + target=github + reason=runner_api_failed + if [ "$EVENT_NAME" = "pull_request" ] && [ "$HEAD_REPO" != "$REPOSITORY" ]; then + reason=fork_or_untrusted_pr + else + if runners="$(gh api orgs/EffortlessMetrics/actions/runners --paginate 2>/tmp/runners.err)"; then + if printf '%s' "$runners" | jq -e '.runners[] | select(.status == "online" and (.busy | not) and ([.labels[].name | ascii_downcase] | index("cx53") and index("em-ci-rust-1.95")))' >/dev/null; then + target=cx53 + reason=cx53_idle + elif printf '%s' "$runners" | jq -e '.runners[] | select(.status == "online" and (.busy | not) and ([.labels[].name | ascii_downcase] | index("cx43") and index("em-ci-rust-1.95")))' >/dev/null; then + target=cx43 + reason=cx43_idle + elif printf '%s' "$runners" | jq -e '.runners[] | select(.status == "online" and (.busy | not) and ([.labels[].name | ascii_downcase] | (index("cx53") or index("cx43"))))' >/dev/null; then + reason=runner_image_unavailable + else + reason=no_idle_runner + fi + else + reason=runner_api_failed + fi + fi + { + echo "router_target=$target" + echo "router_reason=$reason" + echo "repo=$REPOSITORY" + echo "workflow=routed-rust" + echo "run_id=$RUN_ID" + } >> "$GITHUB_OUTPUT" + { + echo "### Ripr Rust Small Router" + echo "" + echo "- repo: \`$REPOSITORY\`" + echo "- workflow: \`routed-rust\`" + echo "- run: \`$RUN_ID\`" + echo "- target: \`$target\`" + echo "- reason: \`$reason\`" + } >> "$GITHUB_STEP_SUMMARY" + + rust-cx53: + name: Ripr Rust Small on CX53 + needs: route + if: needs.route.outputs.router_target == 'cx53' + runs-on: + group: em-ci-small + labels: [self-hosted, Linux, X64, CX53, em-ci-rust-1.95] + container: + image: em-ci-rust:1.95 + options: --cpus=14 --memory=28g -v /mnt/ci-scratch:/mnt/ci-scratch -v /mnt/ci-cache:/mnt/ci-cache -v /mnt/docker:/mnt/docker + env: + CARGO_BUILD_JOBS: "12" + CARGO_HOME: /mnt/ci-cache/cargo-home + SCCACHE_DIR: /mnt/ci-cache/sccache + CARGO_TARGET_DIR: /mnt/ci-scratch/target/${{ github.run_id }}-${{ github.run_attempt }} + TMPDIR: /mnt/ci-scratch/tmp/${{ github.run_id }}-${{ github.run_attempt }} + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + - name: Prepare scratch + run: | + ci-disk-guard /mnt/ci-scratch 100 + ci-disk-guard /mnt/docker 20 + ci-disk-guard /mnt/ci-cache 20 + mkdir -p "$CARGO_HOME" "$SCCACHE_DIR" "$CARGO_TARGET_DIR" "$TMPDIR" + - name: Required Rust gates + run: | + cargo fmt --check + cargo check --workspace --all-targets + cargo clippy --workspace --all-targets -- -D warnings + cargo test --workspace + cargo xtask check-static-language + cargo xtask check-no-panic-family + cargo xtask check-allow-attributes + cargo xtask check-local-context + cargo xtask check-file-policy + cargo xtask check-executable-files + cargo xtask check-workflows + cargo xtask check-droid-review-config + cargo xtask check-spec-format + cargo xtask check-spec-numbering + cargo xtask check-fixture-contracts + cargo xtask check-generated + cargo xtask check-badge-diff-policy + cargo xtask check-generated-clean + cargo xtask check-dependencies + cargo xtask check-process-policy + cargo xtask check-network-policy + - name: Advisory reports + if: always() + run: | + cargo xtask test-efficiency-report || true + cargo xtask badge-artifacts || true + cargo xtask pr-summary || true + cargo xtask reports index || true + cargo xtask receipts || true + cargo xtask reports index || true + - name: PR evidence + if: github.event_name == 'pull_request' + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + GITHUB_PR_LABELS: ${{ join(github.event.pull_request.labels.*.name, ',') }} + RIPR_REVIEW_COMMENTS_TIMEOUT_SECS: "60" + run: | + cargo xtask ripr-pr --base "$BASE_SHA" --head "$HEAD_SHA" + cargo xtask ripr-pr --base "$BASE_SHA" --head "$HEAD_SHA" --check + cargo xtask ripr-review-comments --base "$BASE_SHA" --head "$HEAD_SHA" + cargo xtask ripr-review-comments --base "$BASE_SHA" --head "$HEAD_SHA" --check + cargo xtask impacted-evidence + cargo xtask impacted-evidence --check + cargo xtask ripr-pr-summary + cargo xtask ripr-pr-summary --check + cargo xtask ripr-annotations + cargo xtask ripr-annotations --check + - name: Upload ripr reports + if: always() + uses: actions/upload-artifact@v7 + with: + name: ripr-rust-small-cx53 + path: | + target/ripr/reports/ + target/ripr/receipts/ + target/ripr/pr/ + target/ripr/review/ + target/xtask/impacted-evidence/ + if-no-files-found: ignore + - name: Clean scratch + if: always() + run: | + cargo clean || true + rm -rf "$CARGO_TARGET_DIR" "$TMPDIR" + + rust-cx43: + name: Ripr Rust Small on CX43 + needs: route + if: needs.route.outputs.router_target == 'cx43' + runs-on: + group: em-ci-small + labels: [self-hosted, Linux, X64, CX43, em-ci-rust-1.95] + container: + image: em-ci-rust:1.95 + options: --cpus=14 --memory=28g -v /mnt/ci-scratch:/mnt/ci-scratch -v /mnt/ci-cache:/mnt/ci-cache -v /mnt/docker:/mnt/docker + env: + CARGO_BUILD_JOBS: "12" + CARGO_HOME: /mnt/ci-cache/cargo-home + SCCACHE_DIR: /mnt/ci-cache/sccache + CARGO_TARGET_DIR: /mnt/ci-scratch/target/${{ github.run_id }}-${{ github.run_attempt }} + TMPDIR: /mnt/ci-scratch/tmp/${{ github.run_id }}-${{ github.run_attempt }} + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + - name: Prepare scratch + run: | + ci-disk-guard /mnt/ci-scratch 100 + ci-disk-guard /mnt/docker 20 + ci-disk-guard /mnt/ci-cache 20 + mkdir -p "$CARGO_HOME" "$SCCACHE_DIR" "$CARGO_TARGET_DIR" "$TMPDIR" + - name: Required Rust gates + run: | + cargo fmt --check + cargo check --workspace --all-targets + cargo clippy --workspace --all-targets -- -D warnings + cargo test --workspace + cargo xtask check-static-language + cargo xtask check-no-panic-family + cargo xtask check-allow-attributes + cargo xtask check-local-context + cargo xtask check-file-policy + cargo xtask check-executable-files + cargo xtask check-workflows + cargo xtask check-droid-review-config + cargo xtask check-spec-format + cargo xtask check-spec-numbering + cargo xtask check-fixture-contracts + cargo xtask check-generated + cargo xtask check-badge-diff-policy + cargo xtask check-generated-clean + cargo xtask check-dependencies + cargo xtask check-process-policy + cargo xtask check-network-policy + - name: Advisory reports + if: always() + run: | + cargo xtask test-efficiency-report || true + cargo xtask badge-artifacts || true + cargo xtask pr-summary || true + cargo xtask reports index || true + cargo xtask receipts || true + cargo xtask reports index || true + - name: PR evidence + if: github.event_name == 'pull_request' + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + GITHUB_PR_LABELS: ${{ join(github.event.pull_request.labels.*.name, ',') }} + RIPR_REVIEW_COMMENTS_TIMEOUT_SECS: "60" + run: | + cargo xtask ripr-pr --base "$BASE_SHA" --head "$HEAD_SHA" + cargo xtask ripr-pr --base "$BASE_SHA" --head "$HEAD_SHA" --check + cargo xtask ripr-review-comments --base "$BASE_SHA" --head "$HEAD_SHA" + cargo xtask ripr-review-comments --base "$BASE_SHA" --head "$HEAD_SHA" --check + cargo xtask impacted-evidence + cargo xtask impacted-evidence --check + cargo xtask ripr-pr-summary + cargo xtask ripr-pr-summary --check + cargo xtask ripr-annotations + cargo xtask ripr-annotations --check + - name: Upload ripr reports + if: always() + uses: actions/upload-artifact@v7 + with: + name: ripr-rust-small-cx43 + path: | + target/ripr/reports/ + target/ripr/receipts/ + target/ripr/pr/ + target/ripr/review/ + target/xtask/impacted-evidence/ + if-no-files-found: ignore + - name: Clean scratch + if: always() + run: | + cargo clean || true + rm -rf "$CARGO_TARGET_DIR" "$TMPDIR" + + rust-github: + name: Ripr Rust Small on GitHub Hosted + needs: route + if: needs.route.outputs.router_target == 'github' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + with: + shared-key: ripr-swarm-rust-small-${{ runner.os }} + save-if: ${{ github.ref == 'refs/heads/main' }} + - name: Required Rust gates + run: | + cargo fmt --check + cargo check --workspace --all-targets + cargo clippy --workspace --all-targets -- -D warnings + cargo test --workspace + cargo xtask check-static-language + cargo xtask check-no-panic-family + cargo xtask check-allow-attributes + cargo xtask check-local-context + cargo xtask check-file-policy + cargo xtask check-executable-files + cargo xtask check-workflows + cargo xtask check-droid-review-config + cargo xtask check-spec-format + cargo xtask check-spec-numbering + cargo xtask check-fixture-contracts + cargo xtask check-generated + cargo xtask check-badge-diff-policy + cargo xtask check-generated-clean + cargo xtask check-dependencies + cargo xtask check-process-policy + cargo xtask check-network-policy + - name: Advisory reports + if: always() + run: | + cargo xtask test-efficiency-report || true + cargo xtask badge-artifacts || true + cargo xtask pr-summary || true + cargo xtask reports index || true + cargo xtask receipts || true + cargo xtask reports index || true + - name: PR evidence + if: github.event_name == 'pull_request' + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + GITHUB_PR_LABELS: ${{ join(github.event.pull_request.labels.*.name, ',') }} + RIPR_REVIEW_COMMENTS_TIMEOUT_SECS: "60" + run: | + cargo xtask ripr-pr --base "$BASE_SHA" --head "$HEAD_SHA" + cargo xtask ripr-pr --base "$BASE_SHA" --head "$HEAD_SHA" --check + cargo xtask ripr-review-comments --base "$BASE_SHA" --head "$HEAD_SHA" + cargo xtask ripr-review-comments --base "$BASE_SHA" --head "$HEAD_SHA" --check + cargo xtask impacted-evidence + cargo xtask impacted-evidence --check + cargo xtask ripr-pr-summary + cargo xtask ripr-pr-summary --check + cargo xtask ripr-annotations + cargo xtask ripr-annotations --check + - name: Upload ripr reports + if: always() + uses: actions/upload-artifact@v7 + with: + name: ripr-rust-small-github + path: | + target/ripr/reports/ + target/ripr/receipts/ + target/ripr/pr/ + target/ripr/review/ + target/xtask/impacted-evidence/ + if-no-files-found: ignore + + result: + name: Ripr Rust Small Result + needs: [route, rust-cx53, rust-cx43, rust-github] + if: always() + runs-on: ubuntu-latest + steps: + - name: Summarize routed result + env: + TARGET: ${{ needs.route.outputs.router_target }} + REASON: ${{ needs.route.outputs.router_reason }} + ROUTE_RESULT: ${{ needs.route.result }} + CX53_RESULT: ${{ needs.rust-cx53.result }} + CX43_RESULT: ${{ needs.rust-cx43.result }} + GITHUB_RESULT: ${{ needs.rust-github.result }} + run: | + echo "### Ripr Rust Small Result" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "- target: \`$TARGET\`" >> "$GITHUB_STEP_SUMMARY" + echo "- reason: \`$REASON\`" >> "$GITHUB_STEP_SUMMARY" + echo "- route: \`$ROUTE_RESULT\`" >> "$GITHUB_STEP_SUMMARY" + echo "- cx53: \`$CX53_RESULT\`" >> "$GITHUB_STEP_SUMMARY" + echo "- cx43: \`$CX43_RESULT\`" >> "$GITHUB_STEP_SUMMARY" + echo "- github: \`$GITHUB_RESULT\`" >> "$GITHUB_STEP_SUMMARY" + if [ "$ROUTE_RESULT" != "success" ]; then + exit 1 + fi + case "$TARGET" in + cx53) [ "$CX53_RESULT" = "success" ] ;; + cx43) [ "$CX43_RESULT" = "success" ] ;; + github) [ "$GITHUB_RESULT" = "success" ] ;; + *) exit 1 ;; + esac diff --git a/docs/CI.md b/docs/CI.md index 329d560199f..88b376c5486 100644 --- a/docs/CI.md +++ b/docs/CI.md @@ -241,6 +241,47 @@ and should usually be split. ## Current Workflows +### Swarm Routed Rust + +`ripr-swarm` adds `.github/workflows/routed-rust.yml` as the development-trunk +Rust gate. It exposes one branch-protection-facing check: + +```text +Ripr Rust Small Result +``` + +The implementation jobs are conditional and should not be required directly: + +```text +Route Ripr Rust Small +Ripr Rust Small on CX53 +Ripr Rust Small on CX43 +Ripr Rust Small on GitHub Hosted +``` + +Routing policy: + +```text +trusted same-repo PR or push: + CX53 if idle + CX43 if idle + GitHub-hosted otherwise + +fork or otherwise untrusted PR: + GitHub-hosted only +``` + +The router uses the repository or organization `EM_RUNNER_READ_TOKEN` secret +when available. It selects a self-hosted runner only when the runner is idle and +has both the host label (`CX53` or `CX43`) and the `em-ci-rust-1.95` +image-readiness label. If runner state cannot be read, or a runner is idle but +not image-ready, the workflow fails closed to GitHub-hosted rather than +selecting a self-hosted runner by guesswork. + +The routed lane runs the existing Rust/product command surface without release +package or publish dry-run steps. It keeps advisory evidence artifacts +non-blocking and uploads the normal `target/ripr` report packet when present. + The Rust workflow currently runs: ```bash diff --git a/docs/REPO_SETTINGS.md b/docs/REPO_SETTINGS.md index 74cacef40f7..06d9795233f 100644 --- a/docs/REPO_SETTINGS.md +++ b/docs/REPO_SETTINGS.md @@ -150,6 +150,8 @@ Expected first required checks after proof: Do not require conditional implementation jobs such as `Ripr Rust Small on CX53`, `Ripr Rust Small on CX43`, or `Ripr Rust Small on GitHub Hosted`. +Branch protection should be applied only after `.github/workflows/routed-rust.yml` +has proven CX53, CX43, and GitHub-hosted fallback behavior. Settings App managed rules: diff --git a/docs/swarm-development.md b/docs/swarm-development.md index 69738fa3d6a..553ddfea8e7 100644 --- a/docs/swarm-development.md +++ b/docs/swarm-development.md @@ -30,6 +30,33 @@ Self-hosted jobs are only for trusted same-repo PRs and pushes. Fork or otherwise untrusted pull requests must route to GitHub-hosted runners or skip self-hosted implementation jobs. +The routed Rust workflow is `.github/workflows/routed-rust.yml`. It emits one +branch-protection-facing check: + +```text +Ripr Rust Small Result +``` + +Implementation jobs are conditional: + +```text +Route Ripr Rust Small +Ripr Rust Small on CX53 +Ripr Rust Small on CX43 +Ripr Rust Small on GitHub Hosted +``` + +Do not require implementation jobs directly in branch protection. + +The router reads runner state with `EM_RUNNER_READ_TOKEN` when that secret is +available. It selects a self-hosted runner only when the runner is idle and has +the matching host label plus the `em-ci-rust-1.95` image-readiness label. If +runner state cannot be read, no target runner is idle, or a runner is available +but not image-ready, the workflow falls back to GitHub-hosted with +`router_reason=runner_api_failed`, `router_reason=no_idle_runner`, or +`router_reason=runner_image_unavailable`. Fork PRs route to GitHub-hosted with +`router_reason=fork_or_untrusted_pr`. + The VS Code lane should remain hosted until a separate Node 24 / VS Code / Xvfb runner image is proven. diff --git a/policy/ci-lane-whitelist.toml b/policy/ci-lane-whitelist.toml index 9b51411a318..da9d998f872 100644 --- a/policy/ci-lane-whitelist.toml +++ b/policy/ci-lane-whitelist.toml @@ -45,6 +45,16 @@ estimated_lem = 12 artifact_families = [] description = "Primary Rust merge-safety lane." +[[lane]] +id = "routed-rust-small" +posture = "required" +workflow = ".github/workflows/routed-rust.yml" +jobs = ["Ripr Rust Small Result"] +commands = ["cargo fmt --check", "cargo check --workspace --all-targets", "cargo clippy --workspace --all-targets -- -D warnings", "cargo test --workspace", "cargo xtask check-static-language", "cargo xtask check-no-panic-family", "cargo xtask check-allow-attributes", "cargo xtask check-local-context", "cargo xtask check-file-policy", "cargo xtask check-executable-files", "cargo xtask check-workflows", "cargo xtask check-droid-review-config", "cargo xtask check-spec-format", "cargo xtask check-spec-numbering", "cargo xtask check-fixture-contracts", "cargo xtask check-generated", "cargo xtask check-badge-diff-policy", "cargo xtask check-generated-clean", "cargo xtask check-dependencies", "cargo xtask check-process-policy", "cargo xtask check-network-policy"] +estimated_lem = 12 +artifact_families = ["ripr-evidence"] +description = "Swarm Rust Small result gate routed through CX53, CX43, or GitHub-hosted fallback." + [[lane]] id = "msrv" posture = "required" diff --git a/policy/workflow_allowlist.txt b/policy/workflow_allowlist.txt index 85f45f8ea71..0bfa869b244 100644 --- a/policy/workflow_allowlist.txt +++ b/policy/workflow_allowlist.txt @@ -17,5 +17,6 @@ .github/workflows/pr-plan.yml|1|Advisory PR Plan workflow keeps each run block to one shell command (mkdir/git, ls, printf). .github/workflows/publish-extension.yml|20|Release workflow includes marketplace packaging and publishing orchestration. .github/workflows/release-server-binaries.yml|1|Release workflow delegates server archive packaging, manifest generation, and release upload branching to Rust xtask commands. +.github/workflows/routed-rust.yml|60|Swarm routed Rust workflow selects CX53, CX43, or hosted fallback and runs the existing Rust/product command surface. .github/workflows/security.yml|0|Security workflow uses standard cargo-deny and dependency-review actions without shell run blocks. .github/workflows/test-analytics.yml|1|Test analytics workflow keeps each run block to one cargo or echo command.