version: '3'

tasks:
  test:
    cmds:
    - go test -v -cover ./...

  # postgres tests are currently failing due to issues
  # with the seed.sql file.
  test-postgres:
    env:
      DATABASE_DRIVER: postgres
      DATABASE_CONFIG: host=localhost user=postgres password=postgres dbname=postgres sslmode=disable
      GO111MODULE: 'on'
    cmds:
      - cmd: docker kill postgres
        ignore_error: true
        silent: false
      - silent: false
        cmd: >
          docker run
          -p 5432:5432
          --env POSTGRES_PASSWORD=postgres
          --env POSTGRES_USER=postgres
          --name postgres
          --detach
          --rm
          postgres:9-alpine
      - cmd: go test -v -cover github.com/harness/gitness/internal/store/database
      - cmd: docker kill postgres
        silent: true

  setup:
    cmds:
    - cd web; npm install
    - cd web; npm run build
    - go generate ./...
    - go build

  teardown:
    cmds:
    - rm -rf release
    - rm -rf web/.cache
    - rm -rf web/dist/files
    - rm -rf web/node_modules
    - rm -rf web/.env.development.local
    - rm -rf web/swagger.yaml
    - rm -rf gitness
    - rm -rf database.sqlite3
    - rm -rf .env

  docker-build:
    cmds:
    - docker build -t harness/gitness:linux-amd64 -f docker/Dockerfile .

  docker-build-all:
    cmds:
    - docker build -t harness/gitness:linux-amd64 -f docker/Dockerfile .
    - docker build -t harness/gitness:linux-arm64 -f docker/Dockerfile.linux.arm64 .
    - docker build -t harness/gitness:linux-arm   -f docker/Dockerfile.linux.arm .
