stages:
  - test-and-build
  - build-docker
  - deploy
  - ailab

variables:
  GIT_DEPTH: 1

test:
  stage: test-and-build
  when: manual
  except:
    - main
  tags:
    - ailab
  script:
    - make opencv -j$(nproc --ignore=2)
    - make test

build-web:
  stage: test-and-build
  except:
    - main
  tags:
    - ailab
  before_script:
    - export PATH="/home/fam/.nvm/versions/node/v16.20.2/bin:$PATH"
    - (cd web; npm install)
  script:
    - make web
  artifacts:
    paths:
      - build

build-docker:
  stage: build-docker
  except:
    - main
  tags:
    - ailab
  script:
    - make docker-build
    - make docker-push
    - make docker-push-prod
  dependencies:
    - build-web
  except:
    - main

deploy-dev:
  stage: deploy
  except:
    - main
  tags:
    - ed2
  script:
    - make deploy-api-dev
  cache: []
  dependencies: []

dev-smoke:
  stage: test-and-build
  when: manual
  tags:
    - ailab
  allow_failure: true
  script:
    - ./scripts/emcli --env dev activate 0074253255108
    - ./api/scripts/api_smoke.py -p $EMBLEM_CI_PASSWORD
  cache: []

deploy-prod:
  stage: deploy
  tags:
    - ed2
  only:
    - main
  script:
    - make deploy-api-prod
  cache: []
  dependencies: []

ailab:
  stage: ailab
  when: manual
  tags:
    - ailab
  timeout: 36000 seconds
  before_script:
    - test -d $HOME/venv || python3 -m venv $HOME/venv
    - source $HOME/venv/bin/activate
    - pip install uv --index-url https://pypi.tuna.tsinghua.edu.cn/simple
    - export PATH="$HOME/venv/bin:$HOME/.local/bin:$PATH"
    - $HOME/venv/bin/uv venv --python /usr/bin/python3 venv
    - source venv/bin/activate
    - export PATH="$HOME/venv/bin:$PATH"
    - uv pip install -r requirements.txt --default-index https://pypi.tuna.tsinghua.edu.cn/simple
  script:
    - source venv/bin/activate
    - export PATH="$HOME/venv/bin:$PATH"
    - export DATA_DIR=$HOME/emblem
    - make fetch
    - make sbs
    - make train