# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
default:
  tags:
    - build-push-to-registry

stages:
  - test
  - build
  - deploy
  - publish

sast:
  stage: test
include:
  - template: Security/SAST.gitlab-ci.yml

build-dev:
  image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:16.14.2-alpine3.14
  stage: build
  before_script:
    - apk add git
    - apk add bash
  script:
    - yarn
    - yarn build
    - git config --global user.name build-token
    - git config --global user.email "$GIT_USER"
    - git config --global user.password "$GIT_PWD"
    - git config user.email "$GIT_USER"
    - git remote set-url origin https://"$GIT_USER":"$GIT_PWD"@forge.grandlyon.com/web-et-numerique/factory/llle_project/egl-konnector.git
    - git config --global credential.helper store
    - yarn deploy-dev

build:
  image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:16.14.2-alpine3.14
  stage: build
  before_script:
    - apk add git
    - apk add bash
  script:
    - yarn
    - yarn build
    - git config --global user.name build-token
    - git config --global user.email "$GIT_USER"
    - git config --global user.password "$GIT_PWD"
    - git config user.email "$GIT_USER"
    - git remote set-url origin https://"$GIT_USER":"$GIT_PWD"@forge.grandlyon.com/web-et-numerique/factory/llle_project/egl-konnector.git
    - git config --global credential.helper store
    - yarn deploy
  only:
    - main

deploy_dev:
  stage: deploy
  tags:
    - deploy-alpha
  script:
    - cd /root/ecolyo-infra-scripts/cicid_scripts
    - './update_egl_dev.sh'
  environment:
    name: dev
    url: https://dev.cozy.self-data.alpha.grandlyon.com/
  when: manual

deploy_demo:
  stage: deploy
  tags:
    - deploy-alpha
  script:
    - cd /root/ecolyo-infra-scripts/cicid_scripts
    - './update_all_egl_dev.sh'
  only:
    - master
  environment:
    name: ecolyodemo
    url: https://ecolyodemo.cozy.self-data.alpha.grandlyon.com/

publish:
  stage: publish
  before_script:
    - apk add git
  script:
    - yarn cozyPublish
  only:
    - tags
  when: manual
