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

Convert run-checks script into a Rust binary #628

Merged
merged 28 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cb5d5f8
scripts: Convert run-checks script into a Rust binary
Luni-4 Aug 11, 2023
a454043
Remove shell script
Luni-4 Aug 11, 2023
10037c6
misc: Improve README
Luni-4 Aug 11, 2023
c3f31e3
misc: Make git ignore scripts binaries
Luni-4 Aug 11, 2023
6993fc5
misc: Update pull request template
Luni-4 Aug 11, 2023
151bb2f
ci: Use run-checks binary to run ci checks
Luni-4 Aug 11, 2023
fc8872b
scripts: Exit only when command result is not a success
Luni-4 Aug 11, 2023
1a7c56b
scripts: Fix stdout and stderr function
Luni-4 Aug 11, 2023
85b78bc
scripts: Fix wrong target
Luni-4 Aug 11, 2023
7acc087
scripts: Use constants for no_std targets
Luni-4 Aug 11, 2023
91fe7b0
scripts: Always color cargo output
Luni-4 Aug 12, 2023
22a5ca9
scripts: Remove superfluous prints
Luni-4 Aug 12, 2023
49bb054
scripts: Flush stdout and stderr
Luni-4 Aug 12, 2023
b076e80
scripts: Print commands coherently
Luni-4 Aug 12, 2023
ba9915f
scripts: Use println instead of std::io
Luni-4 Aug 12, 2023
5c59075
scripts: Fix output
Luni-4 Aug 12, 2023
fae6066
scripts: Print colored output for all commands
Luni-4 Aug 12, 2023
8e6fab2
scripts: Remove unused println
Luni-4 Aug 12, 2023
00a0120
scripts: Add a shell script for Unix systems
Luni-4 Aug 14, 2023
624597d
scripts: Add a shell script for Windows
Luni-4 Aug 14, 2023
8e96e51
ci: Simplify scripts
Luni-4 Aug 14, 2023
0695137
Update README
Luni-4 Aug 14, 2023
6a08e8e
ci: Missing directory
Luni-4 Aug 14, 2023
6dab9c5
Use bash
Luni-4 Aug 14, 2023
62d787e
scripts: Set all as default value
Luni-4 Aug 14, 2023
223f6cb
ci: Define a new message for pull_request template
Luni-4 Aug 14, 2023
b62511c
scripts: Use spawn and child process to run commands
Luni-4 Aug 14, 2023
d2c7baf
Remove all option
Luni-4 Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Checklist

- [ ] Confirm that `run-checks.sh` has been executed.
- [ ] Confirm that `run-checks` script has been executed.

### Related Issues/PRs

Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ Cargo.lock
.cargo/config.toml

.idea
.vscode
.vscode

# Ignore binaries contained in the `scripts` directory
scripts/publish
scripts/run-checks
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,30 @@ recommended to read our
[architecture document](https://github.com/burn-rs/burn/tree/main/ARCHITECTURE.md), which explains
our architectural decisions. Please see more details in our [contributing guide](/CONTRIBUTING.md).

## CI
## Continuous Integration

### Run checks

On Unix systems, run `run-checks.sh` using this command

```
run-checks.sh environment
```

On Windows systems, run `run-checks.ps1` using this command:

```
run-checks.ps1 environment
```

The `environment` argument can assume **ONLY** the following values:

- `std` to perform checks using `libstd`
- `no_std` to perform checks on an embedded environment using `libcore`

If no `environment` value has been passed, run both `std` and `no_std` checks.

## Continuous Deployment

### Publish crates

Expand All @@ -295,6 +318,15 @@ Compile `scripts/publish.rs` using this command:
rustc scripts/publish.rs --crate-type bin --out-dir scripts
```

Run `scripts/publish` using this command

```
./scripts/publish crate_name
```

where `crate_name` is the name of the crate to publish


## Disclaimer

Burn is currently in active development, and there will be breaking changes. While any resulting
Expand Down
20 changes: 20 additions & 0 deletions run-checks.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This script runs all `burn` checks locally
#
# Run `run-checks` using this command:
#
# ./scripts/run-checks environment
#
# where `environment` can assume **ONLY** the following values:
#
# - `std` to perform checks using `libstd`
# - `no_std` to perform checks on an embedded environment using `libcore`
#
# If no `environment` value has been passed, run both `std` and `no_std` checks.

# Compile run-checks binary
rustc scripts/run-checks.rs --crate-type bin --out-dir scripts

# Run binary passing the first input parameter, who is mandatory.
# If the input parameter is missing or wrong, it will be the `run-checks`
# binary which will be responsible of arising an error.
./scripts/run-checks $args[0]
164 changes: 21 additions & 143 deletions run-checks.sh
Original file line number Diff line number Diff line change
@@ -1,144 +1,22 @@
#!/bin/bash

# This script is run before a PR is created.
# It is used to check that the code compiles and passes all tests.
# It is also used to check that the code is formatted correctly and passes clippy.

# Usage: ./run-checks.sh {all|no_std|std} (default: all)

# Exit immediately if a command exits with a non-zero status.
set -euo pipefail

# Function to handle errors
error_handler() {
local exit_status=$?
local line_number=$1
local command=$2

echo "Error on line $line_number"
echo "Command '$command' exited with status $exit_status"
}

# Signal trap to call error_handler when a command fails
trap 'error_handler $LINENO $BASH_COMMAND' ERR

# Function to build and test no_std
build_and_test_no_std() {
local dir=$1

echo "$dir"
cd $dir || exit

echo "Build without defaults"
cargo build --no-default-features

echo "Test without defaults"
cargo test --no-default-features

echo "Build for WebAssembly"
cargo build --no-default-features --target wasm32-unknown-unknown

echo "Build for ARM"
cargo build --no-default-features --target thumbv7m-none-eabi

cd .. || exit
}

# Function to build and test all features
build_and_test_all_features() {
local dir=$1

echo "$dir"
cd $dir || exit

echo "Build with all defaults"
cargo build --all-features

echo "Test with all features"
cargo test --all-features

echo "Check documentation with all features"
cargo doc --all-features

cd .. || exit
}

# Set RUSTDOCFLAGS to treat warnings as errors for the documentation build
export RUSTDOCFLAGS="-D warnings"

# Run the checks for std and all features with std
std_func() {
echo "Running std checks"

cargo build --workspace
cargo test --workspace
cargo fmt --check --all
cargo clippy -- -D warnings
cargo doc --workspace

# all features
echo "Running all-features checks"
build_and_test_all_features "burn-dataset"

cd burn-core || exit

echo "Test burn-core with tch backend"
cargo test --features test-tch

echo "Test burn-core with wgpu backend"
cargo test --features test-wgpu

cd .. || exit
}

# Run the checks for no_std
no_std_func() {
echo "Running no_std checks"

# Add wasm32 target for compiler.
rustup target add wasm32-unknown-unknown
rustup target add thumbv7m-none-eabi

build_and_test_no_std "burn"
build_and_test_no_std "burn-core"
build_and_test_no_std "burn-common"
build_and_test_no_std "burn-tensor"
build_and_test_no_std "burn-ndarray"
build_and_test_no_std "burn-no-std-tests"
}

# Save the script start time
start_time=$(date +%s)

# If no arguments were supplied or if it's empty, set the default as 'all'
if [ -z "${1-}" ]; then
arg="all"
else
arg=$1
fi

# Check the argument and call the appropriate functions
case $arg in
all)
no_std_func
std_func
;;
no_std)
no_std_func
;;
std)
std_func
;;
*)
echo "Error: Invalid argument"
echo "Usage: $0 {all|no_std|std}"
exit 1
;;
esac

# Calculate and print the script execution time
end_time=$(date +%s)
execution_time=$((end_time - start_time))
echo "Script executed in $execution_time seconds."

exit 0
#
# This script runs all `burn` checks locally
#
# Run `run-checks` using this command:
#
# ./scripts/run-checks environment
#
# where `environment` can assume **ONLY** the following values:
#
# - `std` to perform checks using `libstd`
# - `no_std` to perform checks on an embedded environment using `libcore`
#
# If no `environment` value has been passed, run both `std` and `no_std` checks.

# Compile run-checks binary
rustc scripts/run-checks.rs --crate-type bin --out-dir scripts

# Run binary passing the first input parameter, who is mandatory.
# If the input parameter is missing or wrong, it will be the `run-checks`
# binary which will be responsible of arising an error.
./scripts/run-checks $1
Loading