Skip to content

Commit

Permalink
feat(ci): run codecov only on modified packages, not dependencies (#1433
Browse files Browse the repository at this point in the history
)

Signed-off-by: Dori Medini <[email protected]>
  • Loading branch information
dorimedini-starkware authored Oct 15, 2024
1 parent 6049de3 commit 458b545
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
run: |
python3 -m venv ci
ci/bin/pip install -r scripts/requirements.txt
ci/bin/python scripts/run_tests.py --changes_only --commit_id ${{ github.event.pull_request.base.sha }}
ci/bin/python scripts/run_tests.py --changes_only --include_dependencies --commit_id ${{ github.event.pull_request.base.sha }}
env:
SEED: 0

Expand Down
37 changes: 30 additions & 7 deletions scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,34 @@ def test_crates(crates: Set[str], codecov: bool):
print("Tests complete.")


def run_test(changes_only: bool, commit_id: Optional[str], codecov: bool):
def run_test(
changes_only: bool, commit_id: Optional[str], codecov: bool, include_dependencies: bool
):
"""
Runs tests.
If changes_only is True, only tests packages that have been modified; if no packages have been
modified, no tests are run. If changes_only is False, tests all packages.
If commit_id is provided, compares against that commit; otherwise, compares against HEAD.
"""
if not changes_only:
assert not include_dependencies, "include_dependencies can only be set with changes_only."
tested_packages = set()
if changes_only:
local_changes = get_local_changes(".", commit_id=commit_id)
modified_packages = get_modified_packages(local_changes)
for p in modified_packages:
deps = get_package_dependencies(p)
tested_packages.update(deps)
print(f"Running tests for {tested_packages} (due to modifications in {modified_packages}).")

if include_dependencies:
for p in modified_packages:
deps = get_package_dependencies(p)
tested_packages.update(deps)
print(
f"Running tests for {tested_packages} (due to modifications in "
f"{modified_packages})."
)
else:
print(f"Running tests for modified crates {modified_packages}.")
tested_packages = modified_packages

# Add global-triggered packages.
extra_packages = packages_to_test_due_to_global_changes(files=local_changes)
print(f"Running tests for global-triggered packages {extra_packages}")
Expand All @@ -70,15 +83,25 @@ def run_test(changes_only: bool, commit_id: Optional[str], codecov: bool):

def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Presubmit script.")
parser.add_argument("--changes_only", action="store_true")
parser.add_argument("--changes_only", action="store_true", help="Only test modified crates.")
parser.add_argument("--commit_id", type=str, help="GIT commit ID to compare against.")
parser.add_argument("--codecov", action="store_true", help="Run with codecov.")
parser.add_argument(
"--include_dependencies",
action="store_true",
help="Dependencies of modified crates are also tested. Can only be set with changes_only.",
)
return parser.parse_args()


def main():
args = parse_args()
run_test(changes_only=args.changes_only, commit_id=args.commit_id, codecov=args.codecov)
run_test(
changes_only=args.changes_only,
commit_id=args.commit_id,
codecov=args.codecov,
include_dependencies=args.include_dependencies,
)


if __name__ == "__main__":
Expand Down

0 comments on commit 458b545

Please sign in to comment.