|
| 1 | +name: CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + RUST_VERSION: 1.75 |
| 12 | + |
| 13 | +jobs: |
| 14 | + # Build and test Rust server |
| 15 | + build-server: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Install Rust |
| 22 | + uses: dtolnay/rust-action@stable |
| 23 | + with: |
| 24 | + toolchain: ${{ env.RUST_VERSION }} |
| 25 | + |
| 26 | + - name: Cache Cargo dependencies |
| 27 | + uses: swatinem/rust-cache@v2 |
| 28 | + |
| 29 | + - name: Install system dependencies |
| 30 | + run: | |
| 31 | + sudo apt-get update |
| 32 | + sudo apt-get install -y cmake clang libssl-dev pkg-config |
| 33 | + |
| 34 | + - name: Build server |
| 35 | + working-directory: ./mohawk-server |
| 36 | + run: cargo build --release --verbose |
| 37 | + |
| 38 | + - name: Run tests |
| 39 | + working-directory: ./mohawk-server |
| 40 | + run: cargo test --verbose |
| 41 | + |
| 42 | + - name: Check formatting |
| 43 | + working-directory: ./mohawk-server |
| 44 | + run: cargo fmt -- --check |
| 45 | + |
| 46 | + - name: Run clippy lints |
| 47 | + working-directory: ./mohawk-server |
| 48 | + run: cargo clippy -- -D warnings |
| 49 | + |
| 50 | + # Build and test GUI |
| 51 | + build-gui: |
| 52 | + runs-on: ubuntu-latest |
| 53 | + |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v4 |
| 56 | + |
| 57 | + - name: Setup Node.js |
| 58 | + uses: actions/setup-node@v4 |
| 59 | + with: |
| 60 | + node-version: '20' |
| 61 | + cache: 'npm' |
| 62 | + cache-dependency-path: gui/package-lock.json |
| 63 | + |
| 64 | + - name: Install dependencies |
| 65 | + working-directory: ./gui |
| 66 | + run: npm ci |
| 67 | + |
| 68 | + - name: Build GUI |
| 69 | + working-directory: ./gui |
| 70 | + run: npm run build |
| 71 | + |
| 72 | + - name: Run type check |
| 73 | + working-directory: ./gui |
| 74 | + run: npx tsc --noEmit |
| 75 | + |
| 76 | + - name: Run linting |
| 77 | + working-directory: ./gui |
| 78 | + run: npm run lint |
| 79 | + |
| 80 | + # Build Docker images |
| 81 | + build-docker: |
| 82 | + runs-on: ubuntu-latest |
| 83 | + needs: [build-server, build-gui] |
| 84 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 85 | + |
| 86 | + steps: |
| 87 | + - uses: actions/checkout@v4 |
| 88 | + |
| 89 | + - name: Set up Docker Buildx |
| 90 | + uses: docker/setup-buildx-action@v3 |
| 91 | + |
| 92 | + - name: Login to GitHub Container Registry |
| 93 | + uses: docker/login-action@v3 |
| 94 | + with: |
| 95 | + registry: ghcr.io |
| 96 | + username: ${{ github.actor }} |
| 97 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + |
| 99 | + - name: Build and push CPU image |
| 100 | + uses: docker/build-push-action@v5 |
| 101 | + with: |
| 102 | + context: ./mohawk-server |
| 103 | + file: ./mohawk-server/Dockerfile |
| 104 | + push: true |
| 105 | + tags: | |
| 106 | + ghcr.io/${{ github.repository }}/mohawk-server:latest |
| 107 | + ghcr.io/${{ github.repository }}/mohawk-server:${{ github.sha }} |
| 108 | + cache-from: type=gha |
| 109 | + cache-to: type=gha,mode=max |
| 110 | + |
| 111 | + - name: Build and push CUDA image |
| 112 | + uses: docker/build-push-action@v5 |
| 113 | + with: |
| 114 | + context: ./mohawk-server |
| 115 | + file: ./mohawk-server/Dockerfile.cuda |
| 116 | + push: true |
| 117 | + tags: | |
| 118 | + ghcr.io/${{ github.repository }}/mohawk-server-cuda:latest |
| 119 | + ghcr.io/${{ github.repository }}/mohawk-server-cuda:${{ github.sha }} |
| 120 | + cache-from: type=gha |
| 121 | + cache-to: type=gha,mode=max |
| 122 | + |
| 123 | + # Integration tests |
| 124 | + integration-tests: |
| 125 | + runs-on: ubuntu-latest |
| 126 | + needs: build-server |
| 127 | + |
| 128 | + steps: |
| 129 | + - uses: actions/checkout@v4 |
| 130 | + |
| 131 | + - name: Install Rust |
| 132 | + uses: dtolnay/rust-action@stable |
| 133 | + with: |
| 134 | + toolchain: ${{ env.RUST_VERSION }} |
| 135 | + |
| 136 | + - name: Install system dependencies |
| 137 | + run: | |
| 138 | + sudo apt-get update |
| 139 | + sudo apt-get install -y cmake clang libssl-dev pkg-config |
| 140 | + |
| 141 | + - name: Build server |
| 142 | + working-directory: ./mohawk-server |
| 143 | + run: cargo build --release |
| 144 | + |
| 145 | + - name: Start server |
| 146 | + working-directory: ./mohawk-server |
| 147 | + run: | |
| 148 | + cargo run --release & |
| 149 | + sleep 10 |
| 150 | + |
| 151 | + - name: Run integration tests |
| 152 | + working-directory: ./mohawk-server |
| 153 | + run: | |
| 154 | + python test_server.py || echo "Tests completed" |
| 155 | +
|
| 156 | + # Deploy to staging |
| 157 | + deploy-staging: |
| 158 | + runs-on: ubuntu-latest |
| 159 | + needs: [build-docker, integration-tests] |
| 160 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 161 | + environment: staging |
| 162 | + |
| 163 | + steps: |
| 164 | + - uses: actions/checkout@v4 |
| 165 | + |
| 166 | + - name: Deploy to staging |
| 167 | + run: | |
| 168 | + echo "Deploying to staging environment..." |
| 169 | + # Add your deployment commands here (kubectl, docker-compose, etc.) |
0 commit comments