forked from thesis/asciidoctor-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·70 lines (59 loc) · 1.69 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Exit on error.
set -e
# Allow ** globs, ignore empty globs
shopt -s extglob globstar nullglob
EX_USAGE=64 # Usage error exit code from /usr/include/sysexits.h
OUTPUT_FORMAT=
ASCIIDOCTOR_ARGS=
while getopts ":f:a:" arg; do
case "${arg}" in
f)
OUTPUT_FORMAT=${OPTARG}
;;
a)
ASCIIDOCTOR_ARGS=${OPTARG}
;;
*)
break
;;
esac
done
shift $((OPTIND-1))
read -r INPUT_FILES <<<$*
ASCIIDOCTOR=asciidoctor
if [[ "pdf" = $OUTPUT_FORMAT ]]; then
ASCIIDOCTOR=asciidoctor-pdf
fi
if [[ -z $INPUT_FILES ]]; then
printf "No input files specified\n" >&2
exit $EX_USAGE
fi
COMMAND=$(echo "$ASCIIDOCTOR -R . -D $GITHUB_WORKSPACE/asciidoc-out -r asciidoctor-diagram -a mermaid-puppeteer-config=/mermaid/puppeteer-config.json -a source-highlighter@=rouge" $ASCIIDOCTOR_ARGS $INPUT_FILES)
OUTPUT=
echo "Running '$COMMAND'"
# TEST env variable indicates we should be in testing mode (below).
mkdir $GITHUB_WORKSPACE/asciidoc-out
eval $COMMAND
FILES=$(echo $GITHUB_WORKSPACE/asciidoc-out/**/*)
OUTPUT="::set-output name=asciidoctor-artifacts::asciidoc-out"
echo "Generated files $FILES"
if [[ -z $TEST_COMMAND && -z $TEST_OUTPUT ]]; then
echo "Output:"
echo "${OUTPUT}"
echo "Output ${OUTPUT}"
elif [[ "${COMMAND}" != "${TEST_COMMAND}" ]]; then
printf "Ran unexpected command:\n" >&2
diff <(echo "${COMMAND}") <(echo "${TEST_COMMAND}") >&2
exit 1
elif [[ "${OUTPUT}" != "${TEST_OUTPUT}" ]]; then
printf "Printed unexpected output:\n" >&2
diff <(echo "${OUTPUT}") <(echo "${TEST_OUTPUT}") >&2
exit 1
else
echo "Command equals test expectations:"
echo "${TEST_COMMAND}"
echo "And output equals test expectations:"
echo "${TEST_OUTPUT}"
exit 0
fi