# SPDX-FileCopyrightText: 2019-2022 Pleroma Authors <https://pleroma.social>
# SPDX-License-Identifier: AGPL-3.0-only

image: node:16-alpine

variables: &global_variables
  DOCKER_DRIVER: overlay2
  DOCKER_HOST: unix:///var/run/docker.sock

cache: &global_cache_policy
  key: '$CI_COMMIT_SHORT_SHA'
  policy: pull-push
  paths:
    - node_modules/
    - build

stages:
  - build
  - test

build:
  stage: build
  before_script: &before-build
    - apk --no-cache add git python3 build-base
  script:
    - yarn
    - yarn build:prod
  artifacts: &release-artifacts
    name: "admin-fe-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA"
    paths:
      - dist/

lint:
  stage: test
  before_script: &before-yarn
    - apk --no-cache add git python3 build-base
    - yarn
  cache:
    key: '$CI_COMMIT_SHORT_SHA'
    policy: pull
  script:
    - yarn lint

test:
  stage: test
  before_script: *before-yarn
  cache:
    key: '$CI_COMMIT_SHORT_SHA'
    policy: pull
  script:
    - yarn test --coverage
  coverage: '/^Lines *: *([^ ]*%) [^%]*$/'
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: coverage/clover.xml