variables:
  SONAR_TOKEN: "$SONAR_TOKEN"
  SONAR_PROJECTKEY: "$CI_PROJECT_NAME"
  SONAR_HOST_URL: "https://sonarqube.neogeo.fr"
  GIT_DEPTH: 0

cache:
  paths:
    - node_modules/

stages:
  - sonarqube
  - build
  - deploy

sonarqube-check:
  image:
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  stage: sonarqube
  script:
    - sonar-scanner -Dsonar.qualitygate.wait=true -Dsonar.projectKey=$CI_PROJECT_NAME -Dsonar.projectName=$CI_PROJECT_NAME -Dsonar.projectVersion=$CI_COMMIT_BRANCH
  allow_failure: true
  only:
    - develop
    - master
    - draft

build_development:
  stage: build
  tags:
    - build
  image: node:14.16.0
  script:
    - npm install --unsafe-perm
    - echo -e "
      NODE_ENV=development\n
      VUE_APP_LOCALE=fr-FR\n
      DOMAIN=https://dev.pigma.neogeo.fr/fr\n
      VUE_APP_DOMAIN=https://dev.pigma.neogeo.fr/\n
      BASE_PATH=/\n
      VUE_APP_NEXT_DEFAULT=/\n
      VUE_APP_BASE_PATH=${BASE_PATH}\n
      VUE_APP_FAVICON_URL=${VUE_APP_DOMAIN}/assets/favicon.png\n
      VUE_APP_LOGIN_API_PATH=/fr/login/\n
      VUE_APP_ORGANISATION_API_PATH=/fr/organisation/\n
      VUE_APP_USERGROUP_API_PATH=/fr/usergroup/\n
      VUE_APP_LOGIN_API_USERNAME=admin\n
      VUE_APP_LOGIN_API_PASSWORD=Neogeo2020\n" > .env
    - npm run build
  artifacts:
    paths:
      - dist
    expire_in: 1 week

deploy-pigma-dev:
  image: alpine
  tags:
    - deploy-dev
  stage: deploy
  when: manual
  script:
    - apk add --no-cache rsync openssh
    - mkdir -p ~/.ssh
    - echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa
    - chmod 600 ~/.ssh/id_dsa
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
    - ls -lrth
    - scp -o "ProxyCommand ssh debian@10.0.30.17 -W %h:%p" -r dist/* debian@10.9.10.13:/opt/neogeo/onegeo-login
    - ssh -J debian@10.0.30.17 debian@10.9.10.13 "echo test"
