/
deploy-to-gh-pages.sh
100 lines (82 loc) · 3.44 KB
/
deploy-to-gh-pages.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
# Exit with nonzero exit code if anything fails.
set -e
# Define repository relative GitHub address.
repositoryRelativeGitHubAddress="Flexberry/flexberry-gis-test-stand-ember-frontend"
# Clone project into 'repository' subfolder && move to it.
echo "Prepare for deploy to gh-pages."
echo "Clone ${repositoryRelativeGitHubAddress} repository & checkout latest version of gh-pages branch."
git clone --recursive "https://github.com/${repositoryRelativeGitHubAddress}.git" repository
cd repository
# Remember existing remote branches in array.
existingRemoteBranches=()
for branch in `git branch -r`;
do
if [ "${branch}" != "origin/HEAD" ] && [ "${branch}" != "origin/gh-pages" ] && [ "${branch}" != "->" ];
then
echo "Add remote branch ${branch} into existing branches array"
existingRemoteBranches=("${existingRemoteBranches[@]}" "${branch#origin/}")
fi
done
existingRemoteBranches=($(echo "${existingRemoteBranches[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
# Checkout gh-pages brunch & pull it's latest version.
git checkout gh-pages
git pull
# Itarate over 'gh-pages'-branch directories (except 'stylesheets' and 'images').
shopt -s dotglob
find * -prune -type d | while read directory; do
if [ "${directory}" != "stylesheets" ] && [ "${directory}" != "images" ] && [ "${directory}" != ".git" ];
then
branch="${directory}"
branchExists=false
if [ $(echo ${existingRemoteBranches[@]} | grep -o "${branch}" | wc -w) -ne 0 ];
then
branchExists=true
fi
# Remove directories for those branches which doesn't exist anymore.
if [ $branchExists = false ];
then
echo "Remove results of previous deploy (for ${branch} branch), because it doesn't exist anymore."
rm -rf "${branch}"
fi
fi
done
# Remove results of previous deploy (for current branch) & recreate directory.
echo "Remove results of previous deploy (for ${TRAVIS_BRANCH} branch)."
rm -rf "${TRAVIS_BRANCH}"
mkdir "${TRAVIS_BRANCH}"
# Copy builded ember application from 'dist' folder into 'repository/${TRAVIS_BRANCH}'.
echo "Copy builded ember application (for ${TRAVIS_BRANCH} branch)."
cp -r ../dist/* "${TRAVIS_BRANCH}"
# Remove previously created index.html page and recreate it with links to application versions related to all existing remote brunches.
rm -rf index.html
cp index.hbs index.html
for branch in "${existingRemoteBranches[@]}"
do
branchDescription=""
if [ "${branch}" = "master" ];
then
branchDescription="Stable version"
fi
if [ "${branch}" = "develop" ];
then
branchDescription="Bleeding edge version"
fi
if [ "${branch}" = "test" ];
then
branchDescription="Temporal testing version"
fi
branchLink="<a href=\"${branch}\/index.html\">http:\/\/flexberry.github.io\/flexberry-gis-test-stand-ember-frontend\/${branch}\/<\/a>"
branchTableRow="<tr>\n<td>${branch}<\/td>\n<td>${branchDescription}<\/td>\n<td>${branchLink}<\/td>\n<\/tr>\n{{branches}}"
sed -i -e "s/{{branches}}/${branchTableRow}/g" index.html
done
sed -i -e "s/{{branches}}//g" index.html
# Configure git.
git config user.name "Flexberry-man"
git config user.email "mail@flexberry.net"
echo "Commit & push changes."
git add --all
git commit -m "Update gh-pages for ${TRAVIS_BRANCH} branch"
# Redirect any output to /dev/null to hide any sensitive credential data that might otherwise be exposed.
git push --force --quiet "https://${GH_TOKEN}@github.com/${repositoryRelativeGitHubAddress}.git" > /dev/null 2>&1
echo "Deploy to gh-pages finished."