variables:
  EXTENSION_PATH: "./deadlock-plugins/deadlock-extension"
  REGISTRY: "registry.takima.io"

stages:
  - build
  - publish


build:
  stage: build
  services:
    - docker:18.09.6-dind
  variables:
    VERSION: "desktop"

  before_script:
    - apk update
    - apk add nodejs npm
    - export TAG=${CI_COMMIT_TAG:-latest}
    - ./setup.sh
  script:
    - ./build.sh $TAG desktop $CI_REGISTRY_IMAGE
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $REGISTRY
    - docker push $CI_REGISTRY_IMAGE/$VERSION:$TAG
  only:
    - master

desktop_extension:package:pre-release:
  stage: build
  cache:
    paths:
      - $EXTENSION_PATH
    policy: push
  before_script:
    - apk update
    - apk add nodejs npm
    - rm -f $EXTENSION_PATH/*.vsix
    - npm install --prefix $EXTENSION_PATH
  script:
    - ./build-desktop.sh staging
  only:
    - master


desktop_extension:publish:pre-release:
  stage: publish
  cache:
    paths:
      - $EXTENSION_PATH
    policy: pull

  before_script:
    - apk update
    - apk add nodejs npm
    - npm install --prefix $EXTENSION_PATH
  script:
    - cd $EXTENSION_PATH
    - npm run vsce-publish -- --pre-release -p $VSCODE_EXTENSION_MARKET_PLACE_ACCESS_TOKEN
  only:
    - master


desktop_extension:package:release:
  stage: build
  cache:
    paths:
      - $EXTENSION_PATH

    policy: push
  before_script:
    - apk update
    - apk add nodejs npm
    - rm -f $EXTENSION_PATH/*.vsix
    - npm install --prefix $EXTENSION_PATH
  script:
    - ./build-desktop.sh prod
  rules:
    - if: $CI_COMMIT_BRANCH == "master" && $CI_COMMIT_TAG =~ /^(?:\d+\.){2}(?:\d+)$/

desktop_extension:publish:release:
  stage: publish
  cache:
    paths:
      - $EXTENSION_PATH
    policy: pull

  before_script:
    - apk update
    - apk add nodejs npm
    - npm install --prefix $EXTENSION_PATH
  script:
    - cd $EXTENSION_PATH
    - npm run vsce-publish -- -p $VSCODE_EXTENSION_MARKET_PLACE_ACCESS_TOKEN
  rules:
    - if: $CI_COMMIT_BRANCH == "master" && $CI_COMMIT_TAG =~ /^(?:\d+\.){2}(?:\d+)$/
