image: registry.gitlab.tugraz.at/dbp/esign/signature/main:v1

cache:
  key: $CI_PROJECT_PATH
  paths:
    - _yarn_cache

before_script:
  - 'git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.tugraz.at/".insteadOf "git@gitlab.tugraz.at:"'
  - git submodule sync
  - git submodule update --init
  - yarn config set cache-folder "$CI_PROJECT_DIR/_yarn_cache"

stages:
  - test
  - deploy
  - e2e

test:
  stage: test
  script:
    - yarn install
    - APP_ENV=development yarn run build
    - yarn run test-full

linting:
  stage: test
  allow_failure: true
  script:
    - yarn install
    - yarn run lint

publish:
  stage: deploy
  only:
    refs:
      - master
  script:
    # https://www.npmjs.com/settings/dbp-deploy/tokens
    # NPM_TOKEN needs to be a "Publish" token with 2FA disabled!
    - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > ~/.npmrc
    - yarn install
    - yarn run build
    # yarn always reports "https://registry.yarnpkg.com/@dbp-topics%2fsignature - Not found", so we are using npm directly
    - npm run publish

deploy:
  stage: deploy
  except:
    - schedules
  only:
    refs:
      - master
      - demo
      - production
  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
