Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
ci: Trigger tests on Cargo.toml and Cargo.lock changes (#48412)
Piotr Osiewiczf0dfb443d6f7
diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.ymlindex 05973e6884e..fe6c123b9b6 100644--- a/.github/workflows/run_tests.yml+++ b/.github/workflows/run_tests.yml@@ -51,8 +51,8 @@ jobs:if [ -z "$GITHUB_BASE_REF" ]; thenecho "Not a PR, running full test suite"echo "changed_packages=" >> "$GITHUB_OUTPUT"- elif echo "$CHANGED_FILES" | grep -qP '^(rust-toolchain\.toml|\.cargo/|\.github/)'; then- echo "Toolchain, .github or cargo config changed, will run all tests"+ elif echo "$CHANGED_FILES" | grep -qP '^(rust-toolchain\.toml|\.cargo/|\.github/|Cargo\.(toml|lock)$)'; then+ echo "Toolchain, cargo config, or root Cargo files changed, will run all tests"echo "changed_packages=" >> "$GITHUB_OUTPUT"else# Extract changed packages from file paths@@ -65,15 +65,8 @@ jobs:FILE_CHANGED_PKGS=$(printf '%s\n%s\n%s\n%s' "$FILE_CHANGED_PKGS" "settings" "storybook" "assets" | sort -u)fi- # Parse Cargo.toml and Cargo.lock for changed dependencies- CARGO_CHANGED_DEPS=""- if echo "$CHANGED_FILES" | grep -qP '^Cargo\.(toml|lock)$'; then- echo "Cargo files changed, analyzing..."- CARGO_CHANGED_DEPS=$(./script/diff-cargo-deps "$COMPARE_REV" || true)- fi-# Combine all changed packages- ALL_CHANGED_PKGS=$(printf '%s\n%s' "$FILE_CHANGED_PKGS" "$CARGO_CHANGED_DEPS" | sort -u | grep -v '^$' || true)+ ALL_CHANGED_PKGS=$(echo "$FILE_CHANGED_PKGS" | grep -v '^$' || true)if [ -z "$ALL_CHANGED_PKGS" ]; thenecho "No package changes detected, will run all tests"diff --git a/script/diff-cargo-deps b/script/diff-cargo-depsdeleted file mode 100755index a45ce442f25..00000000000--- a/script/diff-cargo-deps+++ /dev/null@@ -1,93 +0,0 @@-#!/usr/bin/env python3-"""-Diff workspace dependencies between two git revisions.--Compares both Cargo.toml [workspace.dependencies] and Cargo.lock [[package]]-entries to find which dependencies have changed.--Usage: diff-cargo-deps <old-git-ref>--Outputs one dependency name per line for any deps that were added, removed,-or modified (version, features, checksum, etc).-"""--import subprocess-import sys-import tomllib---def get_file_at_ref(ref: str, path: str) -> str:- """Get file contents at a specific git ref."""- result = subprocess.run(- ["git", "show", f"{ref}:{path}"],- capture_output=True,- text=True,- )- return result.stdout if result.returncode == 0 else ""---def get_workspace_deps(toml_content: str) -> dict:- """Extract [workspace.dependencies] from Cargo.toml content."""- if not toml_content:- return {}- try:- data = tomllib.loads(toml_content)- return data.get("workspace", {}).get("dependencies", {})- except Exception:- return {}---def get_lock_packages(lock_content: str) -> dict[str, dict]:- """Extract [[package]] entries from Cargo.lock as {name: full_entry}."""- if not lock_content:- return {}- try:- data = tomllib.loads(lock_content)- return {pkg["name"]: pkg for pkg in data.get("package", [])}- except Exception:- return {}---def diff_dicts(old: dict, new: dict) -> set[str]:- """Find keys that were added, removed, or whose values changed."""- changed = set()-- for name, value in new.items():- if name not in old or old[name] != value:- changed.add(name)-- for name in old:- if name not in new:- changed.add(name)-- return changed---def main():- if len(sys.argv) < 2:- print("Usage: diff-cargo-deps <old-git-ref>", file=sys.stderr)- sys.exit(1)-- old_ref = sys.argv[1]- changed = set()-- # Diff Cargo.toml workspace dependencies- old_toml = get_file_at_ref(old_ref, "Cargo.toml")- new_toml = open("Cargo.toml").read()- old_deps = get_workspace_deps(old_toml)- new_deps = get_workspace_deps(new_toml)- changed |= diff_dicts(old_deps, new_deps)-- # Diff Cargo.lock packages- old_lock = get_file_at_ref(old_ref, "Cargo.lock")- new_lock = open("Cargo.lock").read()- old_pkgs = get_lock_packages(old_lock)- new_pkgs = get_lock_packages(new_lock)- changed |= diff_dicts(old_pkgs, new_pkgs)-- for name in sorted(changed):- print(name)---if __name__ == "__main__":- main()diff --git a/tooling/xtask/src/tasks/workflows/run_tests.rs b/tooling/xtask/src/tasks/workflows/run_tests.rsindex 8df568bf493..331d6956288 100644--- a/tooling/xtask/src/tasks/workflows/run_tests.rs+++ b/tooling/xtask/src/tasks/workflows/run_tests.rs@@ -159,8 +159,8 @@ fn orchestrate_impl(rules: &[&PathCondition], include_package_filter: bool) -> Nif [ -z "$GITHUB_BASE_REF" ]; thenecho "Not a PR, running full test suite"echo "changed_packages=" >> "$GITHUB_OUTPUT"- elif echo "$CHANGED_FILES" | grep -qP '^(rust-toolchain\.toml|\.cargo/|\.github/)'; then- echo "Toolchain, .github or cargo config changed, will run all tests"+ elif echo "$CHANGED_FILES" | grep -qP '^(rust-toolchain\.toml|\.cargo/|\.github/|Cargo\.(toml|lock)$)'; then+ echo "Toolchain, cargo config, or root Cargo files changed, will run all tests"echo "changed_packages=" >> "$GITHUB_OUTPUT"else# Extract changed packages from file paths@@ -173,15 +173,8 @@ fn orchestrate_impl(rules: &[&PathCondition], include_package_filter: bool) -> NFILE_CHANGED_PKGS=$(printf '%s\n%s\n%s\n%s' "$FILE_CHANGED_PKGS" "settings" "storybook" "assets" | sort -u)fi- # Parse Cargo.toml and Cargo.lock for changed dependencies- CARGO_CHANGED_DEPS=""- if echo "$CHANGED_FILES" | grep -qP '^Cargo\.(toml|lock)$'; then- echo "Cargo files changed, analyzing..."- CARGO_CHANGED_DEPS=$(./script/diff-cargo-deps "$COMPARE_REV" || true)- fi-# Combine all changed packages- ALL_CHANGED_PKGS=$(printf '%s\n%s' "$FILE_CHANGED_PKGS" "$CARGO_CHANGED_DEPS" | sort -u | grep -v '^$' || true)+ ALL_CHANGED_PKGS=$(echo "$FILE_CHANGED_PKGS" | grep -v '^$' || true)if [ -z "$ALL_CHANGED_PKGS" ]; thenecho "No package changes detected, will run all tests"