image: 'maven:3.8.5-openjdk-17-slim'

cache:
  paths:
    - .m2/repository

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version"

stages:
  - build
  - unit_test
  - integration_test

build:
  tags:
    - shared-fi
  stage: build
  script:
    - echo "We are building your project, $GITLAB_USER_LOGIN"
    - ls
    - ./mvnw clean install -Dmaven.test.skip=true $MAVEN_CLI_OPTS

unit_test:
  tags:
    - shared-fi
  stage: unit_test
  script:
    - echo "We are testing your project build with unit tests, $GITLAB_USER_LOGIN"
    - ./mvnw test $MAVEN_CLI_OPTS
  artifacts:
    expire_in: 10 min
    paths:
      - "*/target/surefire-reports/*"
    reports:
      junit:
        - "*/target/surefire-reports/*"

integration_test:
  tags:
    - shared-fi
  stage: integration_test
  script:
    - echo "We are testing your project build with integration tests, $GITLAB_USER_LOGIN"
    - ./mvnw verify $MAVEN_CLI_OPTS
  artifacts:
    expire_in: 10 min
    paths:
      - "*/target/failsafe-reports/*"
    reports:
      junit:
        - "*/target/failsafe-reports/*"