/
fabfile.py
83 lines (58 loc) · 1.58 KB
/
fabfile.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import getpass
from fabric import task
from invocations.console import confirm
from invoke import Responder
from invoke.exceptions import Exit
SSH_PASS = ''
def get_ssh_pass_resp():
global SSH_PASS
if not SSH_PASS:
SSH_PASS = getpass.getpass("What's your private key passphrase?")
return Responder(pattern="Enter passphrase for key .*", response=f'{SSH_PASS}\n')
@task
def test(c):
with c.prefix("source env/bin/activate"):
result = c.run("nosetests -v", warn=True)
if not result.ok and not confirm("Tests failed. Continue?"):
raise Exit()
@task
def commit(c):
message = input("Enter a git commit message: ")
command = "git add . && git commit -am \"{}\"".format(message)
c.run(command)
@task
def push(c):
c.run("git branch")
branch = input("Branch for push:") or "master"
c.run(f"git push origin {branch}", pty=True, watchers=[get_ssh_pass_resp()])
@task
def pull(c):
c.run("git pull", pty=True, watchers=[get_ssh_pass_resp()])
@task
def heroku(c):
c.run("git push heroku master")
@task
def heroku_test(c):
with c.prefix("source env/bin/activate"):
c.run("/snap/bin/heroku run nosetests -v")
@task
def prepare(c):
test(c)
commit(c)
push(c)
@task
def deploy(c):
pull(c)
test(c)
commit(c)
heroku(c)
heroku_test(c)
@task
def rollback(c):
with c.prefix("source env/bin/activate"):
c.run("/snap/bin/heroku rollback", pty=True)
# for debugging
if __name__ == "__main__":
from invoke import Context, Config
con = Context(config=Config())
test(con)