Skip to content

Commit

Permalink
Add CI for Rust code
Browse files Browse the repository at this point in the history
  • Loading branch information
LegNeato committed Nov 23, 2024
1 parent 63250fd commit 9c9be05
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9c9be05

Please sign in to comment.