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
|
2022-01-28 14:37:57 +01:00
|
|
|
basename --multiple rules/* | mapfile -t affected_rules
|
2022-03-08 04:26:53 -08:00
|
|
|
echo "Change in the tools, revalidating all rules"
|
2022-01-28 09:51:13 +01:00
|
|
|
else
|
2022-03-08 04:26:53 -08:00
|
|
|
git diff --name-only "${base}" -- rules/ | # Get all the changes in rules
|
|
|
|
sed -Ee 's#(rules/S[0-9]+)/.*#\1#' | # extract the rule directories
|
|
|
|
sort -u | # deduplicate
|
2024-08-14 09:43:10 +02:00
|
|
|
while IFS= read -r rule; do if [[ -d "$rule" ]]; then echo "$rule"; fi done | # filter out deleted rules
|
2022-03-08 04:26:53 -08:00
|
|
|
sed 's#rules/##' | # get rule ids
|
|
|
|
mapfile -t affected_rules # store them in the `affected_rules` array
|
2024-08-14 09:43:10 +02:00
|
|
|
echo "Validating ${affected_rules[*]}"
|
2022-01-28 09:51:13 +01:00
|
|
|
fi
|
|
|
|
|
2024-08-14 09:43:10 +02:00
|
|
|
printf '\n\n\n'
|
|
|
|
|
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
|
2024-08-14 09:43:10 +02:00
|
|
|
printf '\n\n\n'
|
2022-01-28 09:51:13 +01:00
|
|
|
pipenv run rspec-tools validate-rules-metadata "${affected_rules[@]}"
|
2022-03-08 04:26:53 -08:00
|
|
|
else
|
|
|
|
echo "No rule changed or added"
|
2021-02-23 20:41:11 +01:00
|
|
|
fi
|