#!/bin/bash

set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Tests in this path may read the environment variable
# MODULE_DEFAULTS_TEST_BASELINE which specifies the commit ID that this PR has
# been applied atop.

# Set the $CWD to the root of this repo
GIT_ROOT=$(git rev-parse --show-toplevel)
pushd $GIT_ROOT

# Get a list of changed files
modified_files=$(git log --name-only \
                         --pretty=oneline \
                         --full-index \
                         $MODULE_DEFAULTS_TEST_BASELINE..$MODULE_DEFAULTS_TEST_UPDATED \
                  | grep -vE '^[0-9a-f]{40} ' | sort -u)

for file in ${modified_files[@]}; do
    if [[ $file == *".yaml" ]]; then
        $SCRIPT_DIR/compare_defaults.py \
            $file \
            $MODULE_DEFAULTS_TEST_BASELINE \
            $MODULE_DEFAULTS_TEST_UPDATED
    fi
done

popd
