forked from NCIP/gdc-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-gdc-docs.sh
131 lines (114 loc) · 5.94 KB
/
deploy-gdc-docs.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
#!/bin/bash
# This script pull the latest version from git, build PDF and mkdocs.
# Takes the following arguments:
# - dev
# - qa
while [[ $# > 1 ]]
do
key="$1"
case $key in
-e|--environment)
ENVIRONMENT="$2"
shift
;;
--default)
ENVIRONMENT='dev'
;;
*)
;;
esac
shift
done
if [ "$ENVIRONMENT" != "dev" ] && [ "$ENVIRONMENT" != "qa" ]; then
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Incorrect environment, needs to be dev or qa"
exit;
fi
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Building script for ${ENVIRONMENT}"
rm /tmp/${ENVIRONMENT}-buildlog.txt
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>/tmp/${ENVIRONMENT}-buildlog.txt 2>&1
if [ -d "~/gdc-docs-${ENVIRONMENT}/" ]; then
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Directory exists, removing"
sudo rm ~/gdc-docs-${ENVIRONMENT}/ -R
fi
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Creating directory and cloning git repo"
mkdir ~/gdc-docs-${ENVIRONMENT}/
git clone [email protected]:NCI-GDC/gdc-docs.git ~/gdc-docs-${ENVIRONMENT}/
cd ~/gdc-docs-${ENVIRONMENT}/
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Switching to correct branch"
if [ "$ENVIRONMENT" = "dev" ] ; then
/usr/bin/git checkout develop
elif [ "$ENVIRONMENT" = "qa" ] ; then
/usr/bin/git checkout master
else
exit;
fi
#iconv --verbose -f ascii -t utf-8 -o /tmp/test docs/Data_Portal/PDF/Data_Portal_UG.pd
hasEncodingError=false
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Veryfing if all MARKDOWN have no encoding issue"
for scanFile in $( find docs/ | grep md | egrep -v Eliminate ); do
iconv -f ascii -t utf-8 -o /tmp/test ${scanFile} >> /tmp/${ENVIRONMENT}-buildlog.txt
if [ "$?" -gt 0 ] ; then
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: NOK: ${scanFile} has an encoding error, to address open in vim and use :goto POSITION"
hasEncodingError=true
else
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: OK: ${scanFile} "
fi
done
if $hasEncodingError ; then
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ERROR: Some of the files have encoding errors, not building the site"
if [ -f /tmp/${ENVIRONMENT}-buildlog.txt ]; then
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Copying log file"
cp /tmp/${ENVIRONMENT}-buildlog.txt /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/buildlog.txt
fi
exit
fi
#echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Veryfing if all MARKDOWN files are UTF-8 encoded"
#countWrongFiles=$(for f in `find docs/ | egrep -v Eliminate`; do echo "$f" ' -- ' `file -bi "$f"` ; done | grep ".md" | grep -v "utf-8" | wc -l)
#echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Number of incorrectly encoded files: ${countWrongFiles}"
#if [ "$countWrongFiles" -gt 0 ] ; then
# echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ERROR the following files are not encoded in UTF-8"
# for f in `find docs/ | egrep -v Eliminate`; do echo "$f" ' -- ' `file -bi "$f"` ; done | grep ".md" | grep -v "utf-8"
# if [ -f /tmp/${ENVIRONMENT}-buildlog.txt ]; then
# echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Copying log file"
# cp /tmp/${ENVIRONMENT}-buildlog.txt /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/buildlog.txt
# fi
# exit
#fi
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Looking for User Guides"
userGuides=()
for i in $( ls *_UG.yml ); do
userGuides+=(${i::${#i}-7})
done
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Number of User Guides found: ${#userGuides[@]}"
for userGuide in "${userGuides[@]}"; do
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Starting creation"
if [ ! -d "docs/Data_Portal/PDF/" ]; then
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: PDF Directory does not exists, creating ..."
mkdir docs/${userGuide}/PDF/
fi
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Building pandoc document"
/usr/local/bin/mkdocs2pandoc -f ${userGuide}_UG.yml -o docs/${userGuide}/PDF/${userGuide}_UG.pd
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Replacing strings in pandoc document "
/bin/sed -i -e 's/# / /g' docs/${userGuide}/PDF/${userGuide}_UG.pd
/bin/sed -i -e 's/### /## /g' docs/${userGuide}/PDF/${userGuide}_UG.pd
/bin/sed -i -e 's/\/site\//\/docs\//g' docs/${userGuide}/PDF/${userGuide}_UG.pd
/bin/sed -i -e "s/(images/(https:\/\/gdc-docs.nci.nih.gov\/"$userGuide"\/Users_Guide\/images/g" docs/${userGuide}/PDF/${userGuide}_UG.pd #To make images clickable in the PDF
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Building PDF from pandoc document "
/usr/bin/pandoc --listings -H theme/latex/listings-setup.tex --toc -V documentclass=report -V geometry:"top=2cm, bottom=1.5cm, left=1cm, right=1cm" -f markdown+grid_tables+table_captions docs/${userGuide}/PDF/${userGuide}_Title.txt -o docs/${userGuide}/PDF/${userGuide}_UG.pdf docs/${userGuide}/PDF/${userGuide}_UG.pd
done
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Cleaning previous website directory (rm)"
sudo rm /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/* -R
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Build Encyclopedia"
python buildencyclopedia.py
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Deploying new version to /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/"
/usr/local/bin/mkdocs build -v --site-dir /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/
if [ -f /tmp/${ENVIRONMENT}-buildlog.txt ]; then
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Copying log file"
cp /tmp/${ENVIRONMENT}-buildlog.txt /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/buildlog.txt
fi
#echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Temporarily creating symlink"
#Temporary fix to address a link that would be broken otherwise in the submission portal due to a change of the dictionary name
#rm /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/Dictionary/ -R
#ln -sfn /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/Data_Dictionary /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/Dictionary