|
| 1 | +name: "Check Backend on Pull Request" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + - main |
| 8 | + paths: |
| 9 | + - "backend/**/*.rs" |
| 10 | + - "backend/**/Cargo.toml" |
| 11 | + - "backend/**/Cargo.lock" |
| 12 | + - "backend/rust-toolchain.toml" |
| 13 | + - "backend/rustfmt.toml" |
| 14 | + - ".github/workflows/*.yml" |
| 15 | + push: |
| 16 | + branches: |
| 17 | + - develop |
| 18 | + |
| 19 | +# Ensures only one build is run per branch, unless pushing to develop |
| 20 | +concurrency: |
| 21 | + group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/develop' && github.run_number || github.ref }} |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +env: |
| 25 | + CARGO_ARGS: ${{ github.ref == 'refs/heads/develop' && '--release' || '' }} |
| 26 | + CARGO_TERM_COLOR: always |
| 27 | + SKIP_WASM_BUILD: 1 |
| 28 | + RUST_NIGHTLY_VERSION: 2024-11-19 |
| 29 | + |
| 30 | +defaults: |
| 31 | + run: |
| 32 | + working-directory: "backend" |
| 33 | + |
| 34 | +jobs: |
| 35 | + fmt: |
| 36 | + if: ${{ !startsWith(github.head_ref, 'release/') }} |
| 37 | + name: Rustfmt |
| 38 | + runs-on: ubuntu-latest |
| 39 | + continue-on-error: false |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Install nightly toolchain |
| 44 | + uses: dtolnay/rust-toolchain@master |
| 45 | + with: |
| 46 | + targets: "wasm32-unknown-unknown" |
| 47 | + components: "rustfmt" |
| 48 | + toolchain: "nightly-${{env.RUST_NIGHTLY_VERSION}}" |
| 49 | + |
| 50 | + # some settings are only available in nightly. |
| 51 | + - run: cargo +nightly-$RUST_NIGHTLY_VERSION fmt --all -- --check |
| 52 | + |
| 53 | + lint: |
| 54 | + if: ${{ !startsWith(github.head_ref, 'release/') }} |
| 55 | + name: Clippy |
| 56 | + runs-on: ubuntu-latest |
| 57 | + continue-on-error: false |
| 58 | + steps: |
| 59 | + - uses: actions/checkout@v4 |
| 60 | + - run: ./../.github/scripts/free_disk_space.sh |
| 61 | + - run: sudo apt-get install -y protobuf-compiler |
| 62 | + - uses: actions/cache@v4 |
| 63 | + with: |
| 64 | + path: | |
| 65 | + ~/.cargo/bin/ |
| 66 | + ~/.cargo/registry/index/ |
| 67 | + ~/.cargo/registry/cache/ |
| 68 | + ~/.cargo/git/db/ |
| 69 | + target/ |
| 70 | + key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }} |
| 71 | + restore-keys: ${{ runner.os }}-cargo-lint- |
| 72 | + - run: cargo clippy --all-features --all-targets ${{ env.CARGO_ARGS }} -- -D warnings |
| 73 | + |
| 74 | + test: |
| 75 | + if: ${{ !startsWith(github.head_ref, 'release/') }} |
| 76 | + name: Test |
| 77 | + runs-on: ubuntu-latest |
| 78 | + continue-on-error: false |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v4 |
| 81 | + - run: ./../.github/scripts/free_disk_space.sh |
| 82 | + - run: sudo apt-get install -y protobuf-compiler |
| 83 | + - uses: actions/cache@v4 |
| 84 | + with: |
| 85 | + path: | |
| 86 | + ~/.cargo/bin/ |
| 87 | + ~/.cargo/registry/index/ |
| 88 | + ~/.cargo/registry/cache/ |
| 89 | + ~/.cargo/git/db/ |
| 90 | + target/ |
| 91 | + key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }} |
| 92 | + restore-keys: ${{ runner.os }}-cargo-test- |
| 93 | + - run: cargo test --all-features --all-targets ${{ env.CARGO_ARGS }} |
| 94 | + |
| 95 | + check-wasm: |
| 96 | + if: ${{ !startsWith(github.head_ref, 'release/') }} |
| 97 | + name: Check WASM build |
| 98 | + runs-on: ubuntu-latest |
| 99 | + continue-on-error: false |
| 100 | + steps: |
| 101 | + - uses: actions/checkout@v4 |
| 102 | + - run: ./../.github/scripts/free_disk_space.sh |
| 103 | + - run: sudo apt-get install -y protobuf-compiler |
| 104 | + - uses: actions/cache@v4 |
| 105 | + with: |
| 106 | + path: | |
| 107 | + ~/backend/.cargo/bin/ |
| 108 | + ~/backend/.cargo/registry/index/ |
| 109 | + ~/backend/.cargo/registry/cache/ |
| 110 | + ~/backend/.cargo/git/db/ |
| 111 | + ~/backend/target/ |
| 112 | + key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }} |
| 113 | + restore-keys: ${{ runner.os }}-cargo-lint- |
| 114 | + - run: ./scripts/run_for_all_no_std_crates.sh check --no-default-features --target=wasm32-unknown-unknown |
0 commit comments