11#! /bin/bash
22
3- set -e
4-
53# ensure asciidoctor is installed
64if ! command -v asciidoctor & > /dev/null ;
75then
119
1210# get the *.adoc modules and assemblies in the pull request
1311FILES=$( git diff --name-only HEAD~1 HEAD --diff-filter=d " *.adoc" ' :(exclude)_unused_topics/*' )
14-
1512REPO_PATH=$( git rev-parse --show-toplevel)
1613
1714# get the modules in the PR, search for assemblies that include them, and concat with any updated assemblies files
@@ -24,8 +21,10 @@ check_updated_assemblies () {
2421 # Exit 0 if there are no modified assemblies
2522 if [[ -z " ${UPDATED_ASSEMBLIES} " ]]
2623 then
24+ echo " No updated assemblies found! ✅"
2725 exit 0
2826 fi
27+ update_log
2928 # subtract $REPO_PATH from path with bash substring replacement
3029 UPDATED_ASSEMBLIES=${UPDATED_ASSEMBLIES// " $REPO_PATH /" / }
3130 fi
@@ -42,14 +41,23 @@ check_updated_assemblies () {
4241 if grep -rq " $PAGE " --include " *.yml" _topic_maps ; then
4342 # validate the assembly
4443 echo " Validating $ASSEMBLY ... 🚨"
45- VALIDATION_ERROR=$( asciidoctor " $ASSEMBLY " -a source-highlighter=rouge -a icons! -o /tmp/out.html -v --failure-level WARN --trace)
44+ RED=' \033[0;31m'
45+ NC=' \033[0m'
46+ OUTPUT=$( asciidoctor " $ASSEMBLY " -a source-highlighter=rouge -a icons! -o /tmp/out.html -v --failure-level WARN --trace 2>&1 )
47+
4648 # check assemblies and fail if errors are reported
47- if [[ -z " $VALIDATION_ERROR " ]];
49+ if [[ $? != 0 ]];
4850 then
51+ echo -e " ${RED} $OUTPUT ${NC} "
52+ echo " Validation errors found! ❌"
53+ exit 1
54+ else
4955 echo " No errors found! ✅"
56+ exit 0
5057 fi
5158 else
5259 echo " $ASSEMBLY is not in a topic_map, skipping validation... 😙"
60+ exit 0
5361 fi
5462 done
5563}
@@ -71,8 +79,8 @@ update_log () {
7179# check assemblies and fail if errors are reported
7280if [ -n " ${FILES} " ] ;
7381then
74- update_log
7582 check_updated_assemblies
7683else
7784 echo " No modified AsciiDoc files found! 🥳"
85+ exit 0
7886fi
0 commit comments