Skip to content

Commit

Permalink
feature(ci): Identify which package need to be built according to fil…
Browse files Browse the repository at this point in the history
…e changed
  • Loading branch information
alon-dotan-starkware committed Jun 23, 2024
1 parent 0bd3526 commit 2397846
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/ci
/data
/logs
/target
Expand Down
84 changes: 3 additions & 81 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions crates/gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ testing = []
[dependencies]
axum.workspace = true
# TODO(YaelD, 1/5/2024): Use a fixed version once the StarkNet API is stable.
blockifier = { git = "https://github.com/starkware-libs/blockifier.git", rev = "6babc28a", features = [
"testing",
] }
blockifier = { path = "../blockifier", features = ["testing"] }
cairo-lang-starknet-classes.workspace = true
mempool_infra = { path = "../mempool_infra", version = "0.4.0-dev.2" }
papyrus_config = { path = "../papyrus_config", version = "0.4.0-dev.2" }
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_execution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ testing = ["rand", "rand_chacha", "papyrus_test_utils"]

[dependencies]
anyhow.workspace = true
blockifier = { version = "0.7.0-dev.1" }
blockifier = { path = "../blockifier" }
cairo-lang-starknet-classes.workspace = true
cairo-vm.workspace = true
indexmap.workspace = true
Expand Down
Binary file removed protoc-25.1-linux-x86_64.zip
Binary file not shown.
1 change: 1 addition & 0 deletions scripts/requirments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GitPython
79 changes: 79 additions & 0 deletions scripts/run_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/env python3
from ast import arg
import re
import subprocess
import os
from typing import Dict, List, Set
from git import Repo

PATTERN = r"(\w+)\s*v([\d.]*.*)\((.*?)\)"

def get_workspace_tree() -> Dict[str, str]:
tree = dict()
res = (
subprocess.check_output("cargo tree --depth 0".split())
.decode("utf-8")
.splitlines()
)
for l in res:
m = re.match(PATTERN, l)
if m is not None:
tree.update({m.group(1): m.group(3)})
return tree


def get_local_changes(repo_path) -> List[str]:
os.environ["GIT_PYTHON_REFRESH"] = "quiet" # noqa
repo = Repo(repo_path)
try:
repo.head.object # Check if local_repo is a git repo.
except ValueError:
print(f"unable to validate {repo_path} as a git repo.")
raise

return [c.a_path for c in repo.head.commit.diff(None)]


def get_modified_packages(files: List[str]) -> Set[str]:
tree = get_workspace_tree()
packages = set()
for file in files:
for p_name, p_path in tree.items():
if os.path.abspath(file).startswith(p_path):
packages.add(p_name)
return packages



def get_package_dependencies(package_name: str) -> Set[str]:
res = (
subprocess.check_output(f"cargo tree -i {package_name}".split())
.decode("utf-8")
.splitlines()
)
deps = set()
for l in res:
m = re.match(PATTERN, l)
if m is not None:
deps.add(m.group(1))
return deps


def run_test():
local_changes = get_local_changes(".")
modified_packages = get_modified_packages(local_changes)
for p in modified_packages:
deps = get_package_dependencies(p)
print(f"Running tests for {deps}")
args = []
for d in deps:
args.extend(["--package", d])
cmd = ["cargo", "test"] + args
print(cmd)
subprocess.run(cmd)

if __name__ == "__main__":
print("Running tests...")
run_test()
# Run tests here
print("Tests complete.")

0 comments on commit 2397846

Please sign in to comment.