Skip to content

Commit deb2d4f

Browse files
Introduced a script to publish the "docs" folder to the gh-pages branch. The script can also be run locally to push the gh-pages of forks
1 parent 135c1da commit deb2d4f

File tree

3 files changed

+251
-0
lines changed

3 files changed

+251
-0
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ language: node_js
22
node_js:
33
- '4'
44

5+
env:
6+
global:
7+
- ENCRYPTION_LABEL: "aa286ccd339e"
8+
- COMMIT_AUTHOR_EMAIL: "[email protected]"
9+
510
before_install:
611
- 'git checkout -B $TRAVIS_BRANCH' # Reconcile detached HEAD
712
- 'npm install -g bower grunt-cli'
@@ -14,6 +19,7 @@ script:
1419

1520
after_success:
1621
- sh -x ./scripts/publish.sh
22+
- ./scripts/publish-ghpages.sh -t docs
1723

1824
# OpenShift expects its deployment branch to be "master-dist". This can be changed using:
1925
# rhc app-configure patternfly/angular --deployment-branch master-dist

deploy-key.enc

3.17 KB
Binary file not shown.

scripts/publish-ghpages.sh

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit -o nounset
4+
5+
####################################
6+
# repo specific variables
7+
####################################
8+
TRIGGER_REPO_SLUG="patternfly/angular-patternfly"
9+
TRIGGER_REPO_BRANCH="master"
10+
####################################
11+
####################################
12+
13+
SCRIPT=`basename $0`
14+
ACTION="Manual"
15+
REPO_NAME="origin"
16+
SOURCE_BRANCH=`git rev-parse --abbrev-ref HEAD`
17+
18+
RED='\033[0;31m'
19+
YELLOW='\033[1;33m'
20+
GREEN='\033[1;32m'
21+
NC='\033[0m' # No Color
22+
23+
echoHeader () {
24+
echo
25+
echo -e "${YELLOW}################################################################################${NC}"
26+
echo -e "${GREEN}${@}${NC}"
27+
echo -e "${YELLOW}################################################################################${NC}"
28+
}
29+
30+
confirm () {
31+
# call with a prompt string or use a default
32+
QUESTION="${1:-Are you sure? [y/N]} "
33+
echo -e -n $QUESTION
34+
read -r RESPONSE
35+
case $RESPONSE in
36+
[yY][eE][sS]|[yY])
37+
true
38+
;;
39+
*)
40+
false
41+
;;
42+
esac
43+
}
44+
45+
setUserInfo () {
46+
git config --global user.name "patternfly-build"
47+
git config --global user.email "[email protected]"
48+
git config --global push.default simple
49+
}
50+
51+
getDeployKey () {
52+
# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
53+
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
54+
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
55+
ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
56+
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
57+
openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in deploy_key.enc -out deploy_key -d
58+
chmod 600 deploy_key
59+
eval `ssh-agent -s`
60+
ssh-add deploy_key
61+
}
62+
63+
checkTriggerRepo () {
64+
echo "$TRAVIS_REPO_SLUG $TRIGGER_REPO_SLUG $TRIGGER_REPO_BRANCH"
65+
if [ "${TRAVIS_REPO_SLUG}" = "${TRIGGER_REPO_SLUG}" ]; then
66+
echo "This action is running against ${TRIGGER_REPO_SLUG}."
67+
if [ -z "${TRAVIS_TAG}" -a "${TRAVIS_BRANCH}" != "${TRIGGER_REPO_BRANCH}" ]; then
68+
echo "This commit was made against ${TRAVIS_BRANCH} and not the ${TRIGGER_REPO_BRANCH} branch. Aborting."
69+
exit 1
70+
fi
71+
else
72+
echo "This action is not running against ${TRIGGER_REPO_SLUG}. Aborting."
73+
exit 1
74+
fi
75+
}
76+
77+
inferRepo () {
78+
REPO=`git config remote.${REPO_NAME}.url`
79+
SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
80+
echo "Inferred REPO ${SSH_REPO}"
81+
}
82+
83+
confirmRepo () {
84+
confirm "${YELLOW}Push ${SITE_FOLDER} to repo ${SSH_REPO}/gh-pages? [y/N] ${NC}"
85+
return $?
86+
}
87+
88+
checkRemoteBranchExists () {
89+
BRANCH="${1:-gh-pages}"
90+
EXISTING=`git ls-remote --heads ${REPO} ${BRANCH}`
91+
echo $EXISTING
92+
}
93+
94+
cleanSite () {
95+
if [ -d "github.io" ]; then
96+
rm -rf github.io
97+
fi
98+
}
99+
100+
cleanBranch () {
101+
# check if the branch exists without triggering errexit
102+
git rev-parse --verify --quiet gh-pages-deploy 1> /dev/null && rc=$? || rc=$?
103+
if [ "$rc" = 0 ]; then
104+
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
105+
if [ "$CURRENT_BRANCH" = "gh-pages-deploy" ]; then
106+
git checkout $SOURCE_BRANCH
107+
fi
108+
git branch -D gh-pages-deploy
109+
fi
110+
}
111+
112+
cloneSite () {
113+
git clone --branch gh-pages $SSH_REPO github.io
114+
}
115+
116+
copySite () {
117+
echo rsync -q -rav --delete --exclude .git ${SITE_FOLDER} github.io
118+
rsync -q -rav --delete --exclude .git ${SITE_FOLDER}/ github.io/
119+
}
120+
121+
pushSite () {
122+
SHA=`git rev-parse HEAD`
123+
git -C github.io add . -A
124+
if [ -z "$(git -C github.io status --porcelain)" ]; then
125+
echo -e "${YELLOW}Site directory clean, no changes to commit.${NC}"
126+
else
127+
echo -e "${YELLOW}Changes in site directory, committing changes.${NC}"
128+
git -C github.io commit -q -a -m "Added files from commit #${SHA} "
129+
echo -e "Pushing commit ${SHA} to repo ${SSH_REPO}."
130+
confirmRepo && rc=$? || rc=$?
131+
if [ "$rc" = 0 ]; then
132+
git -C github.io push $SSH_REPO gh-pages:gh-pages
133+
fi
134+
fi
135+
}
136+
137+
splitSite () {
138+
git checkout -b gh-pages-deploy
139+
git add -f ${SITE_FOLDER}
140+
git commit -q -m "Added ${SITE_FOLDER} folder"
141+
142+
SHA=`git subtree split --prefix ${SITE_FOLDER} gh-pages-deploy`
143+
echo -e "Pushing commit ${SHA} to repo ${SSH_REPO}."
144+
confirmRepo && rc=$? || rc=$?
145+
if [ "$rc" = 0 ]; then
146+
git push ${SSH_REPO} ${SHA}:refs/heads/gh-pages --force
147+
fi
148+
}
149+
150+
deploySite () {
151+
if [ "$SOURCE_BRANCH" = "gh-pages" -o "$SOURCE_BRANCH" = "gh-pages-deploy" ]; then
152+
echo -e "${RED}Error: cannot deploy from the gh-pages branch. Please checkout a different branch."
153+
fi
154+
155+
git checkout ${SOURCE_BRANCH}
156+
inferRepo $REPO_NAME
157+
EXISTING=`checkRemoteBranchExists gh-pages`
158+
if [ -n "$EXISTING" ]; then
159+
echo -e "${GREEN}### gh-pages branch exists, pushing updates${NC}"
160+
cleanSite
161+
cloneSite
162+
copySite
163+
pushSite
164+
cleanSite
165+
else
166+
echo -e "${GREEN}### gh-pages branch does not exist, splitting branch${NC}"
167+
cleanBranch
168+
splitSite
169+
cleanBranch
170+
fi
171+
}
172+
173+
manualDeploy () {
174+
deploySite
175+
}
176+
177+
travisDeploy () {
178+
checkTriggerRepo
179+
setUserInfo
180+
getDeployKey
181+
deploySite
182+
}
183+
184+
checkSiteFolderExists () {
185+
if [ -z $SITE_FOLDER ]; then
186+
echo -e "${RED}Error: Please specify a folder to publish.${NC}"
187+
usage
188+
exit -1
189+
fi
190+
191+
if [ ! -d ${SITE_FOLDER} ]; then
192+
echo -e "${RED}Error: The '${SITE_FOLDER}' folder does not exsit. Run the build script to generate it.${NC}"
193+
exit -1
194+
fi
195+
}
196+
197+
parseOpts() {
198+
while getopts htr:b: OPT "$@"; do
199+
case $OPT in
200+
h) usage; exit 0;;
201+
t) ACTION="Travis";;
202+
r) REPO_NAME=$OPTARG;;
203+
b) SOURCE_BRANCH=$OPTARG;;
204+
esac
205+
done
206+
207+
shift $((OPTIND-1))
208+
SITE_FOLDER="${1:- }"
209+
}
210+
211+
usage () {
212+
cat <<- EEOOFF
213+
214+
This script will publish files to the gh-pages branch of your repo.
215+
216+
$SCRIPT [option] folder
217+
218+
Example: $SCRIPT
219+
220+
OPTIONS:
221+
h Display this message
222+
t Perform a deploy from travis, using a travis encrypted key
223+
r Repository name to publish to (deafult: origin)
224+
b Source branch to publish from (default: master)
225+
226+
EEOOFF
227+
}
228+
229+
main () {
230+
parseOpts "$@"
231+
232+
checkSiteFolderExists
233+
234+
echoHeader "${ACTION} deploy of ${REPO_NAME}/${SOURCE_BRANCH}:${SITE_FOLDER} to gh-pages"
235+
236+
case $ACTION in
237+
Manual)
238+
manualDeploy "$@"
239+
;;
240+
Travis)
241+
travisDeploy
242+
esac
243+
}
244+
245+
main "$@"

0 commit comments

Comments
 (0)