-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit.sh
executable file
·67 lines (56 loc) · 1.86 KB
/
commit.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
#!/bin/sh -e
# Usage: commit.sh [commit message]
SOURCE_DIR="$( cd "$( dirname "$0" )" && pwd )"
#PUBLISH_DIR="$SOURCE_DIR/public"
PUBLISH_DIR="$DEST_PATH"
SOURCE_BRANCH=master
PUBLISH_BRANCH=gh-pages
# OpenShift support
if [ -n "$OPENSHIFT_APP_NAME" ]; then
echo "Configuring git on OpenShift"
export GIT_DIR="${OPENSHIFT_HOMEDIR}git/${OPENSHIFT_APP_NAME}.git"
mkdir -p "$OPENSHIFT_DATA_DIR/.ssh"
echo "ssh -o UserKnownHostsFile=$OPENSHIFT_DATA_DIR/.ssh/known_hosts -i $OPENSHIFT_APP_SSH_KEY \$@" > /tmp/git_ssh
chmod +x /tmp/git_ssh
export GIT_SSH=/tmp/git_ssh
else
export GIT_DIR="$SOURCE_DIR/.git"
fi
COMMIT_MESSAGE="$@"
if [ -z "$COMMIT_MESSAGE" ]; then
COMMIT_MESSAGE="$(git log -1 --pretty=%B) (built by $0)"
fi
# ensure the publish branch is up to date and in place in the publish folder
git fetch --force origin "${PUBLISH_BRANCH}:${PUBLISH_BRANCH}"
if [ -n "$REBUILD_FIRST" -o ! -d "$PUBLISH_DIR/.git" ]; then
echo "Building preview dir for repository."
rm -rf "$PUBLISH_DIR"
git clone --shared --no-checkout "$GIT_DIR" "$PUBLISH_DIR"
echo "ref: refs/heads/${PUBLISH_BRANCH}" > "${PUBLISH_DIR}/.git/HEAD"
(
cd "$PUBLISH_DIR"
unset GIT_DIR
git checkout --force "$PUBLISH_BRANCH" || git checkout --orphan "$PUBLISH_BRANCH"
rm -rf *
)
# build with a script that will terminate
gulp build ${DEBUG_COLORS:+--color}
fi
# commit the result
(
echo "Committing current preview dir."
cd "$PUBLISH_DIR"
unset GIT_DIR
git add --all .
git commit -m "$COMMIT_MESSAGE"
git push origin "${PUBLISH_BRANCH}:${PUBLISH_BRANCH}"
)
if [ -n "$PUBLISH_IMMEDIATELY" ]; then
echo "Publishing immediately."
./publish.sh "$PUBLISH_BRANCH"
fi
# upload result
if [ -n "$OPENSHIFT_APP_NAME" ]; then
echo "Uploading results."
git push origin "${PUBLISH_BRANCH}:${PUBLISH_BRANCH}"
fi