Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/scripts/rust_affected.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3
"""Does this pull request change anything the Rust jobs build, lint or test?

CI's "Rust (clippy)" and "Rust (tests)" jobs run on every pull request (the
required "Rust (workspace)" check waits on both) but skip their steps when
the answer is no, so a pull request that only moves a pin
(selfhost/versions.json) finishes them in seconds instead of most of an hour.

The list is wider than the crates because the workspace reads more than its
own sources:
- include_str!/include_bytes! embed files from lambda/, infra/cfn/,
infra/lib/, installer/lib/ and docs/api/;
- worker/build.rs hashes services/worker/src and services/common/src;
- tests read or scan files across the repository: model_call_sites.rs walks
every .js/.mjs/.cjs/.ts/.tsx file, model_ids.rs and run_status.rs read
lambda/ and infra/lib/, and tests/no_hosted_urls.rs scans services, lambda,
infra/lib, infra/bin, installer/lib, installer/bin and selfhost.

Anything uncertain (no diff, an unexpected checkout) counts as a change, so
the jobs run in full rather than pass without running.

Usage: rust_affected.py [FILE ...] (no files: read names from stdin)
Prints "true" or "false".
"""

import sys

# Every file under these runs the Rust jobs.
DIRS = (
"services/",
"lambda/",
"docs/api/",
"infra/cfn/",
"infra/lib/",
"infra/bin/",
"installer/lib/",
"installer/bin/",
)

# The files that decide how this workflow runs them.
FILES = () # throwaway test: lets this PR (workflow + pin) take the skip path

# Cargo, toolchain and formatter settings, wherever they sit.
NAMES = (
"Cargo.toml",
"Cargo.lock",
"rustfmt.toml",
".rustfmt.toml",
"clippy.toml",
".clippy.toml",
)

# Rust sources anywhere, and the JS/TS model_call_sites.rs scans repo-wide.
EXTS = (".rs", ".js", ".mjs", ".cjs", ".ts", ".tsx")

# What tests/no_hosted_urls.rs scans under selfhost/ (versions.json is not).
SELFHOST_EXTS = (".rs", ".ts", ".mjs", ".js", ".py", ".sh", ".yaml", ".yml", ".html")


def affects_rust(path):
path = path.strip()
name = path.rsplit("/", 1)[-1]
return (
path.startswith(DIRS)
or path in FILES
or name in NAMES
or name.startswith("rust-toolchain")
or path.startswith(".cargo/")
or "/.cargo/" in path
or path.endswith(EXTS)
or (path.startswith("selfhost/") and path.endswith(SELFHOST_EXTS))
)


def main(argv):
paths = argv[1:] or sys.stdin.read().splitlines()
paths = [p for p in paths if p.strip()]
# No changed files means the diff did not work: run everything.
run = not paths or any(affects_rust(p) for p in paths)
print("true" if run else "false")
return 0


if __name__ == "__main__":
sys.exit(main(sys.argv))
44 changes: 44 additions & 0 deletions .github/scripts/test_rust_affected.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import sys
import unittest

sys.path.insert(0, os.path.dirname(__file__))

from rust_affected import affects_rust # noqa: E402


class AffectsRust(unittest.TestCase):
def test_pin_and_docs_only_skip(self):
for p in [
"selfhost/versions.json",
"README.md",
"docs/incidents.md",
"coderhelm-jira/manifest.yml",
".github/workflows/deploy.yml",
]:
self.assertFalse(affects_rust(p), p)

def test_rust_inputs_run(self):
for p in [
"services/worker/src/main.rs",
"services/common/contract/messages.json",
"services/Cargo.lock",
"services/rust-toolchain.toml",
"rustfmt.toml",
".cargo/config.toml",
"services/.cargo/config.toml",
".github/workflows/ci.yml",
".github/scripts/rust_affected.py",
"lambda/log-analyzer/model_prices.json",
"infra/cfn/coderhelm-log-reader.yaml",
"docs/api/openapi.json",
"installer/lib/github-app.mjs",
"coderhelm-jira/src/index.js",
"selfhost/install.sh",
"selfhost/launch/check.mjs",
]:
self.assertTrue(affects_rust(p), p)


if __name__ == "__main__":
unittest.main()
53 changes: 47 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,37 @@ jobs:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
# The merge commit and its first parent (the base it merged onto).
fetch-depth: 2
# Skip the steps below when nothing the Rust build reads changed (a pin
# bump in selfhost/versions.json): the job still reports, in seconds.
# The list and why: .github/scripts/rust_affected.py.
- name: Rust-affecting changes
id: changes
working-directory: .
run: |
if git rev-parse --verify -q HEAD^2 >/dev/null; then
run=$(git diff --name-only HEAD^1 HEAD | python3 .github/scripts/rust_affected.py)
else
run=true
fi
echo "run=$run" >> "$GITHUB_OUTPUT"
echo "Rust steps run: $run"
- if: steps.changes.outputs.run == 'true'
uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
- if: steps.changes.outputs.run == 'true'
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
workspaces: services
cache-on-failure: true
- run: cargo fmt --check --all
- if: steps.changes.outputs.run == 'true'
run: cargo fmt --check --all
# --all-targets: tests are linted too (a test-only lint once failed
# only on a local --all-targets run).
- run: cargo clippy --workspace --all-targets -- -D warnings
- if: steps.changes.outputs.run == 'true'
run: cargo clippy --workspace --all-targets -- -D warnings

rust-test:
name: Rust (tests)
Expand All @@ -80,8 +100,26 @@ jobs:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
# The merge commit and its first parent (the base it merged onto).
fetch-depth: 2
# Skip the steps below when nothing the Rust build reads changed (a pin
# bump in selfhost/versions.json): the job still reports, in seconds.
# The list and why: .github/scripts/rust_affected.py.
- name: Rust-affecting changes
id: changes
working-directory: .
run: |
if git rev-parse --verify -q HEAD^2 >/dev/null; then
run=$(git diff --name-only HEAD^1 HEAD | python3 .github/scripts/rust_affected.py)
else
run=true
fi
echo "run=$run" >> "$GITHUB_OUTPUT"
echo "Rust steps run: $run"
- if: steps.changes.outputs.run == 'true'
uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
- if: steps.changes.outputs.run == 'true'
uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
workspaces: services
cache-on-failure: true
Expand All @@ -91,17 +129,20 @@ jobs:
# --workspace on both steps: one feature set, so one build (`-p worker`
# alone resolves features differently and compiles everything again).
- name: Incident regressions
if: steps.changes.outputs.run == 'true'
run: cargo test --workspace -- 'incidents::'
# Stops, asks, blocks and loops replayed through the real decision
# functions and graded on the decision, with the stop judge's recorded
# answers k = 3 times each (pass^k; passes/replay/README.md). It gates
# any prompt, model or effort change to a judgment step.
- name: Replay suite
if: steps.changes.outputs.run == 'true'
run: cargo test --workspace -- 'replay::'
# Includes the reviewer evals (worker passes::review_eval): recorded
# review histories replayed through the real decision code, no model.
# The incident and replay suites already ran above, on the same build.
- name: Workspace tests
if: steps.changes.outputs.run == 'true'
run: cargo test --workspace -- --skip 'incidents::' --skip 'replay::'

rust:
Expand Down
2 changes: 1 addition & 1 deletion selfhost/versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"about": "The dashboard commit each platform release ships: a full 40-character commit SHA of CoderHelm/coderhelm, never a branch or tag (scripts/check-dashboard-ref.mjs fails CI and the release otherwise). The release workflow builds exactly this commit (dashboard/) into dashboard.tar.gz. Move it with scripts/bump-dashboard.sh in a reviewed PR, in the same PR as any API change the dashboard needs.",
"about": "The dashboard commit each platform release ships: a full 40-character commit SHA of CoderHelm/coderhelm, never a branch or tag (scripts/check-dashboard-ref.mjs fails CI and the release otherwise). The release workflow builds exactly this commit (dashboard/) into dashboard.tar.gz. Move it with scripts/bump-dashboard.sh in a reviewed PR, in the same PR as any API change the dashboard needs. (throwaway CI test)",
"dashboardRef": "7c863eb49c569105c69363fd74a9781e97ebc2f5"
}
Loading