Skip to content

Commit 5adea0d

Browse files
committed
adding check asciidoctor step to build
1 parent 4c6bec9 commit 5adea0d

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@ cache: pip
33
# env:
44
# - PR_AUTHOR=${TRAVIS_PULL_REQUEST_SLUG::-15}
55
git:
6-
depth: 1
6+
depth: 2
77
jobs:
88
allow_failures:
99
env:
1010
- CAN_FAIL=true
1111
include:
12+
# fail if asciidoctor encounters errors
13+
- stage: validate
14+
name: "Validate updated assemblies with Asciidoctor"
15+
install:
16+
- gem install asciidoctor
17+
- gem install asciidoctor-diagram
18+
script:
19+
- chmod +x ./scripts/check-asciidoctor-build.sh
20+
- ./scripts/check-asciidoctor-build.sh
1221
- stage: build
1322
name: "Build openshift-enterprise distro"
1423
before_install:
@@ -81,6 +90,7 @@ jobs:
8190
- chmod +x autopreview.sh && ./autopreview.sh
8291

8392
stages:
93+
- validate
8494
- build
8595
- netlify
8696
#- check-with-vale

scripts/check-asciidoctor-build.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# ensure asciidoctor is installed
6+
if ! command -v asciidoctor &>/dev/null ;
7+
then
8+
echo "Asciidoctor is not installed. Please install it and try again."
9+
exit 127
10+
fi
11+
12+
# get the *.adoc modules and assemblies in the pull request
13+
FILES=$(git diff --name-only HEAD~1 HEAD --diff-filter=d "*.adoc")
14+
15+
REPO_PATH=$(git rev-parse --show-toplevel)
16+
17+
# get the modules in the PR, search for assemblies that include them, and concat with any updated assemblies files
18+
check_updated_assemblies () {
19+
MODULES=$(echo "$FILES" | awk '/modules\/(.*)\.adoc/')
20+
if [ "${MODULES}" ]
21+
then
22+
# $UPDATED_ASSEMBLIES is the list of assemblies that contains changed modules
23+
UPDATED_ASSEMBLIES=$(grep -rnwl "$REPO_PATH" --include=\*.adoc --exclude-dir={snippets,modules} -e "$MODULES")
24+
# subtract $REPO_PATH from path with bash substring replacement
25+
UPDATED_ASSEMBLIES=${UPDATED_ASSEMBLIES//"$REPO_PATH/"/}
26+
fi
27+
# $ASSEMBLIES is the list of modifed assemblies
28+
ASSEMBLIES=$(echo "$FILES" | awk '!/modules\/(.*)\.adoc/')
29+
# concatenate both lists and remove dupe entries
30+
ALL_ASSEMBLIES=$(echo "$UPDATED_ASSEMBLIES $ASSEMBLIES" | tr ' ' '\n' | sort -u)
31+
# validate the assemblies
32+
echo "Validating updated assemblies. Validation will fail with FAILED, ERROR, or WARNING messages..."
33+
asciidoctor $ALL_ASSEMBLIES -a icons! -o /dev/null -v --failure-level WARN
34+
}
35+
36+
# check assemblies and fail if errors are reported
37+
if [ -n "${FILES}" ] ;
38+
then
39+
check_updated_assemblies
40+
else
41+
echo "No modified AsciiDoc files found."
42+
fi

0 commit comments

Comments
 (0)