1
1
#! /bin/bash
2
2
3
- set -e
4
-
5
3
# ensure asciidoctor is installed
6
4
if ! command -v asciidoctor & > /dev/null ;
7
5
then
11
9
12
10
# get the *.adoc modules and assemblies in the pull request
13
11
FILES=$( git diff --name-only HEAD~1 HEAD --diff-filter=d " *.adoc" ' :(exclude)_unused_topics/*' )
14
-
15
12
REPO_PATH=$( git rev-parse --show-toplevel)
16
13
17
14
# 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 () {
24
21
# Exit 0 if there are no modified assemblies
25
22
if [[ -z " ${UPDATED_ASSEMBLIES} " ]]
26
23
then
24
+ echo " No updated assemblies found! ✅"
27
25
exit 0
28
26
fi
27
+ update_log
29
28
# subtract $REPO_PATH from path with bash substring replacement
30
29
UPDATED_ASSEMBLIES=${UPDATED_ASSEMBLIES// " $REPO_PATH /" / }
31
30
fi
@@ -42,14 +41,23 @@ check_updated_assemblies () {
42
41
if grep -rq " $PAGE " --include " *.yml" _topic_maps ; then
43
42
# validate the assembly
44
43
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
+
46
48
# check assemblies and fail if errors are reported
47
- if [[ -z " $VALIDATION_ERROR " ]];
49
+ if [[ $? != 0 ]];
48
50
then
51
+ echo -e " ${RED} $OUTPUT ${NC} "
52
+ echo " Validation errors found! ❌"
53
+ exit 1
54
+ else
49
55
echo " No errors found! ✅"
56
+ exit 0
50
57
fi
51
58
else
52
59
echo " $ASSEMBLY is not in a topic_map, skipping validation... 😙"
60
+ exit 0
53
61
fi
54
62
done
55
63
}
@@ -71,8 +79,8 @@ update_log () {
71
79
# check assemblies and fail if errors are reported
72
80
if [ -n " ${FILES} " ] ;
73
81
then
74
- update_log
75
82
check_updated_assemblies
76
83
else
77
84
echo " No modified AsciiDoc files found! 🥳"
85
+ exit 0
78
86
fi
0 commit comments