-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
163 lines (135 loc) · 3.59 KB
/
tasks.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from invoke import task
import os
import webbrowser
@task(aliases=("list", "lsit", "ist", "-list", "lis", "li"))
def _dash_dash_list(c):
"""
because i forget --list often and fixz my ttypos
"""
c.run("invoke --list")
@task(aliases=("gh", "repo", "remote", "web"))
def github(c):
"""
opens the GitHub website for this project in default browser
"""
SITE = "https://github.com/brainwriting/brainwriting.github.io"
print("Opening...", SITE)
webbrowser.open(SITE)
@task(aliases=("ghd", "desktop"))
def github_desktop(c):
"""
opens the GitHub Desktop app <yes i am *that* lazy>. macOS only.
"""
c.run("open -a 'GitHub Desktop'")
@task(aliases=("usage", "examples"))
def print_examples(c):
"""
prints example usage
"""
usage = """
SEE LIST OF TASKS:
$ invoke --list
OR
$ invoke -l
HELP:
$ invoke --help {task_from_list}
BUILD:
$ invoke build -c
$ invoke build --clean
HI:
$ invoke hi Name
$ invoke hi --name Name
$ invoke hi --name=Name
$ invoke hi -n Name
$ invoke hi -nName
"""
print(usage)
@task(help={"name": "Name of the person to say hi to."})
def hi(c, name, help=False):
"""
Say hi to someone.
"""
print("Hi {}!".format(name))
@task
def clean(c):
"""
Remove old build files
"""
print("Cleaning!")
c.run("echo ./clean.sh")
@task(clean)
def build(c):
"""
Build the executable
"""
print("Building!")
c.run("echo ./build.sh")
@task
def deploy(c):
"""
Deploy on a server
"""
print("Deploying!")
cwd = os.getcwd()
if cwd[-3:] == "api":
c.run("./deploy.sh")
return
os.chdir("api")
c.run("./deploy.sh")
@task(aliases=("format", "black", "lint"))
def black_auto_format(c):
"""
Make the code look nice.
"""
print("Formatting!")
cwd = os.getcwd()
if cwd[-3:] == "api":
os.chdir("..")
c.run("./format.sh")
return
c.run("./format.sh")
@task
def docker(c):
"""
Docker build && docker run
"""
c.run("./docker_build.sh")
# http://www.pyinvoke.org/faq.html#running-local-shell-commands-run
c.run("./docker_run.sh", pty=True)
@task(aliases=("heroku", "h", "hd"))
def heroku_deploy(c):
"""
Deploy to heroku.
Simply follows instructions here...
https://devcenter.heroku.com/articles/container-registry-and-runtime#getting-started
"""
UH_OH_MSG = "\n\n\nuh oh, I forgot to set my secrets locally."
UH_OH_MSG += "\nrun ```cat .export_env_vars``` for export statements"
UH_OH_MSG += "\nif that file does not exist then try running"
UH_OH_MSG += "\n```invoke heroku-config```"
UH_OH_MSG += "\nif heroku is not setup either..."
UH_OH_MSG += "\nI should make a tutorial for this..."
assert os.environ.get("api_key", None) is not None, UH_OH_MSG
c.run("heroku container:login")
c.run(
"heroku container:push -a brainwriting web --arg api_key,client_id,client_secret,project_id,spreadsheet_id,spreadsheet_range"
) # noqa
c.run("heroku container:release -a brainwriting web")
c.run("heroku open -a brainwriting")
pass
@task(aliases=("heroku-env", "he", "heroku-config", "heroku-vars", "vars"))
def get_all_heroku_config_vars(c):
print("Getting environment variables...")
var_names = [
"api_key",
"client_id",
"client_secret",
"project_id",
"spreadsheet_id",
"spreadsheet_range",
]
cmd = "heroku config:get -a brainwriting {}"
for v in var_names:
print("{}".format(v))
c.run(cmd.format(v))
print()