-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
deploy.sh
executable file
·69 lines (55 loc) · 1.93 KB
/
deploy.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
#!/bin/bash
# Exit with nonzero exit code if anything fails
set -e
REPO=`git config remote.origin.url`
SSH_REPO=${REPO/https:\/\/github.com\//[email protected]:}
SHA=`git rev-parse --verify HEAD`
# Only build and deploy docs on a specific node version
if [[ $TRAVIS_NODE_VERSION != $DEPLOY_ON_NODE_VERSION ]]; then
echo "Current Node.js versions doesn’t match ($TRAVIS_NODE_VERSION != $DEPLOY_ON_NODE_VERSION). Skipping generating and deploying the docs."
exit 0
fi
# Only build and deploy docs when the current build is for a Git tag.
if [[ $TRAVIS_TAG == "" ]]; then
echo "Not a build for a Git tag. Skipping generating and deploying the docs."
exit 0
fi
# Create $DOCS_DIR
mkdir $DOCS_DIR
echo -e "Created directory $DOCS_DIR\n"
# Change directory to $DOCS_DIR
cd $DOCS_DIR
echo "Changed directory to: "
pwd
echo -e ""
# Clone the existing gh-pages into $DOCS_DIR
git clone $REPO .
echo -e "Cloned $REPO\n"
git checkout $TARGET_BRANCH
# Clean out existing contents
rm -rf **
echo -e "Cleaned out existing contents of $DOCS_DIR\n"
# Generate docs in $TRAVIS_BUILD_DIR
cd $TRAVIS_BUILD_DIR
npm run doc
echo -e "Generated docs\n"
# Change directory to $DOCS_DIR
cd $DOCS_DIR
# Exit if there are no changes to the generated content
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to the output on this run; exiting."
exit 0
fi
# Git setup
git config user.name $COMMIT_AUTHOR_NAME
git config user.email $COMMIT_AUTHOR_EMAIL
# Commit the new of the new version
git add --all .
git commit -m "Deploy docs to GitHub Pages ($TRAVIS_TAG)"
echo -e "Committed docs to $TARGET_BRANCH\n"
# Now that we're all set up, we can push.
# Info: Any command that using GH_OAUTH_TOKEN must pipe the output to /dev/null
# to not expose your oauth token
git push https://${GH_OAUTH_TOKEN}@github.com/${GH_OWNER}/${GH_PROJECT_NAME} HEAD:$TARGET_BRANCH > /dev/null 2>&1
echo -e "Pushed changes to $TARGET_BRANCH\n"
echo "We are done ✌(-‿-)✌"