#!/bin/bash
set -e

export GIT_PAGER=cat

if [ -n "$SKIP_VALIDATE" ]; then
    echo Skipping validation
    exit
fi

cd $(dirname $0)/..

echo Running: install script signature checks
sha256sum -c install.sh.sha256sum

echo Running: go mod tidy
go mod tidy

echo Running validation

. ./scripts/version.sh

if [ -n "$DIRTY" ]; then
    echo Source dir is dirty
    git status --porcelain --untracked-files=no
    git diff
    exit 1
fi

echo Running: go mod verify
go mod verify

if [ ! -e build/data ];then
    mkdir -p build/data
fi

if [ -z "$SKIP_LINT" ] && command -v golangci-lint; then
    echo Running: golangci-lint
    golangci-lint run --timeout=5m
fi
