image: node:16

variables:
  GIT_STRATEGY: clone
  GIT_AUTHOR_NAME: Skunk Bot
  GIT_AUTHOR_EMAIL: skunkbot@goodgamestudios.com
  GIT_COMMITTER_NAME: Skunk Bot
  GIT_COMMITTER_EMAIL: skunkbot@goodgamestudios.com

stages:
  - staging
  - production
  - synchronize

cache:
  key:
    files:
      - package-lock.json
  paths:
    - node_modules/

before_script:
  - npm ci --cache node_modules --prefer-offline

publish-to-qa:
  stage: staging
  tags:
    - cxf
  script:
    - npm run build:qa
    - npm run release
  only:
    - develop

publish-to-production:
  stage: production
  tags:
    - cxf
  script:
    - npm run build:live
    - npm run release
  only:
    - master

merge-master-to-develop:
  stage: synchronize
  tags:
    - cxf
  script:
    - git fetch
    - git checkout -b develop --track origin/develop
    - git merge origin/master
    - git push https://gitlab-ci-token:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git HEAD:develop
  only:
    - master
