on:
  push:
  pull_request:
  workflow_call:
    inputs:
      ref:
        type: "string"
        required: true
        description: "The ref (branch or tag) to build"

jobs:

  build-frontend:
    name: "Build frontend"
    runs-on: "ubuntu-latest"
    steps:
      - uses: "actions/checkout@v4"
        with:
          ref: "${{ inputs.ref }}"
      - uses: "actions/setup-node@v4"
        with:
          cache: "yarn"
      - run: "yarn install"
      - run: "yarn build"
      - uses: "actions/upload-artifact@v4"
        with:
          name: "frontend"
          path: "dist"
          retention-days: 5

  build-backend:
    name: "Build backend"
    runs-on: "ubuntu-latest"
    steps:
      - uses: "actions/checkout@v4"
        with:
          ref: "${{ inputs.ref }}"
      - run: "pipx install poetry"
      - uses: "actions/setup-python@v5"
        with:
          python-version: "3.12"
          cache: "poetry"
      - run: "SKIP_BUILD_FRONTEND=true poetry lock"
      - run: "SKIP_BUILD_FRONTEND=true poetry install"
      - run: "SKIP_BUILD_FRONTEND=true poetry build"

  build-logo:
    name: "Build logo"
    runs-on: "ubuntu-latest"
    steps:
      - uses: "actions/checkout@v4"
        with:
          ref: "${{ inputs.ref }}"
      - run: "pipx install poetry"
      - uses: "actions/setup-python@v5"
        with:
          python-version: "3.12"
          cache: "poetry"
      - run: "SKIP_BUILD_FRONTEND=true poetry lock"
      - run: "SKIP_BUILD_FRONTEND=true poetry install"
      - run: "poetry run python yacv_server/logo.py"
      - uses: "actions/upload-artifact@v4"
        with:
          name: "logo"
          path: "assets/logo_build"
          retention-days: 5

  build-example:
    name: "Build example"
    runs-on: "ubuntu-latest"
    steps:
      - uses: "actions/checkout@v4"
        with:
          ref: "${{ inputs.ref }}"
      - run: "pipx install poetry"
      - uses: "actions/setup-python@v5"
        with:
          python-version: "3.12"
          cache: "poetry"
      - run: "SKIP_BUILD_FRONTEND=true poetry lock"
      - run: "SKIP_BUILD_FRONTEND=true poetry install"
      - run: "YACV_DISABLE_SERVER=true poetry run python example/object.py"
      - uses: "actions/upload-artifact@v4"
        with:
          name: "example"
          path: "export"
          retention-days: 5