|
| 1 | +name: Rust Services CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + paths: |
| 7 | + - 'rust-services/**' |
| 8 | + - '.github/workflows/rust-services.yml' |
| 9 | + pull_request: |
| 10 | + branches: [main, develop] |
| 11 | + paths: |
| 12 | + - 'rust-services/**' |
| 13 | + - '.github/workflows/rust-services.yml' |
| 14 | + |
| 15 | +env: |
| 16 | + CARGO_TERM_COLOR: always |
| 17 | + RUST_BACKTRACE: 1 |
| 18 | + |
| 19 | +jobs: |
| 20 | + check: |
| 21 | + name: Check |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Install Rust toolchain |
| 27 | + uses: dtolnay/rust-action@stable |
| 28 | + with: |
| 29 | + components: clippy, rustfmt |
| 30 | + |
| 31 | + - name: Cache cargo |
| 32 | + uses: actions/cache@v4 |
| 33 | + with: |
| 34 | + path: | |
| 35 | + ~/.cargo/bin/ |
| 36 | + ~/.cargo/registry/index/ |
| 37 | + ~/.cargo/registry/cache/ |
| 38 | + ~/.cargo/git/db/ |
| 39 | + rust-services/target/ |
| 40 | + key: ${{ runner.os }}-cargo-${{ hashFiles('rust-services/**/Cargo.lock') }} |
| 41 | + restore-keys: | |
| 42 | + ${{ runner.os }}-cargo- |
| 43 | + |
| 44 | + - name: Check formatting |
| 45 | + working-directory: rust-services |
| 46 | + run: cargo fmt --all -- --check |
| 47 | + |
| 48 | + - name: Clippy |
| 49 | + working-directory: rust-services |
| 50 | + run: cargo clippy --all-targets --all-features -- -D warnings |
| 51 | + |
| 52 | + - name: Check |
| 53 | + working-directory: rust-services |
| 54 | + run: cargo check --all-targets |
| 55 | + |
| 56 | + test: |
| 57 | + name: Test |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: check |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v4 |
| 62 | + |
| 63 | + - name: Install Rust toolchain |
| 64 | + uses: dtolnay/rust-action@stable |
| 65 | + |
| 66 | + - name: Cache cargo |
| 67 | + uses: actions/cache@v4 |
| 68 | + with: |
| 69 | + path: | |
| 70 | + ~/.cargo/bin/ |
| 71 | + ~/.cargo/registry/index/ |
| 72 | + ~/.cargo/registry/cache/ |
| 73 | + ~/.cargo/git/db/ |
| 74 | + rust-services/target/ |
| 75 | + key: ${{ runner.os }}-cargo-${{ hashFiles('rust-services/**/Cargo.lock') }} |
| 76 | + |
| 77 | + - name: Run tests |
| 78 | + working-directory: rust-services |
| 79 | + run: cargo test --all-features --verbose |
| 80 | + |
| 81 | + benchmark: |
| 82 | + name: Benchmark |
| 83 | + runs-on: ubuntu-latest |
| 84 | + needs: test |
| 85 | + steps: |
| 86 | + - uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: Install Rust toolchain |
| 89 | + uses: dtolnay/rust-action@stable |
| 90 | + |
| 91 | + - name: Cache cargo |
| 92 | + uses: actions/cache@v4 |
| 93 | + with: |
| 94 | + path: | |
| 95 | + ~/.cargo/bin/ |
| 96 | + ~/.cargo/registry/index/ |
| 97 | + ~/.cargo/registry/cache/ |
| 98 | + ~/.cargo/git/db/ |
| 99 | + rust-services/target/ |
| 100 | + key: ${{ runner.os }}-cargo-${{ hashFiles('rust-services/**/Cargo.lock') }} |
| 101 | + |
| 102 | + - name: Run benchmarks |
| 103 | + working-directory: rust-services |
| 104 | + run: cargo bench --package benchmarks -- --noplot |
| 105 | + |
| 106 | + - name: Upload benchmark results |
| 107 | + uses: actions/upload-artifact@v4 |
| 108 | + with: |
| 109 | + name: benchmark-results |
| 110 | + path: rust-services/target/criterion/ |
| 111 | + |
| 112 | + build: |
| 113 | + name: Build |
| 114 | + runs-on: ubuntu-latest |
| 115 | + needs: test |
| 116 | + strategy: |
| 117 | + matrix: |
| 118 | + service: [shape-validator, realtime-sync, render-service] |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@v4 |
| 121 | + |
| 122 | + - name: Install Rust toolchain |
| 123 | + uses: dtolnay/rust-action@stable |
| 124 | + |
| 125 | + - name: Cache cargo |
| 126 | + uses: actions/cache@v4 |
| 127 | + with: |
| 128 | + path: | |
| 129 | + ~/.cargo/bin/ |
| 130 | + ~/.cargo/registry/index/ |
| 131 | + ~/.cargo/registry/cache/ |
| 132 | + ~/.cargo/git/db/ |
| 133 | + rust-services/target/ |
| 134 | + key: ${{ runner.os }}-cargo-${{ hashFiles('rust-services/**/Cargo.lock') }} |
| 135 | + |
| 136 | + - name: Build release |
| 137 | + working-directory: rust-services |
| 138 | + run: cargo build --release --package ${{ matrix.service }} |
| 139 | + |
| 140 | + - name: Upload binary |
| 141 | + uses: actions/upload-artifact@v4 |
| 142 | + with: |
| 143 | + name: ${{ matrix.service }}-linux-amd64 |
| 144 | + path: rust-services/target/release/${{ matrix.service }} |
| 145 | + |
| 146 | + docker: |
| 147 | + name: Docker Build |
| 148 | + runs-on: ubuntu-latest |
| 149 | + needs: build |
| 150 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 151 | + strategy: |
| 152 | + matrix: |
| 153 | + service: [shape-validator, realtime-sync, render-service] |
| 154 | + steps: |
| 155 | + - uses: actions/checkout@v4 |
| 156 | + |
| 157 | + - name: Set up Docker Buildx |
| 158 | + uses: docker/setup-buildx-action@v3 |
| 159 | + |
| 160 | + - name: Login to Docker Hub |
| 161 | + uses: docker/login-action@v3 |
| 162 | + with: |
| 163 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 164 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 165 | + |
| 166 | + - name: Build and push |
| 167 | + uses: docker/build-push-action@v5 |
| 168 | + with: |
| 169 | + context: rust-services |
| 170 | + file: rust-services/${{ matrix.service }}/Dockerfile |
| 171 | + push: true |
| 172 | + tags: | |
| 173 | + devstroop/penpot-${{ matrix.service }}:latest |
| 174 | + devstroop/penpot-${{ matrix.service }}:${{ github.sha }} |
| 175 | + cache-from: type=gha |
| 176 | + cache-to: type=gha,mode=max |
0 commit comments