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=id-$CI_PROJECT_ID -Dsonar.projectName="$CI_PROJECT_PATH" -Dsonar.projectVersion=$CI_COMMIT_BRANCH
  allow_failure: true
  only:
    - develop
    - master
    - draft

build_development:
  stage: build
  tags:
    - build
  image: node:18.16.0
  script:
    - npm install --unsafe-perm
    - echo -e "
      NODE_ENV=development\n
      DOMAIN=https://dev.pigma.neogeo.fr/\n
      VUE_APP_DOMAIN=${DOMAIN}\n
      BASE_PATH=/\n
      VUE_APP_BASE_PATH=${BASE_PATH}\n
      VUE_APP_NEXT_DEFAULT=/\n
      VUE_APP_LOCALE=fr-FR\n
      VUE_APP_I18N_LOCALE=fr\n
      VUE_APP_I18N_DEFAULT_LOCALE=fr\n
      VUE_APP_I18N_FALLBACK_LOCALE=fr\n
      VUE_APP_I18N_SUPPORTED_LOCALE=fr,en\n
      VUE_APP_LOGO=@/assets/logo.png\n
      VUE_APP_TITLE=Onegeo-Suite\n
      VUE_APP_FAVICON_URL=${VUE_APP_DOMAIN}/assets/favicon.png\n
      VUE_APP_LOGIN_API_PATH=/login/\n
      VUE_APP_ORGANISATION_API_PATH=/organisation/\n
      VUE_APP_USERGROUP_API_PATH=/usergroup/\n
      VUE_APP_PERSONAL_DATA_API_PATH=/personal-data/\n
      VUE_APP_EXTERNAL_LOGIN=true\n
      VUE_APP_EXTERNAL_LOGIN_URL=http://127.0.0.1:80/oidc/authenticate\n
      VUE_APP_EXTERNAL_LOGOUT_URL=http://127.0.0.1:80/oidc/logout/?redirect_uri=/fr/login/signout\n
      VUE_APP_EXTERNAL_LOGOUT_METHOD=get\n
      VUE_APP_EXTERNAL_LOGIN_LABEL=Se connecter avec mon compte FooBar\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"
