-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleverscript
More file actions
executable file
·72 lines (57 loc) · 2.53 KB
/
Copy pathcleverscript
File metadata and controls
executable file
·72 lines (57 loc) · 2.53 KB
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
#!/usr/bin/env python
import argparse
import os
import re
import subprocess
import tempfile
def run(cmd):
print("----------------------------------------------------------------------")
print("%s" % cmd)
print("----------------------------------------------------------------------")
if os.system(cmd) != 0:
raise Exception(cmd)
def scrub(s):
return re.sub('[^A-Za-z0-9]', '-', s)
parser = argparse.ArgumentParser(description="Run a clever script.")
parser.add_argument("cleverscript", nargs="?", default=None, help="cleverscript to run, e.g., \"deploy-to-production\" runs \".cleverscript-deploy-to-production\" (default is to run default \".cleverscript\" if exists)")
parser.add_argument("--cleverbuild_number", help="the cleverbuild_number to run the cleverscript (default is latest cleverbuild_number)")
args = parser.parse_args()
git_branch = subprocess.Popen("git rev-parse --abbrev-ref HEAD".split(), stdout=subprocess.PIPE).communicate()[0].splitlines()[0]
git_branch = scrub(git_branch)
# get latest tag
cleverbuild_number = args.cleverbuild_number
if not cleverbuild_number:
branch_tags = {}
for line in subprocess.Popen("git tag".split(), stdout=subprocess.PIPE).communicate()[0].splitlines():
tag = os.path.basename(line)
num = int(re.findall("[0-9]+", tag)[-1])
if "cleverbuild-%s-" % git_branch in tag:
branch_tags[num] = tag
cleverbuild_number = int(re.findall("[0-9]+", branch_tags[sorted(branch_tags)[-1]])[-1])
tag = "cleverbuild-%s-%s" % (git_branch, str(cleverbuild_number))
os.environ["CLEVERBUILD_BRANCH"] = git_branch
os.environ["CLEVERBUILD_NUMBER"] = str(cleverbuild_number)
# DEPRECATED
# DEPRECATED
# DEPRECATED
git_commit_cmd = "git rev-parse %s" % tag
git_commit = subprocess.Popen(git_commit_cmd.split(), stdout=subprocess.PIPE).communicate()[0].splitlines()[0]
os.environ["GIT_COMMIT"] = git_commit
# DEPRECATED
# DEPRECATED
# DEPRECATED
# work_tree
os.system("mkdir -p %s/cleverbuild" % tempfile.gettempdir())
work_tree = tempfile.mkdtemp(dir="%s/cleverbuild" % tempfile.gettempdir())
run("git archive %s | tar -x -C %s" % (tag, work_tree))
# run cleverbuild
dot_cleverbuild = ".cleverbuild"
run("cd %s && if [ -f %s ]; then ./%s; fi" % (work_tree, dot_cleverbuild, dot_cleverbuild))
# run cleverscript
cleverscript = ".cleverscript"
if args.cleverscript:
cleverscript = args.cleverscript
run("cd %s && ./%s" % (work_tree, cleverscript))
else:
run("cd %s && if [ -f %s ]; then ./%s; fi" % (work_tree, cleverscript, cleverscript))
run("echo %s" % tag)