|
| 1 | +name: Rust |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + name: Run Rust Tests |
| 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 | + components: rustfmt |
| 28 | + |
| 29 | + # Install Rust toolchains for each `blog/*/code` directory |
| 30 | + - name: Installing Rust toolchains |
| 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 | + run: | |
| 44 | + for dir in blog/*/code; do |
| 45 | + if [ -f "$dir/Cargo.toml" ]; then |
| 46 | + echo "Checking formatting in $dir" |
| 47 | + (cd "$dir" && cargo fmt --check) |
| 48 | + else |
| 49 | + echo "Skipping $dir as it does not contain a Cargo.toml file" |
| 50 | + fi |
| 51 | + done |
| 52 | +
|
| 53 | + # Run builds tests for each `blog/*/code` directory |
| 54 | + - name: Build and Test |
| 55 | + run: | |
| 56 | + for dir in blog/*/code; do |
| 57 | + if [ -f "$dir/Cargo.toml" ]; then |
| 58 | + cd "$dir" |
| 59 | + echo "Running build in $dir" |
| 60 | + cargo build --release |
| 61 | + echo "Running tests in $dir" |
| 62 | + cargo test --release |
| 63 | + else |
| 64 | + echo "Skipping $dir as it does not contain a Cargo.toml file" |
| 65 | + fi |
| 66 | + done |
0 commit comments