stages:
  - build
  - publish

before_script:
  - apk update
  - apk add nodejs npm
  - apk add yarn
  - apk add curl
  - export TAG=${CI_COMMIT_TAG:-latest}

build:
  stage: build
  services:
    - docker:18.09.6-dind
  parallel:
    matrix:
      - VERSION: [code, kube]
  script:
    - ./build.sh $TAG $VERSION $CI_REGISTRY_IMAGE
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.e-biz.fr
    - docker push $CI_REGISTRY_IMAGE/$VERSION:$TAG
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
    - if: $CI_COMMIT_TAG != null


desktop_extension:package:pre-release:
  stage: build
  cache:
    paths:
      - ./deadlock-plugins/deadlock-extension/
  script:
    - ./build-desktop.sh staging
  rules:
    - if: $CI_COMMIT_BRANCH == "develop"

desktop_extension:publish:pre-release:
  stage: publish
  cache:
    paths:
      - ./deadlock-plugins/deadlock-extension/
    policy: pull
  script:
    - cd ./deadlock-plugins/deadlock-extension
    - npm run vsce-publish -- -pre-release -p $VSCODE_EXTENSION_MARKET_PLACE_ACCESS_TOKEN
  rules:
    - if: $CI_COMMIT_BRANCH == "develop"


desktop_extension:package:release:
  stage: build
  cache:
    paths:
      - ./deadlock-plugins/deadlock-extension/
  script:
    - ./build-desktop.sh prod
  rules:
    - if: $CI_COMMIT_BRANCH == "main"

desktop_extension:publish:release:
  stage: publish
  cache:
    paths:
      - ./deadlock-plugins/deadlock-extension/
    policy: pull
  script:
    - cd ./deadlock-plugins/deadlock-extension
    - npm run vsce-publish -- -p $VSCODE_EXTENSION_MARKET_PLACE_ACCESS_TOKEN
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
