2022-01-28 09:51:13 +01:00
|
|
|
#!/bin/bash
|
|
|
|
set -ueo pipefail
|
2022-01-28 14:37:57 +01:00
|
|
|
shopt -s lastpipe # To pipe command result into mapfile and have the array variable available in the main shell process.
|
2022-01-28 09:51:13 +01:00
|
|
|
|
|
|
|
git fetch --quiet "${CIRRUS_DEFAULT_ORIGIN:-origin}" "${CIRRUS_DEFAULT_BRANCH:-master}"
|
|
|
|
base="$(git merge-base FETCH_HEAD HEAD)"
|
|
|
|
echo "Comparing against the merge-base: ${base}"
|
|
|
|
if ! git diff --name-only --exit-code "${base}" -- rspec-tools/
|
|
|
|
then
|
|
|
|
# Revalidate all rules
|
2022-01-28 14:37:57 +01:00
|
|
|
basename --multiple rules/* | mapfile -t affected_rules
|
2022-01-28 09:51:13 +01:00
|
|
|
else
|
2022-01-28 14:37:57 +01:00
|
|
|
git diff --name-only "${base}" -- rules/ | sed -Ee 's#rules/(S[0-9]+)/.*#\1#' | sort -u | mapfile -t affected_rules
|
2022-01-28 09:51:13 +01:00
|
|
|
fi
|
|
|
|
|
2021-02-23 20:41:11 +01:00
|
|
|
# Validate metadata
|
2022-01-28 09:51:13 +01:00
|
|
|
if [[ "${#affected_rules[@]}" -gt 0 ]]
|
|
|
|
then
|
|
|
|
cd rspec-tools
|
|
|
|
pipenv install
|
|
|
|
pipenv run rspec-tools validate-rules-metadata "${affected_rules[@]}"
|
2021-02-23 20:41:11 +01:00
|
|
|
fi
|