stages:
  - lint
  - prettier
  - test
  - deploy
cache:
  paths:
    - ~/.cache

lint:commit:
  image: node:16.16.0-alpine
  stage: lint
  allow_failure: true
  before_script:
    - apk add --no-cache npm git
    - npm ci
  script:
    - echo "${CI_COMMIT_MESSAGE}" | npx commitlint

linter:
  image: node:16.16.0-alpine
  stage: lint
  before_script:
    - apk add --no-cache npm git
    - npm ci
  script:
    - npm run lint:ts
  only:
    - development
    - merge_requests
    - tags

prettier:
  image: node:16.16.0-alpine
  stage: prettier
  before_script:
    - apk add --no-cache npm git
    - npm ci
  script:
    - npm run prettier:ci
  only:
    - development
    - merge_requests
    - tags

jest:
  image: node:16.16.0-alpine
  stage: test
  coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
  before_script:
    - apk add --no-cache npm git
    - npm ci
  script:
    - npm run test:ci
  only:
    - development
    - merge_requests
    - tags
  artifacts:
    when: always
    reports:
      junit:
        - junit.xml
      coverage_report:
        coverage_format: cobertura
        path: coverage/cobertura-coverage.xml

deploy_staging:
  image: node:16.16.0
  stage: deploy
  only:
    - development
  script:
    - npm install --global vercel
    - vercel pull --yes --environment=production --token=$VERCEL_TOKEN
    - vercel build --prod --token=$VERCEL_TOKEN
    - vercel deploy --prebuilt --prod --token=$VERCEL_TOKEN
