#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."

# Lists the tracked and the new, not ignored files that match a pattern.
files() {
  git ls-files --cached --others --exclude-standard -- "$@"
}

unformatted=$(gofumpt -l .)
if [ -n "$unformatted" ]; then
  printf 'gofumpt: unformatted files:\n%s\n' "$unformatted" >&2
  exit 1
fi

go vet ./...
golangci-lint run
go test -race -short ./...
files '*.nix' | xargs nixfmt --check
files '*.rst' | xargs rstfmt --check
files '*.md' | xargs mdformat --check
shellcheck bin/check bin/format bin/reflow bin/service-update .githooks/commit-msg
