image: golang:latest

stages:
  - check
  - package

.test:
  stage: check
  script:
    - go test -v -coverprofile=c.out ./...
    - |
      cat c.out |
      awk 'BEGIN {cov=0; stat=0;}
           $3!="" { cov+=($3==1?$2:0); stat+=$2; }
           END {printf("total coverage: %.2f%% of statements\n", (cov/stat)*100);}'
    - go get github.com/boumenot/gocover-cobertura
    - go run github.com/boumenot/gocover-cobertura < c.out > coverage.xml
  coverage: '/total coverage: \d+\.\d+?%/'
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: coverage.xml

test-1.18:
  extends: .test
  image: golang:1.18

test-1.19:
  extends: .test
  image: golang:1.19

test-1.20:
  extends: .test
  image: golang:1.20

test-1.21:
  extends: .test
  image: golang:1.21

test-1.22:
  extends: .test
  image: golang:1.22

test-1.23:
  extends: .test
  image: golang:1.23

lint:
  stage: check
  script:
    - go vet ./...
    - go fmt ./... && git diff --exit-code --color

# Once all native tests passed, also run Salsa CI, except on a tag push as
# Salsa CI does not run on tag pushes at all
Salsa-CI:
  stage: package
  trigger:
    include: debian/salsa-ci.yml
    strategy: depend
  except:
    variables:
      - $CI_COMMIT_TAG != null
