Skip to content

Add CI for Rust code #2

Add CI for Rust code

Add CI for Rust code #2

Workflow file for this run

name: Rust
on:
push:
branches:
- main
pull_request:
jobs:
test:
name: Run Rust Tests
runs-on: ubuntu-latest
steps:
# Checkout the code
- name: Checkout Code
uses: actions/checkout@v4
# Set up Rust toolchain.
# This will be overwritten anyway by a `rust-toolchain.toml`
# file.
- name: Setup Rust Toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: rustfmt
# Run rustfmt and confirm no changes for each `blog/*/code` directory
- name: Check Formatting
run: |
for dir in blog/*/code; do
if [ -f "$dir/Cargo.toml" ]; then
echo "Checking formatting in $dir"
(cd "$dir" && cargo fmt --check)
else
echo "Skipping $dir as it does not contain a Cargo.toml file"
fi
done
# Run tests for each `blog/*/code` directory
- name: Build and Test
run: |
for dir in blog/*/code; do
if [ -f "$dir/Cargo.toml" ]; then
cd "$dir";
echo "Running build in $dir"
cargo build --release
echo "Running tests in $dir"
cargo test --release
else
echo "Skipping $dir as it does not contain a Cargo.toml file"
fi
done