-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpublish.sh
109 lines (93 loc) · 2.54 KB
/
publish.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
#!/bin/bash
TMP_DIR=/tmp/publish_$$
mkdir -p $TMP_DIR
cd $TMP_DIR
REPO=$1
VERSION=$2
USER=$GITHUB_USER
PASS=$GITHUB_PASSWORD
EMAIL=$GIT_EMAIL
NAME=$GIT_NAME
if [ -z $USER ]; then
if [ ! -z "$3" ]; then
USER=$3
fi
fi
if [ -z $PASS ]; then
if [ ! -z "$4" ]; then
PASS=$4
fi
fi
if [ -z "$USER" ]; then
echo "Usage: publish.sh <repo> <version> [<gh-user> [gh-password]]" >&2
echo "" >&2
echo " Username/password may also be passed by setting environment variables:" >&2
echo " GITHUB_USER" >&2
echo " GITHUB_PASSWORD" >&2
echo " If no password set then will try to use private key" >&2
echo "" >&2
echo " Git name/email - if not set locally then need to be provided via environment variables:" >&2
echo " GIT_EMAIL" >&2
echo " GIT_NAME" >&2
exit 1
fi
echo "Repository: $REPO"
echo "Version: $VERSION"
echo "Cloning git repos"
USER_PASS=$USER
if [ ! -z $PASS ]; then
USER_PASS=$USER_PASS:$PASS
fi
git clone -b gh-pages https://[email protected]/$REPO.git gh-pages
git clone -b $VERSION https://[email protected]/$REPO.git source
git clone -b $VERSION https://[email protected]/$REPO-documentation.git doco-source-test
git clone -b $VERSION https://[email protected]/$REPO-documentation.git doco-source
cd $TMP_DIR/doco-source-test
bundle exec jekyll build --trace --config _config.yml
RESULT=$?
if [ $RESULT -ne 0 ]; then
exit 1
fi
cd $TMP_DIR
rm -rf doco-source-test
if [ $VERSION == "master" ]; then
echo "Need to parse pom.xml"
# exit 1
fi
# todo: removing old master content? Manual for now
if [ -d gh-pages/$VERSION ]; then
echo "Cleaning out old site content for branch $VERSION"
cd gh-pages
git rm -rf $VERSION
cd ..
fi
PAGES_DIR=gh-pages/$VERSION
if [ $VERSION == "master" ]; then
PAGES_DIR=gh-pages
fi
echo "Generating maven site"
mkdir -p $PAGES_DIR/maven
cd source
mvn -q install -DskipTests=true
mvn -q site:site site:deploy -Dsite.deploy.dir=$TMP_DIR/$PAGES_DIR/maven
cd ..
echo "Copying maven site into place"
rm -rf doco-source/.git
cp -R doco-source/* $PAGES_DIR
echo "Telling git about our changes"
cd gh-pages
# todo: move these to env variables
if [ ! -z $EMAIL ]; then
git config user.email $EMAIL
fi
if [ ! -z $NAME ]; then
git config user.name $NAME
fi
git add -A
echo "Pushing to live"
git commit -m "Pushing latest site updates"
# the sed is so we don't show the password in the log
git push https://[email protected]/$REPO.git gh-pages 2>&1 | sed -e 's/\/\/.*\:.*@github\.com/\/\/github\.com/'
cd ..
echo "Cleanup.."
rm -rf $TMP_DIR