Skip to content
This repository was archived by the owner on Jun 28, 2023. It is now read-only.

Commit 745fdfd

Browse files
committed
Add auto deploy docs to gh-pages
1 parent adfe901 commit 745fdfd

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ script:
3535

3636
after_success:
3737
- coveralls
38+
- ./build_doc.py
3839

3940
deploy:
4041
- provider: releases

build_doc.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python3
22

33
from subprocess import check_output
4+
import shlex
5+
import os
46
import logging
57

68

@@ -15,11 +17,16 @@
1517
HTML_DIR = 'html'
1618

1719

18-
def run_cmd(cmd):
19-
logging.info('command: {}'.format(cmd))
20-
result = check_output(cmd.split()).strip()
21-
if result:
20+
def run_cmd(cmd, quiet=False):
21+
if not quiet:
22+
logging.info('command: {}'.format(cmd))
23+
24+
# use shlex to keep quoted substrings
25+
result = check_output(shlex.split(cmd)).strip()
26+
27+
if result and not quiet:
2228
logging.debug(result.decode())
29+
2330
return result
2431

2532

@@ -58,12 +65,37 @@ def update_html():
5865
dst=destination))
5966

6067

68+
def get_commit_message():
69+
return run_cmd('git log -1 --pretty="%s"')
70+
71+
72+
def get_repo_url():
73+
return run_cmd('git remote get-url origin')
74+
75+
76+
def commit_to_github():
77+
run_cmd('pip install -U ghp-import')
78+
msg = get_commit_message().decode()
79+
cmd = 'ghp-import -n -r origin -b gh-pages -m "{}" {}'.format(msg,
80+
HTML_DIR)
81+
run_cmd(cmd)
82+
83+
url = get_repo_url().decode().lstrip('https://')
84+
gh_token = os.environ['GH_TOKEN']
85+
# Please set your GH_TOKEN as Travis CI
86+
cmd = 'git push -fq \
87+
https://{}@{}.git gh-pages:gh-pages'.format(gh_token,
88+
url)
89+
run_cmd(cmd, quiet=True)
90+
91+
6192
def main():
6293
clean_old_build()
6394
build_docstring_rst()
6495
build_html()
6596
duplicate_old_html()
6697
update_html()
98+
commit_to_github()
6799

68100

69101
if __name__ == '__main__':

0 commit comments

Comments
 (0)