# This can be removed if you are not using AppServer
.before_script_template:
  before_script:
    - check_if_version_installed=$(. ~/init_nodejs.sh >/dev/null; nvm ls --no-colors 24.13.0 | tail -1 | tr -d '\->*' | tr -d '[:space:]')
    - if [[ "$check_if_version_installed" == "N/A" ]]; then . ~/init_nodejs.sh >/dev/null; nvm install 24.13.0; fi
    - . ~/init_nodejs.sh >/dev/null; nvm use --delete-prefix 24.13.0

Admin UI build:
  extends: .before_script_template
  script:
    - yarn install
    # CI=false : avoid warnings to be treated as errors
    - CI=false yarn typescript
  tags:
    - yarn

ESlint analyze:
  extends: .before_script_template
  # Run when
  # - the pipeline is triggered by a merge request event and there are changes in the src directory
  # - the pipeline is triggered by a new commit on the default branch and there are changes in the src directory
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event' || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      changes:
        - src/**/*
  script:
    - yarn install
    - git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
    # Use different eslint command based on pipeline source
    # For default branch: use yarn eslint (whole project is analyzed)
    # For other pipelines: use yarn eslint-pipeline (only changed files are analyzed)
    - |
      if [ $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH ]; then
        CI=false yarn eslint
      else
        CI=false yarn eslint-pipeline
      fi
  tags:
    - yarn

SonarQube analyze admin UI:
  extends: .before_script_template
  script:
    - yarn && yarn coverage --passWithNoTests
    - sonar-scanner -D project.settings=sonar-project-frontend.properties
  tags:
    - sonar
