-
Notifications
You must be signed in to change notification settings - Fork 1
/
push_ghpages.sh
84 lines (70 loc) · 2.19 KB
/
push_ghpages.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
83
84
#! /bin/bash
# This script is used to automate the process of push to the branch gh-pages from github.
# The main purpose of the "manually" deploying is to allow the use of a "Thirt Party Plugin", that don't work with automatic deploy.
#
# This script dependents from a branch previously created "gh-pages" on github and the folder "_site" were the build content must be.
#
# Description:
# Fist it creates a folder called "PUSH_FOLDER",
# then it's cloned only the branch "gh-pages" from github.
# The directory is temporaly changed to "PUSH_FOLDER".
# In the directory it
BUILD_FOLDER="_site";
PUSH_FOLDER="_site_ghpages";
COMMIT_MESSAGE=$1
#Remove all the content from the "PUSH_FOLDER".
function removeAllContentFromPushFolder(){
echo $(rm -r $PUSH_FOLDER/*);
}
#Create the folder "PUSH_FOLDER".
function createFolderToPush(){
echo "$(mkdir $PUSH_FOLDER)"
}
#Copy all the content from the folder _site to PUSH_FOLDER.
function copySiteToFolder(){
echo "$(cp -r $BUILD_FOLDER/. $PUSH_FOLDER)"
}
#Clone only the branch "gh-pages" to the folder "PUSH_FOLDER".
function cloneGhpages(){
echo "$(git clone --branch gh-pages `git config remote.origin.url` $PUSH_FOLDER)"
}
function prepareThePushFolder(){
if [[ -d ./$PUSH_FOLDER ]]
then
#Remove all the content from the folder "PUSH_FOLDER".
removeAllContentFromPushFolder
else
#Create the folder "PUSH_FOLDER" if it doesn't exist.
createFolderToPush
#Call the function that clone the branch "gh-pages" to the folder "PUSH_FOLDER".
cloneGhpages
fi
#Call the function that copy all the content from the folder _site to "PUSH_FOLDER".
copySiteToFolder
}
function changeDirectoryToGhpages(){
CHANGE_TO_SITE= cd $PUSH_FOLDER
echo $CHANGE_TO_SITE;
}
function setMessageCommit(){
if ! [ "$COMMIT_MESSAGE" ]
then
COMMIT_MESSAGE='Automatic Commit'
else
echo "$COMMIT_MESSAGE"
fi
}
function pushBranchGhpages(){
git add .
git commit -m "$COMMIT_MESSAGE"
git push
}
function changeDirectoryBack(){
BACKFOLDER= cd ..
echo $BACKFOLDER
}
prepareThePushFolder
changeDirectoryToGhpages
setMessageCommit
pushBranchGhpages
changeDirectoryBack