/
deploy.py
65 lines (56 loc) · 1.74 KB
/
deploy.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
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
# -*- coding: utf-8 -*-
import logging
import os
import click
from .main import main
from .tools import check_call
_logger = logging.getLogger(__name__)
@click.command(
help="Deploy sphinx docs to gh_pages branch by pulling from output dir."
)
@click.option(
'-b', '--branches',
help='Comma separated list of branches to build on',
default='master',
show_default=True
)
@click.option(
'-c', '--cname',
help='Write a CNAME file with the given CNAME.'
)
@click.option(
'-m', '--message',
default='Update documentation',
help='The commit message to use on the target branch.',
show_default=True
)
@click.pass_context
def deploy(ctx, branches, cname, message):
"""
Deploy built docs to gh-pages, uses ``GH_TOKEN`` for pushing built
documentation files located in *target/doc* to gh
"""
branch = os.environ['TRAVIS_BRANCH']
pr = os.environ['TRAVIS_PULL_REQUEST']
token = os.environ.get('GH_TOKEN')
repo = os.environ['TRAVIS_REPO_SLUG']
tag = os.environ['TRAVIS_TAG']
outdir = ctx.obj['outdir']
if token is None:
click.ClickException("ERROR: GH_TOKEN is missing!")
branches = branches.split(',')
if (branch in branches and (pr == 'false')) or tag:
remote = 'https://%s@github.com/%s.git' % (token, repo)
call = ['ghp-import', '-p', '-f', '-n', '-r', remote]
if cname:
call.extend(['-c', cname])
if message:
call.extend(['-m', message])
call.append(outdir)
_logger.info('uploading docs...')
check_call(call)
_logger.info('success!')
else:
_logger.info("Deploy triggered for non-master branch '%s': skipping "
"deploy", branch)
main.add_command(deploy)