Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: run only rust tests affected with changed files #928

Merged

Conversation

MatejVukosav
Copy link
Member

@MatejVukosav MatejVukosav commented Nov 3, 2024

Tested with changed files
https://github.com/calimero-network/core/actions/runs/11698775125

./scripts/test.sh now accepts --all or --local {changed_files}

Docs calimero-network/calimero-network.github.io#48

@MatejVukosav MatejVukosav self-assigned this Nov 3, 2024
@MatejVukosav MatejVukosav marked this pull request as draft November 3, 2024 12:34
@MatejVukosav MatejVukosav force-pushed the chore--run-only-rust-tests-affected-with-changed-files branch from 440184f to 3282a2b Compare November 3, 2024 12:59
@MatejVukosav MatejVukosav force-pushed the chore--run-only-rust-tests-affected-with-changed-files branch 4 times, most recently from 0f30db8 to 607c923 Compare November 3, 2024 16:29
@MatejVukosav MatejVukosav force-pushed the chore--run-only-rust-tests-affected-with-changed-files branch from 607c923 to d55637c Compare November 3, 2024 16:45
Copy link
Member

@chefsale chefsale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MatejVukosav MatejVukosav marked this pull request as ready for review November 6, 2024 07:05
…-run-only-rust-tests-affected-with-changed-files
@MatejVukosav MatejVukosav force-pushed the chore--run-only-rust-tests-affected-with-changed-files branch from 10b935e to 3a1392f Compare November 6, 2024 07:07
@MatejVukosav MatejVukosav merged commit 1ff1351 into master Nov 6, 2024
15 checks passed
@MatejVukosav MatejVukosav deleted the chore--run-only-rust-tests-affected-with-changed-files branch November 6, 2024 07:31
Copy link
Member

@miraclx miraclx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of the crates don't compile on their own, for example calimero-server, calimero-node-primitives, calimero-config etc, relying instead for merod & meroctl to maximally define all the minimum feature requirements to satisfy all the crates.

Not an ideal situation, but quite the effort to untangle. It's tracked by #265 under

This PR attempts to test each crate independently, it will break in cases where cargo build for a specific crate doesn't work.

if mode is not "all", this will not test apps and contracts? they don't have calimero- prefix, nor are they in crates/* folder.

We should revert this.

Comment on lines +77 to +93
# Remove duplicates
unique_changed_crates=()
for item in "${changed_crates[@]}"; do
# Check if item is already in unique_array
duplicate=false
for unique_item in "${unique_changed_crates[@]}"; do
if [[ "$item" == "$unique_item" ]]; then
duplicate=true
break
fi
done
# If item is not a duplicate, add it to unique_array
if ! $duplicate; then
unique_changed_crates+=("$item")
fi
done
echo "Unique crates from changed files" "${unique_changed_crates[@]}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uniq command?

Comment on lines +101 to +117
# get list of all dependencies from the crate including external dependencies
dependencies=($(cargo metadata --format-version=1 --no-deps | jq -r --arg CRATE "$calimero_package_name" '
.packages[] |
select(.dependencies | any(.name == $CRATE)) |
.name
'))

for dep in "${dependencies[@]}"; do
# Compare dependency with list of crates from workspace to skip external dependencies
calimero_dep_crate_path="${dep/calimero-/crates/}"
for crate in "${all_crates[@]}"; do
if [[ "$crate" == "$calimero_dep_crate_path" ]]; then
echo "Found matching dependency: $calimero_dep_crate_path"
dep_arr+=("$calimero_dep_crate_path")
fi
done
done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't need to test dependencies of changed crates, but "dependents" of changed crates.

calimero-node depends on calimero-context which depends on calimero-primitives, if calimero-context changes we need to test that as well as calimero-node, but not necessarily calimero-primitives

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It tests dependencies which imports changed crate

crate_package_name=("${crate/crates\//calimero-}")
if [[ "$crate_package_name" == "calimero-merod" ]]; then
echo "Testing crate merod"
cargo +nightly test -p "merod"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why test with nightly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants