2021-05-04 09:58:49 +02:00
|
|
|
#!/bin/bash
|
2021-05-05 07:53:30 +02:00
|
|
|
set -uo pipefail
|
2021-05-04 09:58:49 +02:00
|
|
|
|
2022-05-23 14:14:57 +02:00
|
|
|
readonly ALLOWED_RULE_SUB_FOLDERS=['common'];
|
|
|
|
|
2021-06-09 11:15:47 +02:00
|
|
|
# Install script dependencies
|
|
|
|
cd rspec-tools
|
|
|
|
pipenv install
|
|
|
|
cd ..
|
2021-05-04 09:58:49 +02:00
|
|
|
|
2021-06-09 11:15:47 +02:00
|
|
|
# Compute the set of affected rules
|
2022-02-01 13:25:23 +01:00
|
|
|
git fetch origin "$CIRRUS_DEFAULT_BRANCH"
|
2021-06-09 11:15:47 +02:00
|
|
|
branch_base_sha=$(git merge-base FETCH_HEAD HEAD)
|
|
|
|
echo "Comparing against the merge-base: $branch_base_sha"
|
2022-02-01 13:25:23 +01:00
|
|
|
changeset=$(git diff --name-only "$branch_base_sha"..HEAD)
|
2021-06-09 11:15:47 +02:00
|
|
|
affected_rules=$(printf '%s\n' "$changeset" | grep '/S[0-9]\+/' | sed 's:\(.*/S[0-9]\+\)/.*:\1:' | sort | uniq)
|
|
|
|
affected_tooling=$(printf '%s\n' "$changeset" | grep -v '/S[0-9]\+/')
|
2022-02-01 13:25:23 +01:00
|
|
|
if [ -n "$affected_tooling" ]; then
|
2021-06-09 11:15:47 +02:00
|
|
|
echo "Some rpec tools are changed, validating all rules"
|
|
|
|
affected_rules=rules/*
|
|
|
|
fi
|
|
|
|
|
2021-09-21 11:30:38 +02:00
|
|
|
exit_code=0
|
|
|
|
|
2022-02-01 13:25:23 +01:00
|
|
|
./ci/generate_html.sh
|
|
|
|
|
2021-05-04 09:58:49 +02:00
|
|
|
cd rspec-tools
|
2022-02-01 13:25:23 +01:00
|
|
|
if pipenv run rspec-tools check-description --d ../out; then
|
|
|
|
echo "rule.adoc is fine"
|
2021-05-05 09:40:19 +02:00
|
|
|
else
|
2022-02-04 17:28:24 +01:00
|
|
|
echo "ERROR: There are invalid rule.adoc"
|
2021-05-05 07:53:30 +02:00
|
|
|
exit_code=1
|
|
|
|
fi
|
2021-05-04 09:58:49 +02:00
|
|
|
cd ..
|
|
|
|
|
2022-02-03 13:21:42 +01:00
|
|
|
echo "Testing the following rules: ${affected_rules}"
|
|
|
|
|
2021-06-09 11:15:47 +02:00
|
|
|
for dir in $affected_rules
|
2020-06-23 11:33:04 +02:00
|
|
|
do
|
2021-06-09 11:15:47 +02:00
|
|
|
if [ ! -d "$dir" ]; then
|
|
|
|
echo "Apparently $dir is deleted, skipping"
|
|
|
|
continue
|
|
|
|
fi
|
2021-01-07 17:15:42 +01:00
|
|
|
dir=${dir%*/}
|
|
|
|
|
2022-02-01 13:25:23 +01:00
|
|
|
subdircount=$(find "$dir" -maxdepth 1 -type d | wc -l)
|
2021-01-07 17:15:42 +01:00
|
|
|
|
|
|
|
# check if there are language specializations
|
|
|
|
if [[ "$subdircount" -eq 1 ]]
|
|
|
|
then
|
|
|
|
# no specializations, that's fine if the rule is deprecated
|
2021-06-08 14:23:48 +02:00
|
|
|
if grep -q '"status": "deprecated"\|"status": "closed"' "$dir/metadata.json"; then
|
|
|
|
echo "INFO: deprecated generic rule $dir with no language specializations"
|
2020-06-23 11:33:04 +02:00
|
|
|
else
|
2021-06-08 14:23:48 +02:00
|
|
|
echo "ERROR: non-deprecated generic rule $dir with no language specializations"
|
|
|
|
exit_code=1
|
2020-06-23 11:33:04 +02:00
|
|
|
fi
|
2021-01-07 17:15:42 +01:00
|
|
|
else
|
|
|
|
#validate asciidoc
|
2022-02-01 13:25:23 +01:00
|
|
|
supportedLanguages=$(sed 's/ or//' supported_languages.adoc | tr -d '`,')
|
|
|
|
for language in $dir/*/
|
2021-01-07 17:15:42 +01:00
|
|
|
do
|
|
|
|
language=${language%*/}
|
2022-02-01 13:25:23 +01:00
|
|
|
if [[ ! "${supportedLanguages[*]}" == *"${language##*/}"* ]]; then
|
2022-05-23 14:14:57 +02:00
|
|
|
if [[ ! "${ALLOWED_RULE_SUB_FOLDERS[*]}" == *"${language##*/}"* ]]; then
|
|
|
|
echo "ERROR: ${language##*/} is not a supported language"
|
|
|
|
exit_code=1
|
|
|
|
fi
|
2021-01-07 17:15:42 +01:00
|
|
|
else
|
2022-05-23 14:14:57 +02:00
|
|
|
RULE="$language/rule.adoc"
|
|
|
|
if test -f "$RULE"; then
|
|
|
|
# We build this filename that describes the path to workaround the fact that asciidoctor will not tell
|
|
|
|
# us the path of the file in case of error.
|
|
|
|
# We can remove it if https://github.com/asciidoctor/asciidoctor/issues/3414 is fixed.
|
|
|
|
TMP_ADOC="$language/tmp_$(basename "${dir}")_${language##*/}.adoc"
|
|
|
|
echo "== Description" > "$TMP_ADOC"
|
|
|
|
cat "$RULE" >> "$TMP_ADOC"
|
|
|
|
else
|
|
|
|
echo "ERROR: no asciidoc file $RULE"
|
|
|
|
exit_code=1
|
|
|
|
fi
|
2021-01-07 17:15:42 +01:00
|
|
|
fi
|
|
|
|
done
|
2022-02-07 18:22:30 +01:00
|
|
|
|
2022-02-01 13:25:23 +01:00
|
|
|
# Check that all adoc are included
|
|
|
|
find "$dir" -name "*.adoc" -execdir sh -c 'grep -h "include::" "$1" | grep -v "rule.adoc" | sed "s/include::\(.*\)\[\]/\1/" | xargs -r -I@ realpath "$PWD/@"' shell {} \; > included
|
2022-02-07 18:22:30 +01:00
|
|
|
find "$dir" -name "*.adoc" ! -name 'rule.adoc' ! -name 'tmp*.adoc' -exec sh -c 'realpath $1' shell {} \; > created
|
2022-02-01 13:25:23 +01:00
|
|
|
orphans=$(comm -1 -3 <(sort -u included) <(sort -u created))
|
|
|
|
if [[ -n "$orphans" ]]; then
|
|
|
|
printf 'ERROR: These adoc files are not included anywhere:\n-----\n%s\n-----\n' "$orphans"
|
|
|
|
exit_code=1
|
|
|
|
fi
|
|
|
|
rm -f included created
|
2021-01-07 17:15:42 +01:00
|
|
|
fi
|
2020-06-23 11:33:04 +02:00
|
|
|
done
|
|
|
|
|
2022-02-07 18:22:30 +01:00
|
|
|
ADOC_COUNT=$(find rules -name "tmp*.adoc" | wc -l)
|
|
|
|
|
2022-02-08 11:00:03 +01:00
|
|
|
if (( ADOC_COUNT > 0 )); then
|
2022-02-07 18:22:30 +01:00
|
|
|
if asciidoctor --failure-level=WARNING -o /dev/null rules/*/*/tmp*.adoc; then
|
|
|
|
if asciidoctor -a rspecator-view --failure-level=WARNING -o /dev/null rules/*/*/tmp*.adoc; then
|
2023-03-07 17:16:47 +01:00
|
|
|
echo "${ADOC_COUNT} documents checked with success"
|
2022-02-07 18:22:30 +01:00
|
|
|
else
|
|
|
|
echo "ERROR: malformed asciidoc files in rspecator-view"
|
|
|
|
exit_code=1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "ERROR: malformed asciidoc files"
|
|
|
|
exit_code=1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "No new asciidoc file changed"
|
|
|
|
fi
|
|
|
|
|
2022-02-01 13:25:23 +01:00
|
|
|
if (( exit_code == 0 )); then
|
2021-06-09 11:15:47 +02:00
|
|
|
echo "Success"
|
|
|
|
else
|
|
|
|
echo "There were errors"
|
|
|
|
fi
|
2021-05-03 21:31:58 +02:00
|
|
|
exit $exit_code
|