Skip to content

Add CI for Rust code #43

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

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Changes from all commits
Commits
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
68 changes: 68 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Rust

on:
push:
branches:
- main
pull_request:

jobs:
test:
name: Works on ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}

steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v4

# Set up Rust toolchain
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable

# Install Rust toolchains for each `blog/*/code` directory
- name: Installing specific Rust toolchains
shell: bash
run: |
for dir in blog/*/code; do
if [ -f "$dir/Cargo.toml" ]; then
echo "Installing toolchain for $dir"
(cd "$dir" && cargo version)
else
echo "Skipping $dir as it does not contain a Cargo.toml file"
fi
done

# Run rustfmt and confirm no changes for each `blog/*/code` directory
- name: Check formatting
shell: bash
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 builds and tests for each `blog/*/code` directory
- name: Build and test
shell: bash
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