image: golang:1.22

stages:
- build
- test
- integration

# go-build builds all packages.
go-build:
  stage: build
  script: go build ./...

# Succeeds if no changes are suggested by gofmt -d .
gofmt:
  stage: test
  script: if gofmt -d . | grep . ; then false ; else true ; fi

# go-test runs tests with the data-race detector enabled.
go-test:
  stage: test
  script: go test -v -race ./...

# There are three flavors of the integration tests, "default" with
# primary and secondary, "extended" where secondary is promoted to new
# primary, and "ephemeral" which runs a simpler backend without mysql
# and trillian.
integration-ephemeral:
  stage: integration
  needs: ["go-test"]
  script: ./integration/test.sh --ephemeral
  artifacts:
    paths: 
    - ./integration/tmp/

integration-default:
  stage: integration
  needs: ["go-test"]
  services:
  - alias: mysql
    name: git.glasklar.is:5050/sigsum/admin/ci-container-images/trilliandb:latest
  variables:
    MYSQL_URI: test:test@tcp(mysql:3306)/test
  script: ./integration/test.sh
  artifacts:
    paths: 
    - ./integration/tmp/

integration-extended:
  stage: integration
  needs: ["go-test"]
  services:
  - alias: mysql
    name: git.glasklar.is:5050/sigsum/admin/ci-container-images/trilliandb:latest
  variables:
    MYSQL_URI: test:test@tcp(mysql:3306)/test
  script: ./integration/test.sh --extended
  artifacts:
    paths: 
    - ./integration/tmp/
