cache:
    key: "$CI_BUILD_REF_NAME"
    paths:
        - node_modules
        - .maven
stages:
    - build
    - test
    - package

before_script:
    - export MAVEN_USER_HOME=`pwd`/.maven
    - chmod +x mvnw
    - ./mvnw com.github.eirslett:frontend-maven-plugin:install-node-and-npm -DnodeVersion=v6.10.0 -DnpmVersion=4.3.0
    - ./mvnw com.github.eirslett:frontend-maven-plugin:npm

maven-build:
    stage: build
    script: ./mvnw compile -Dmaven.repo.local=$MAVEN_USER_HOME

maven-test:
    stage: test
    script:
        - ./mvnw test -Dmaven.repo.local=$MAVEN_USER_HOME
    artifacts:
        paths:
            - target/surefire-reports/*
maven-front-test:
    stage: test
    script:
        - ./mvnw com.github.eirslett:frontend-maven-plugin:npm -Dfrontend.yarn.arguments=test
    artifacts:
        paths:
            - target/test-results/karma/*
gatling-test:
    stage: test
    allow_failure: true
    script:
        - ./mvnw gatling:execute -Dmaven.repo.local=$MAVEN_USER_HOME
    before_script:
        - export MAVEN_USER_HOME=`pwd`/.maven
        - chmod +x mvnw
        - ./mvnw com.github.eirslett:frontend-maven-plugin:install-node-and-npm -DnodeVersion=v6.10.0 -DnpmVersion=4.3.0
        - ./mvnw com.github.eirslett:frontend-maven-plugin:npm
        - ./mvnw &
    artifacts:
        paths:
            - target/gatling/*
maven-package:
    stage: package
    script:
        - ./mvnw package -Pprod -DskipTests -Dmaven.repo.local=$MAVEN_USER_HOME
    artifacts:
        paths:
            - target/*.war