name: Backend only integration tests

on:
  push:
    branches:
      - "main"
    paths:
      - "backend/**"
      - ".github/workflows/backend-test.yml"
  pull_request:
    types: [opened, synchronize, reopened]
    paths:
      - "backend/**"
      - ".github/workflows/backend-test.yml"

defaults:
  run:
    working-directory: ./backend

jobs:
  cargo_test:
    runs-on: ubicloud-standard-8
    services:
      postgres:
        image: postgres
        ports:
          - 5432:5432
        env:
          POSTGRES_DB: windmill
          POSTGRES_PASSWORD: changeme
        options: >-
          --health-cmd pg_isready --health-interval 10s --health-timeout 5s
          --health-retries 5
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: "9.0.x"
      - uses: denoland/setup-deno@v2
        with:
          deno-version: v2.x
      - uses: actions/setup-go@v2
        with:
          go-version: 1.21.5
      - uses: actions/setup-python@v2
        with:
          python-version: 3.11
      - uses: oven-sh/setup-bun@v2
        with:
          bun-version: 1.1.40
      - uses: astral-sh/setup-uv@v4
        with:
          version: "0.4.18"
      - uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          cache-workspaces: backend
          toolchain: 1.82.0
      - uses: Swatinem/rust-cache@v2
        with:
          workspaces: backend
      - name: cargo test
        timeout-minutes: 16
        run:
          deno --version && bun -v && go version && python3 --version &&
          SQLX_OFFLINE=true
          DATABASE_URL=postgres://postgres:changeme@localhost:5432/windmill
          DISABLE_EMBEDDING=true RUST_LOG=info PYTHON_PATH=$(which python)
          DENO_PATH=$(which deno) BUN_PATH=$(which bun) GO_PATH=$(which go)
          UV_PATH=$(which uv) cargo test --features
          enterprise,deno_core,license,python,rust,scoped_cache --all -- --nocapture
