#!/bin/sh

if ! make -C collector check-staged; then
	echo "Format errors found! Run 'make -C collector format' in order to fix them."
	echo "Use the '--no-verify' flag in order to bypass the pre-commit check altogether."
	exit 1
fi

# Validate CircleCI configuration if it was modified and the CLI is available
if command -v circleci >/dev/null && git diff --name-only --cached | grep -qE '^\.circleci/config\.yml$'; then
	echo "Validating CircleCI configuration..."
	circleci config validate --org-slug gh/stackrox .circleci/config.yml
fi
