-
Notifications
You must be signed in to change notification settings - Fork 75
/
deploy-ghpages.py
executable file
·40 lines (34 loc) · 1.42 KB
/
deploy-ghpages.py
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
"""
Travis CI Script for generating libdoc for robotpageobjects.Page and publishing it
"""
from os import getenv, chdir
from re import sub
from subprocess import check_output, check_call
from tempfile import mkdtemp
from shutil import rmtree
if getenv('TRAVIS_REPO_SLUG') != 'ncbi/robotframework-pageobjects':
print "Repo is a fork, not building docs"
exit()
if getenv('TRAVIS_BRANCH') != 'master':
print "Branch is not master, not building docs"
exit()
if getenv('TRAVIS_PULL_REQUEST') != 'false':
print "Pull request detected, not building docs"
exit()
repo = check_output("git config remote.origin.url", shell=True)
repo = sub(r'^git:', 'https:', repo).strip()
deploy_url = sub(r'https://', 'https://%s@' % getenv('GIT_TOKEN'), repo)
deploy_branch = 'gh-pages'
rev = check_output("git rev-parse HEAD", shell=True).strip()
dir = mkdtemp()
check_call("git clone --branch %s %s %s" % (deploy_branch, repo, dir), shell=True)
chdir(dir)
check_call("python -m robot.libdoc robotpageobjects.Page index.html", shell=True)
print "Docs built successfully"
check_call("git config user.name '%s'" % getenv('GIT_NAME'), shell=True)
check_call("git config user.email '%s'" % getenv('GIT_EMAIL'), shell=True)
check_call("git commit -m 'Built from %s' index.html" % rev, shell=True)
check_call("git push -q %s %s" % (deploy_url, deploy_branch), shell=True)
chdir(getenv('TRAVIS_BUILD_DIR'))
rmtree(dir)
print "Docs pushed successfully"