-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
book_deploy.sh
executable file
·56 lines (47 loc) · 1.75 KB
/
book_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
#!/bin/bash
#
# Deploy the PDF, HTML, EPUB files of an Underscore book (source)
# into another Git repository (target)
#
set -e
# Configuration
# 1. The key for writing into the other repository.
# This is committed to the repo, encrypted by Travis,
# with filename extension '.enc'.
export KEY_FILENAME="book_deploy_rsa"
# 2. The branch we deploy from.
# Only deploy for non-PR commits to this branch.
export DEPLOY_BRANCH="develop"
# 3. Folder inside target of where to place the artifacts:
export TARGET_DIR=books/scala-with-cats/
# 4. Commit message prefix (for the "books" repository)
export COMMIT_PREFIX="deploy scala with cats via travis"
# End of configuration
if [[ "${TRAVIS_PULL_REQUEST}" == "false" && "${TRAVIS_BRANCH}" == "${DEPLOY_BRANCH}" ]]; then
echo "Starting deploy to Github Pages"
mkdir -p "~/.ssh"
echo -e "Host github.com\n\tStrictHostKeyChecking no\nIdentityFile ~/.ssh/${KEY_FILENAME}\n" >> ~/.ssh/config
cp ${KEY_FILENAME} ~/.ssh/${KEY_FILENAME}
chmod 600 ~/.ssh/${KEY_FILENAME}
git config --global user.email "hello@underscore.io"
git config --global user.name "Travis Build"
export SRC_DIR=`pwd` # e.g., /home/travis/build/underscoreio/insert-book-name-here
export TEMP_DIR=/tmp/dist
mkdir -p $TEMP_DIR
cd $TEMP_DIR
git clone git@github.com:underscoreio/books.git
mkdir -p $TARGET_DIR
cd $TARGET_DIR
cp $SRC_DIR/dist/*.pdf .
cp $SRC_DIR/dist/*.html .
cp $SRC_DIR/dist/*.epub .
git add .
git commit -m "$COMMIT_PREFIX $TRAVIS_JOB_NUMBER $TRAVIS_COMMIT [ci skip]"
git push git@github.com:underscoreio/books.git master:master
rm -rf $TEMP_DIR
else
echo "Not deploying:"
echo "TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST"
echo "TRAVIS_BRANCH=$TRAVIS_BRANCH"
echo "DEPLOY_BRANCH=$DEPLOY_BRANCH"
fi