diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml new file mode 100644 index 0000000..e5be2af --- /dev/null +++ b/.github/workflows/rust.yaml @@ -0,0 +1,53 @@ +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