image: registry.gitlab.tugraz.at/dbp/web-components/toolkit/main:v2

cache:
  key: ${CI_PROJECT_PATH}
  paths:
    - _yarn_cache
    - _playwright_cache

variables:
  PLAYWRIGHT_BROWSERS_PATH: "$CI_PROJECT_DIR/_playwright_cache"

before_script:
  - yarn config set cache-folder "$CI_PROJECT_DIR/_yarn_cache"

stages:
  - test
  - deploy

test:
  stage: test
  script:
    - yarn install --frozen-lockfile
    - yarn run test

linting:
  stage: test
  script:
    - yarn install --frozen-lockfile
    - yarn run lint

publish:
  stage: deploy
  environment:
    name: deploy
    url: https://www.npmjs.com/search?q=%40dbp-toolkit
  only:
    refs:
      - master
  script:
    # https://www.npmjs.com/settings/dbp-deploy/tokens
    # NPM_TOKEN needs to be a "Publish" token with 2FA disabled!
    # "Automation" tokens don't work with lerna (even if they would work with "npm publish")
    - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > ~/.npmrc
    - yarn install --frozen-lockfile
    - yarn run build
    - yarn run publish

deploy:
  stage: deploy
  except:
    - schedules
  only:
    refs:
      - master
      - demo
  inherit:
    variables: false
  variables:
    UPSTREAM_PROJECT_PATH: ${CI_PROJECT_PATH}
    UPSTREAM_COMMIT_BRANCH: ${CI_COMMIT_BRANCH}
    UPSTREAM_COMMIT_SHA: ${CI_COMMIT_SHA}
  trigger:
    project: dbp/deployer
    strategy: depend