Skip to content

Commit 76a9586

Browse files
committed
Add CI for Rust code
1 parent 63250fd commit 76a9586

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

.github/workflows/rust.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
name: Works on ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-latest, windows-latest]
15+
runs-on: ${{ matrix.os }}
16+
17+
steps:
18+
# Checkout the code
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
# Set up Rust toolchain
23+
- name: Setup Rust toolchain
24+
uses: actions-rust-lang/setup-rust-toolchain@v1
25+
with:
26+
toolchain: stable
27+
28+
# Install Rust toolchains for each `blog/*/code` directory
29+
- name: Installing specific Rust toolchains
30+
shell: bash
31+
run: |
32+
for dir in blog/*/code; do
33+
if [ -f "$dir/Cargo.toml" ]; then
34+
echo "Installing toolchain for $dir"
35+
(cd "$dir" && cargo version)
36+
else
37+
echo "Skipping $dir as it does not contain a Cargo.toml file"
38+
fi
39+
done
40+
41+
# Run rustfmt and confirm no changes for each `blog/*/code` directory
42+
- name: Check formatting
43+
shell: bash
44+
run: |
45+
for dir in blog/*/code; do
46+
if [ -f "$dir/Cargo.toml" ]; then
47+
echo "Checking formatting in $dir"
48+
(cd "$dir" && cargo fmt --check)
49+
else
50+
echo "Skipping $dir as it does not contain a Cargo.toml file"
51+
fi
52+
done
53+
54+
# Run builds and tests for each `blog/*/code` directory
55+
- name: Build and test
56+
shell: bash
57+
run: |
58+
for dir in blog/*/code; do
59+
if [ -f "$dir/Cargo.toml" ]; then
60+
cd "$dir"
61+
echo "Running build in $dir"
62+
cargo build --release
63+
echo "Running tests in $dir"
64+
cargo test --release
65+
else
66+
echo "Skipping $dir as it does not co

0 commit comments

Comments
 (0)