#!/usr/bin/env bash
set -euo pipefail
log() {
printf "\n[%s] %s\n" "$(date +'%b %d %I:%M:%S %p')" "$*"
}
log "Tidying Go modules and checking for changes..."
go mod tidy
if ! git diff --exit-code go.mod go.sum; then
log "go.mod or go.sum has uncommitted changes after 'go mod tidy'."
exit 1
fi
log "Checking code format with 'go fmt'..."
fmt_output=$(go fmt ./...)
if [ -n "$fmt_output" ]; then
log "The following files are not formatted properly:"
echo "$fmt_output"
log "Please run 'go fmt' to fix the formatting issues."
exit 1
fi
log "Running golangci-lint..."
if ! golangci-lint run; then
log "Linting issues detected."
exit 1
fi
log "Searching for TODOs..."
if ag TODO --ignore-dir vendor --ignore scripts --ignore-case | grep -v 'context\.TODO()' ; then
log "Error: Found TODOs in the codebase. Please address them before proceeding."
exit 1
fi
log "Running unit tests..."
cd "$( dirname "${BASH_SOURCE[0]}" )/.."
./scripts/unit.sh
log "Running integration tests..."
./scripts/integration.sh
log "Running contract tests..."
./scripts/contract.sh
log "All tests completed successfully."