image: golang:latest

stages:
  - test

run_tests:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
  stage: test
  script:
    - go install gotest.tools/gotestsum@latest
    - gotestsum --format testname --junitfile report.xml
  artifacts:
    when: always
    reports:
      junit: report.xml

lint:
  image: golangci/golangci-lint:v1.55-alpine
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
  stage: test
  script:
    - golangci-lint run --issues-exit-code 1 --print-issued-lines=false --new-from-rev $CI_MERGE_REQUEST_DIFF_BASE_SHA --out-format code-climate:gl-code-quality-report.json,line-number
  artifacts:
    reports:
      codequality: gl-code-quality-report.json
    paths:
      - gl-code-quality-report.json
