forked from Rob-Pait/dreamcloud-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjenkins-script.sh
More file actions
executable file
·94 lines (79 loc) · 3.27 KB
/
jenkins-script.sh
File metadata and controls
executable file
·94 lines (79 loc) · 3.27 KB
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
#! /bin/bash
#################################################################################
# This script takes diffs between the last successful jenkins run and the #
# current run to find what files have changed. The script updates (in zendesk) #
# each article that has changed (by looking at the rst files). It also updates #
# each article that uses an image that has changed (by finding images that have #
# changed and then grepping recursively for that filename in each rst file). #
# The script figures out what section ID an article has by looking at the #
# "section_id.txt" file in the directory that also has the article source (rst) #
#################################################################################
if [ -z "$EMAIL" ] ; then
echo '$EMAIL is not set'
exit 1
fi
if [ -z "$ZENDESK_PASS" ] ; then
echo '$ZENDESK_PASS is not set'
exit 1
fi
if [ -z "$ZENDESK_URL" ] ; then
echo '$ZENDESK_URL is not set'
exit 1
fi
# Build the documentation
tox
if [ $? -ne 0 ] ; then
echo "tox build failed"
exit 1
fi
# Clone the publish script
git clone https://github.com/dreamhost/zendesk-publish-script.git
if [ $? -ne 0 ] ; then
echo "Could not clone the publishing script"
exit 1
fi
# create a venv to run the publishing script
virtualenv venv ; . venv/bin/activate ; pip install -r zendesk-publish-script/requirements.txt
if [ $? -ne 0 ] ; then
echo "Failed to make a virtualenv with the proper modules"
exit 1
fi
# Get all the files that have changed since the last time the script published
# to zendesk
files="`git diff --name-only $GIT_PREVIOUS_SUCCESSFUL_COMMIT $GIT_COMMIT`"
# If a file is an image, add the places where it is referenced to $files
for file in $files ; do
if `echo "$file" | egrep -i '\.png$|\.jpg$' > /dev/null` ; then
file_name="`basename $file`"
affected_files="`grep -R $file_name source/* | cut -d ':' -f1`"
files="$(echo -e "${files}\n${affected_files}")"
fi
done
files="`echo "$files" | sort -u`"
for file in $files ; do
if [ -e "$file" ] ; then
# if the file extension is .rst and it is not "index.rst", get the
# location it built to and publish it to the section specified in the
# file "section_id.txt" in the rst file's directory
if `echo "$file" | egrep '^source/.*\.rst$' > /dev/null` && ! `echo "$file" | egrep '\/index\.rst$' > /dev/null` && ! `echo "$file" | egrep '\/common\/.*\.rst$' > /dev/null` ; then
html_file="`echo $file | sed 's/^source\(.*\).rst$/build\/html\1\.html/'`"
echo "$html_file"
dir="`dirname $file`"
if [ -f "${dir}/section_id.txt" ] ; then
section_id="$( cat "${dir}/section_id.txt" )"
elif [ -f "${dir}/../section_id.txt" ] ; then
section_id="$( cat "${dir}/../section_id.txt" )"
fi
if [ -z "$section_id" ] ; then
echo "Cannot find the section id for file $file"
exit 1
fi
python zendesk-publish-script/publish.py "$html_file" "$section_id"
if [ $? -ne 0 ] ; then
exit 1
fi
fi
fi
done
git clone https://github.com/dreamhost/zendesk-pull-article-id
python zendesk-pull-article-id/get_metadata.py