#!/usr/bin/env bash
set -e

# GO:GENERATE
go generate

# FORMATTING
exec 5>&1
output="$(go fmt ./... | tee /dev/fd/5)"
[[ -z "$output" ]]

# UNIT TESTS
UNIT_TEST_REPORT=$(go test -timeout 30s -v -race ./...)

returncode=$?
if [ $returncode -ne 0 ]; then
  echo "unit tests failed"
  echo ${UNIT_TEST_REPORT}
  exit 1
fi

go mod tidy

git add .