-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgenerate-travis.py
More file actions
executable file
·95 lines (80 loc) · 3.41 KB
/
generate-travis.py
File metadata and controls
executable file
·95 lines (80 loc) · 3.41 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
import os
import re
import subprocess
import sys
import getopt
def loginTravis(project, token):
traviscmd = ["travis", "login", "--github-token", token]
travisprocess = subprocess.Popen(traviscmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd='./'+project)
travisout, traviserr = travisprocess.communicate()
if traviserr:
print "ERROR ON LOGIN ("+project+"): "+traviserr
return False;
return True;
def createTravisSecure(project = "", purge = False, keyName="ciDeployUserName", keyValue="robson"):
purgeParam = "";
if (purge):
purgeParam = "-x"
traviscmd = ["travis", "encrypt", "-r", "liveSense/"+project, purgeParam, "-a", "env.global", keyName+"="+keyValue]
travisprocess = subprocess.Popen(traviscmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd='./'+project)
travisout, traviserr = travisprocess.communicate()
if traviserr:
print "ERROR ON ENCRYPT ("+project+"): "+traviserr
return
def processDirectories(ciDeployUserName, ciDeployPassword, githubToken):
for project in os.listdir('.'):
if os.path.isfile(project) or project == '.git' or project == 'docgenerator': pass
else:
if (not os.path.isfile(project+'/.travis.yml')):
print("Updating travis secret: "+project+" "+ciDeployUserName+" "+ciDeployPassword+" "+githubToken)
if (loginTravis(project, githubToken)):
f = open(project+'/.travis.yml', 'w')
f.truncate();
f.write("language: java\n")
f.write("before_install:\n")
f.write("- curl https://raw.github.com/liveSense/all/master/travis-settings.xml --create-dirs -o target/travis/settings.xml\n")
f.write("jdk:\n")
f.write("- openjdk6\n")
f.write("script:\n")
f.write("- mvn deploy --settings target/travis/settings.xml\n")
f.close()
createTravisSecure(project, True, "CI_DEPLOY_USERNAME", ciDeployUserName)
createTravisSecure(project, False, "CI_DEPLOY_PASSWORD", ciDeployPassword)
def printHelp():
print 'Usage: \ngenerate-travis.py -t <github token> -u <maven deploy user> -p <maven deploy password>'
return
def main(argv):
githubToken = None
ciDeployUserName = None
ciDeployPassword = None
try:
opts, args = getopt.getopt(argv,"ht:u:p:",["github-token=","user=","password="])
except getopt.GetoptError:
printHelp()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
printHelp()
sys.exit()
elif opt in ("-t", "--github-token"):
githubToken = arg
elif opt in ("-u", "--user"):
ciDeployUserName = arg
elif opt in ("-p", "--password"):
ciDeployPassword = arg
if (githubToken is None):
print('ERROR: You must specify GitHub authentication token\n');
printHelp()
sys.exit(2)
if (githubToken is None):
print('ERROR: You must specify Maven deploy username\n');
printHelp()
sys.exit(2)
if (githubToken is None):
print('ERROR: You must specify Maven deploy password\n');
printHelp()
sys.exit(2)
processDirectories(ciDeployUserName, ciDeployPassword, githubToken)
if __name__ == "__main__":
main(sys.argv[1:])