forked from mattbdean/JRAW
-
Notifications
You must be signed in to change notification settings - Fork 11
/
upload_docs.sh
executable file
·65 lines (52 loc) · 2.09 KB
/
upload_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
#!/bin/bash
set -e
shopt -s extglob
## Where the docs will be found after building them in master
BUILD_DOC="build/docs/javadoc/"
## Name of the 'javadoc' folder
DOC_FOLDER=$(basename ${BUILD_DOC})
## First seven characters of the latest commit SHA
COMMIT_SHA=$(git rev-parse --short HEAD --verify)
## Last release (vX.X.X)
LATEST_TAG=$(git describe --abbrev=0 --tags)
## Generic commit message
COMMIT_MSG="Update Javadoc to commit $COMMIT_SHA"
## Where the docs will be placed in the gh-pages branch
OUT_DIR="docs/git"
## Use 'dumb' Gradle output
TERM=dumb
## Where the commit SHA will be placed
VERSION_FILE="$OUT_DIR/version.txt"
# cd into the script's directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIR"
# See if the docs are already uploaded by querying GitHub Pages
latest_version=$(curl "http://thatjavanerd.github.io/JRAW/${VERSION_FILE}")
if [[ ${latest_version} == "${COMMIT_SHA}" ]]; then
echo "Docs already uploaded. Exiting"
exit
fi
# Travis uses the git:// URL. When pushing, GitHub will return an error.
# Use smart HTTP instead. See http://stackoverflow.com/q/7548661/1275092.
git remote set-url origin https://github.com/thatJavaNerd/JRAW
# Fetch the other branches since Travis only clones master
git fetch origin gh-pages:gh-pages
rm -rf "$BUILD_DOC" # Remove all old javadoc
# Build the javadoc and give it a more descriptive title
./gradlew javadoc -Djavadoc-version="commit $COMMIT_SHA ($LATEST_TAG+)"
cp -r "$BUILD_DOC" -r .. # Move the javadoc out of git's reach
git checkout gh-pages
rm -r ${OUT_DIR} # Remove current version of the docs
mkdir -p "$OUT_DIR"
mv ../${DOC_FOLDER}/* "$OUT_DIR" # Move the javadoc to its corresponding folder
rm -r ../${DOC_FOLDER}/ # Remove the temp folder
echo "$COMMIT_SHA" > "$VERSION_FILE" # Update the version
# Configure git
git config user.name "$GIT_NAME"
git config user.email "$GIT_EMAIL"
git config credential.helper "store --file=.git/credentials"
echo "https://$GIT_USER:[email protected]" > .git/credentials
git add --all docs/
git commit -m "$COMMIT_MSG"
git push --set-upstream origin gh-pages
git checkout master