-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
137 lines (108 loc) · 3.77 KB
/
build.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
echo "Let's make a book!"
bumpLevel=""
onlyRun=""
if [ "$1" = "-BumpLevel" ]; then
bumpLevel="$2"
elif [ "$3" = "-BumpLevel" ]; then
bumpLevel="$4"
fi
if [ "$1" = "-OnlyRun" ]; then
onlyRun="$2"
elif [ "$3" = "-OnlyRun" ]; then
onlyRun="$4"
fi
echo ">>> Gathering files and counting words"
cat ./chapters/*.md > ./tmp-all.txt
counts=($(wc tmp-all.txt | grep -P '\d+' --only-matching))
echo " There are ${counts[1]} words."
rm ./tmp-all.txt
buildcommand=""
nextbuild="preview"
echo ""
echo ">>> Determining build number..."
if [ "$bumpLevel" != "" ]; then
buildtags=($(git tag -l "v*" --sort=-v:refname))
IFS='.' read -r -a versionbits <<< "${buildtags[0]}"
myString="${myString:1}"
major="${versionbits[0]}"
major="${major:1}" # remove the "v" in front
minor="${versionbits[1]}"
patch="${versionbits[2]}"
if [ "$bumpLevel" = "major" ]; then
major=$(($major + 1))
minor="0"
patch="0"
echo "major bump to: $major"
elif [ "$bumpLevel" = "minor" ]; then
minor=$(($minor + 1))
patch="0"
echo "minor bump to: $minor"
elif [ "$bumpLevel" = "patch" ]; then
patch=$(($patch + 1))
echo "patch bump to: $patch"
else
echo "ERROR: Invalid level bump option (should be one of: major, minor, patch)"
exit 1
fi
nextbuild="$major.$minor.$patch"
echo " This will be build: $nextbuild"
buildcommand="--metadata=build:$nextbuild"
else
currenttag=($(git tag --points-at HEAD))
if [[ ${#currenttag[@]} > 1 ]]; then
echo "WARNING: More than one tag reference, generating 'preview' build"
elif [[ "${currenttag[0]}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
currenttag="${currenttag[0]}"
nextbuild="${currenttag:1}" # remove the "v" in front
echo " Using current tag: $nextbuild"
buildcommand="--metadata=build:$nextbuild"
else
echo "WARNING: Current tag reference is not a valid build, generating 'preview' build"
fi
fi
if [[ "$onlyRun" = "" || "$onlyRun" = "pdf" ]]; then
echo ""
echo ">>> Generating PDF file"
cat config-common.yaml > tmp-config-pdf.yaml
cat config-pdf.yaml >> tmp-config-pdf.yaml
pdfcommand="pandoc -s -d tmp-config-pdf.yaml -o ./output/book-$nextbuild.pdf $buildcommand ./chapters/*.md"
echo " $pdfcommand"
$pdfcommand
rm ./tmp-config-pdf.yaml
fi
if [[ "$onlyRun" = "" || "$onlyRun" = "epub" ]]; then
echo ""
echo ">>> Generating ePub file"
cat config-common.yaml > tmp-config-epub.yaml
cat config-epub.yaml >> tmp-config-epub.yaml
epubcommand="pandoc -s -d tmp-config-epub.yaml -o ./output/book-$nextbuild.epub $buildcommand ./chapters/*.md"
echo " $epubcommand"
$epubcommand
rm ./tmp-config-epub.yaml
fi
if [[ "$onlyRun" = "" || "$onlyRun" = "manuscript" ]]; then
echo ""
echo ">>> Generating manuscript file"
cat config-common.yaml > tmp-config-manuscript.yaml
cat config-manuscript.yaml >> tmp-config-manuscript.yaml
manuscriptCommand="pandoc -s -d tmp-config-manuscript.yaml -o ./output/tmp-manuscript.md ./chapters/*.md"
echo " generating intermediary markdown:"
echo " $manuscriptCommand"
$manuscriptCommand
manuscriptCommand="pandoc -o ./output/manuscript-$nextbuild.docx --reference-doc template-manuscript.docx -f markdown -t docx ./output/tmp-manuscript.md"
echo " generating docx manuscript:"
echo " $manuscriptCommand"
$manuscriptCommand
rm ./tmp-config-manuscript.yaml
rm ./output/tmp-manuscript.md
fi
if [[ "$bumpLevel" != "" && "$nextbuild" != "preview" ]]; then
echo ""
echo ">>> Tagging new build: git tag v$nextbuild"
git tag "v$nextbuild"
git push origin "v$nextbuild"
fi
echo ""
echo "All done!"
echo ""