stages:
  - lint
  - build
  - test
  - deploy

eslint client:
  stage: lint
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      changes:
        - packages/client/src/**/*
  image: node:23-alpine
  script:
    - npm i --include=dev
    - npm -w packages/client run lint
  artifacts:
    reports:
      codequality: packages/client/gl-codequality.json

eslint server:
  stage: lint
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      changes:
        - packages/server/src/**/*
  image: node:23-alpine
  script:
    - npm i --include=dev
    - npm -w packages/server run lint
  artifacts:
    reports:
      codequality: packages/server/gl-codequality.json

jest server:
  stage: test
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      changes:
        - packages/server/src/**/*
  image: node:23-alpine
  services:
    - name: postgres:14-alpine
      alias: postgres
      variables:
        POSTGRES_DB: canvas
        POSTGRES_USER: canvas
        POSTGRES_PASSWORD: canvas
        POSTGRES_HOST_AUTH_METHOD: trust
  variables:
    DATABASE_URL: postgres://canvas@postgres/canvas
  script:
    - npm i --include=dev
    - npx -w packages/server prisma migrate reset --force
    - npm -w packages/server run test:ci

build wiki:
  stage: build
  trigger:
    include: .gitlab/ci/wiki.yml
  allow_failure: true
  rules:
    - if: $CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

deploy:
  stage: deploy
  trigger:
    include: .gitlab/ci/deploy.yml
  allow_failure: true
  rules:
    - if: $CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
