Merge pull request #115 from codervisor/copilot/implement-spec-193 #56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: API Contract Tests | |
| on: | |
| push: | |
| pull_request: | |
| jobs: | |
| contract-tests: | |
| name: Contract Tests (${{ matrix.target }}) | |
| runs-on: ubuntu-latest | |
| continue-on-error: ${{ matrix.target == 'next' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: [rust, next] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: pnpm | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build Rust HTTP server | |
| if: matrix.target == 'rust' | |
| run: | | |
| cd rust | |
| cargo build --release --bin leanspec-http | |
| - name: Start Rust HTTP server | |
| if: matrix.target == 'rust' | |
| run: | | |
| nohup ./rust/target/release/leanspec-http --port 3001 >/tmp/leanspec-http.log 2>&1 & | |
| - name: Start Next.js server | |
| if: matrix.target == 'next' | |
| run: | | |
| pnpm --filter @leanspec/ui dev -- --hostname 0.0.0.0 --port 3000 >/tmp/next.log 2>&1 & | |
| - name: Wait for server | |
| run: | | |
| TARGET=${{ matrix.target }} | |
| URL=http://localhost:3001/health | |
| if [ "$TARGET" = "next" ]; then URL=http://localhost:3000/api/projects; fi | |
| for i in {1..40}; do | |
| if curl -sf "$URL" >/dev/null; then exit 0; fi | |
| sleep 1 | |
| done | |
| echo "Server did not start" && exit 1 | |
| - name: Run contract tests | |
| env: | |
| API_BASE_URL: ${{ matrix.target == 'rust' && 'http://localhost:3001' || 'http://localhost:3000' }} | |
| run: pnpm -C tests/api test | |
| - name: Upload server logs on failure | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: api-contract-logs-${{ matrix.target }} | |
| path: | | |
| /tmp/leanspec-http.log | |
| /tmp/next.log |