name: Build and Lint on Pull Request

on:
  workflow_dispatch:
  pull_request:
    types: ["opened", "synchronize", "ready_for_review"]

jobs:
  lint-apiserver:
    if: github.event.pull_request.draft == false
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.x" # Specify the Python version you need
      - name: Install Pylint
        run: python -m pip install ruff
      - name: Install Apiserver Dependencies
        run: cd apiserver && pip install -r requirements.txt
      - name: Lint apiserver
        run: ruff check --fix apiserver

  lint-admin:
    if: github.event.pull_request.draft == false
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - run: yarn install
      - run: yarn lint --filter=admin

  lint-space:
    if: github.event.pull_request.draft == false
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - run: yarn install
      - run: yarn lint --filter=space

  lint-web:
    if: github.event.pull_request.draft == false
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - run: yarn install
      - run: yarn lint --filter=web

  build-admin:
    needs: lint-admin
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - run: yarn install
      - run: yarn build --filter=admin

  build-space:
    needs: lint-space
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - run: yarn install
      - run: yarn build --filter=space

  build-web:
    needs: lint-web
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - run: yarn install
      - run: yarn build --filter=web
