image: node:10.14.2-stretch
stages: [setup, verify, deploy, trigger]
install:
  stage: setup
  cache:
    paths:
      - .cache/npm
  script:
    - &npm_install npm install --quiet --no-progress --cache=.cache/npm
lint:
  stage: verify
  cache: &pull_cache
    policy: pull
    paths:
      - .cache/npm
  script:
    - *npm_install
    - node_modules/.bin/gulp lint
bundle-stable:
  stage: deploy
  only:
    - master@swd/swlab-ui
  cache: *pull_cache
  script:
    - *npm_install
    - node_modules/.bin/gulp bundle
  artifacts:
    paths:
      - build/ui-bundle.zip
bundle-dev:
  stage: deploy
  except:
    - master
  cache: *pull_cache
  script:
    - *npm_install
    - node_modules/.bin/gulp bundle
  artifacts:
    expire_in: 1 day # unless marked as keep from job page
    paths:
      - build/ui-bundle.zip
pages:
  stage: deploy
  only:
    - master@swd/swlab-ui
  cache: *pull_cache
  script:
    - *npm_install
    - node_modules/.bin/gulp preview:build
    # FIXME figure out a way to avoid copying these files to preview site
    - rm -rf public/_/{helpers,layouts,partials}
  artifacts:
    paths:
      - public
trigger-swlab-docs:
  stage: trigger
  script:
    - >
      curl -X POST 
      -F token=$TRIGGER_SWLAB_DOCS
      -F ref=master 
      https://gitlab.bwg.co.kr/api/v4/projects/952/trigger/pipeline
    - >
      curl -X POST 
      -F token=$TRIGGER_SWLAB_DOCS_BXCM
      -F ref=master 
      https://gitlab.bwg.co.kr/api/v4/projects/972/trigger/pipeline
    - >
      curl -X POST 
      -F token=$TRIGGER_SWLAB_DOCS_BXCP
      -F ref=master 
      https://gitlab.bwg.co.kr/api/v4/projects/974/trigger/pipeline
    - >
      curl -X POST 
      -F token=$TRIGGER_SWLAB_DOCS_BXI
      -F ref=master 
      https://gitlab.bwg.co.kr/api/v4/projects/971/trigger/pipeline
    - >
      curl -X POST 
      -F token=$TRIGGER_SWLAB_DOCS_BXM
      -F ref=master 
      https://gitlab.bwg.co.kr/api/v4/projects/973/trigger/pipeline
    - >
      curl -X POST 
      -F token=$TRIGGER_SWLAB_DOCS_BXM_S
      -F ref=master 
      https://gitlab.bwg.co.kr/api/v4/projects/987/trigger/pipeline

