Skip to content

Commit

Permalink
refactor(ci): combine test/codecov scripts (#1406)
Browse files Browse the repository at this point in the history
Signed-off-by: Dori Medini <dori@starkware.co>
  • Loading branch information
dorimedini-starkware authored Oct 15, 2024
1 parent 4f50219 commit 57a15a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
run: |
python3 -m venv ci
ci/bin/pip install -r scripts/requirements.txt
ci/bin/python scripts/run_codecov.py --changes_only --commit_id ${{ github.event.pull_request.base.sha }}
ci/bin/python scripts/run_tests.py --codecov --changes_only --commit_id ${{ github.event.pull_request.base.sha }}
if [ -f codecov.json ]; then
echo "codecov_output=true" >> $GITHUB_OUTPUT
else
Expand All @@ -150,7 +150,7 @@ jobs:
run: |
python3 -m venv ci
ci/bin/pip install -r scripts/requirements.txt
ci/bin/python scripts/run_codecov.py
ci/bin/python scripts/run_tests.py --codecov
echo "codecov_output=true" >> $GITHUB_OUTPUT
env:
SEED: 0
Expand Down
50 changes: 0 additions & 50 deletions scripts/run_codecov.py

This file was deleted.

15 changes: 10 additions & 5 deletions scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def packages_to_test_due_to_global_changes(files: List[str]) -> Set[str]:
return set()


def test_crates(crates: Set[str]):
def test_crates(crates: Set[str], codecov: bool):
"""
Runs tests for the given crates.
If no crates provided, runs tests for all crates.
Expand All @@ -30,15 +30,19 @@ def test_crates(crates: Set[str]):
args.extend(["--package", package])

# If crates is empty (i.e. changes_only is False), all packages will be tested (no args).
cmd = ["cargo", "test"] + args
cmd = (
["cargo", "llvm-cov", "--codecov", "-r", "--output-path", "codecov.json"]
if codecov
else ["cargo", "test"]
) + args

print("Running tests...")
print(cmd, flush=True)
subprocess.run(cmd, check=True)
print("Tests complete.")


def run_test(changes_only: bool, commit_id: Optional[str]):
def run_test(changes_only: bool, commit_id: Optional[str], codecov: bool):
"""
Runs tests.
If changes_only is True, only tests packages that have been modified; if no packages have been
Expand All @@ -61,19 +65,20 @@ def run_test(changes_only: bool, commit_id: Optional[str]):
print("No changes detected.")
return

test_crates(crates=tested_packages)
test_crates(crates=tested_packages, codecov=codecov)


def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Presubmit script.")
parser.add_argument("--changes_only", action="store_true")
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.")
return parser.parse_args()


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


if __name__ == "__main__":
Expand Down

0 comments on commit 57a15a3

Please sign in to comment.