-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis-deploy.sh
executable file
·82 lines (65 loc) · 2.33 KB
/
.travis-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
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# Hightly inspired by https://gist.github.com/domenic/ec8b0fc8ab45f39403dd
# Set the environment to be choosy
set -o errexit
set -o pipefail
set -o nounset
# Configure branches
SOURCE_BRANCH='master'
SOURCE_PATH='org.concrete5.repository/target/repository'
TARGET_BRANCH='gh-pages'
TARGET_PATH='p2'
# Check that the source directory exists
if [ ! -d "${SOURCE_PATH}" ]; then
echo "Source directory ${SOURCE_PATH} not found: skipping deploy."
exit 0
fi
# Check that we are pushing to the right branch
if [ "${TRAVIS_PULL_REQUEST:=}" != 'false' -o "${TRAVIS_BRANCH:=}" != "$SOURCE_BRANCH" ]; then
echo "Not pushing to ${SOURCE_BRANCH}: skipping deploy."
exit 0
fi
# Check that the GitHub encrypted token is defined
if [ -z "${GUTHUB_ACCESS_TOKEN:=}" ]; then
echo 'Missing GUTHUB_ACCESS_TOKEN environment variable.'
# To create it:
# - go to https://github.com/settings/tokens/new
# - create a new token
# - sudo apt install -y build-essential ruby ruby-dev
# - sudo gem install travis
# - travis encrypt -r <owner>/<repo> GUTHUB_ACCESS_TOKEN=<TOKEN>
# - Add to the env setting of:
# secure: "encrypted string"
exit 0
fi
# Setup the destinaton branch settings
REMOTE_ORIGIN=`git config remote.origin.url`
if [[ ! "${REMOTE_ORIGIN}" =~ github.com/(.+)/(.+)\.git$ ]]; then
echo "Failed to analyze remote origin: ${REMOTE_ORIGIN}"
exit 0
fi
REPO_OWNER=${BASH_REMATCH[1]}
REPO_SLUG=${BASH_REMATCH[2]}
# Determine the SHA-1 of the last commit
COMMIT_SHA1=`git rev-parse --verify HEAD`
# Determine the email of the last commit
COMMIT_AUTHOR_EMAIL=`git log -1 --pretty="%cE"`
# Clone the existing gh-pages for this repo into deploy
git clone "${REMOTE_ORIGIN}" deploy
cd deploy
git checkout "${TARGET_BRANCH}"
# Configure git environment
git config user.name 'Travis CI'
git config user.email "${COMMIT_AUTHOR_EMAIL}"
git remote add deploy "https://${GUTHUB_ACCESS_TOKEN}@github.com/${REPO_OWNER}/${REPO_SLUG}.git"
# Remove previous update site contents
rm --recursive --force "${TARGET_PATH}"
# Copy the new update site contents
cp --recursive "../${SOURCE_PATH}" "${TARGET_PATH}"
# Add all the new files to git index
git add --all "${TARGET_PATH}"
# Create the git commit
git commit --message="Update Site refreshed after commit ${COMMIT_SHA1}"
# Push
git push deploy "${TARGET_BRANCH}"
echo 'Deployed.'