forked from datamicroscopes/release
/
fabfile.py
75 lines (58 loc) · 2.04 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
import sys
import yaml
from fabric import api as fab
from sh import git
TRAVIS_YAML = 'travis.yml'
WARNING = """
#############################################################
# WARNING: .travis.yml is automatically generated by fabric.
# Please modify travis.yml if you want your changes to stick.
#############################################################
"""
@fab.task
def release_all(channel="main"):
"""Release datamicroscopes to Anaconda.org for OS X and Linux"""
release_osx(channel)
release_linux(channel)
@fab.task
def release_osx(channel="main"):
"""Release datamicroscopes to Anaconda.org for OS X"""
_release('objective-c', "Release OS X", channel)
@fab.task
def release_linux(channel="main"):
"""Release datamicroscopes to Anaconda.org for Linux"""
_release('python', "Release Linux", channel)
def _is_dirty():
return "" != git.status(porcelain=True).strip()
def _generate_yaml(language, channel):
with open(TRAVIS_YAML, "r") as f:
travis = yaml.load(f)
travis['language'] = language
travis['env']['global'].append('ANACONDA_CHANNEL={}'.format(channel))
with open('.travis.yml', 'w') as f:
current = yaml.dump(travis)
f.write(WARNING + current)
def _release(language, message, channel):
print message, "...",
if _is_dirty():
sys.exit("Repo must be in clean state before deploying. Please commit changes.")
_generate_yaml(language, channel)
if _is_dirty():
git.add('.travis.yml')
git.commit(m=message, allow_empty=True)
git.pull(rebase=True)
git.push()
print "done."
@fab.task
def update():
"""Update all submodules to Github versions"""
if _is_dirty():
sys.exit("Repo must be in clean state before updating. Please commit changes.")
git.submodule.update(remote=True, rebase=True)
if _is_dirty():
print "Updated repositories:"
print git.status(porcelain=True).strip()
git.add(all=True)
git.commit(m="Update submodules to origin")
else:
sys.exit('Nothing to update.')