#!/usr/bin/env bash

# Copyright (C) Lightbend Inc. <https://www.lightbend.com>

# shellcheck source=scripts/scriptLib
. "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/scriptLib"

cd "$DOCUMENTATION"

printMessage "RUNNING DOCUMENTATION VALIDATION"
runSbt evaluateSbtFiles
runSbt validateDocs
runSbt headerCheck test:headerCheck

scalafmtValidation "documentation"
javafmtValidation "documentation"

printMessage "ALL DOCUMENTATION VALIDATION PASSED"

# Check that markdown files have copyright headers

./addMarkdownCopyright

# Only checks diffs inside the documentation directory
git diff --exit-code . || (
  echo "ERROR: Documentation copyright or sources license header check failed, see differences above."
  echo "To fix, run the './addMarkdownCopyright' script inside the documentation directory or 'sbt test:compile' at the root of the repo."
  echo "After that you can update your pull request."
  false
)
