#This declares the pipeline stages  
image: node:13.1

stages:
  - build
  - test
  - deploy
  
cache:
  paths:
  - node_modules/
  
build:
  stage: build
  script:
    - npm install
    - npm run-script build
  tags:
    - docker
    
test:
  stage: test
  script:
    - echo "Running react test suite......"
  tags:
    - docker

license_management:
  stage: test
  image:
    name: "registry.gitlab.labranet.jamk.fi//gitlab-org/security-products/license-management:$CI_SERVER_VERSION_MAJOR-$CI_SERVER_VERSION_MINOR-stable"
    entrypoint: [""]
  variables:
    SETUP_CMD: $LICENSE_MANAGEMENT_SETUP_CMD
  allow_failure: true
  script:
    - /run.sh analyze .
  artifacts:
    reports:
      license_management: $CI_PROJECT_DIR/gl-license-management-report.json
    expire_in: 1 week
  dependencies: []
  only:
    refs:
      - branches
    variables:
      - $GITLAB_FEATURES =~ /\blicense_management\b/
  except:
    variables:
      - $LICENSE_MANAGEMENT_DISABLED

  tags:
    - docker


code_quality:
  stage: test
  image: docker:stable
  allow_failure: true
  services:
    - docker:stable-dind
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - |
      if ! docker info &>/dev/null; then
        if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then
          export DOCKER_HOST='tcp://localhost:8080'
        fi
      fi
    - docker run
        --env SOURCE_CODE="$PWD"
        --volume "$PWD":/code
        --volume /var/run/docker.sock:/var/run/docker.sock
        "registry.gitlab.labranet.jamk.fi/gitlab-org/security-products/codequality:12-0-stable" /code
  artifacts:
    reports:
      codequality: $CI_PROJECT_DIR/gl-code-quality-report.json
    expire_in: 1 week
    when: always
  dependencies: []
  only:
    refs:
      - branches
      - tags
  except:
    variables:
      - $CODE_QUALITY_ENABLE

  tags:
    - docker

    
deploy:
  stage: deploy
  script:
    - echo 'Deploy'
  tags:
    - docker

