Initialize Tizen 2.3
[framework/web/webkit-efl.git] / TizenScripts / release-webkit
1 #!/usr/bin/python
2 #####################################################################
3 # Helper script to release
4 #####################################################################
5 import sys, os
6 import getopt
7 import signal
8 import time
9
10 enableDryRun = False
11
12 def help():
13     print """
14 # Helper Script to release WebKit. #
15
16 Usage: release-webkit [OPTIONS]
17
18 [OPTIONS]
19    -h, --help          : Print this message.
20    -n, --dry-run       : Don't actually run any commands; just print them.
21    -c, --create-commit : (devel/webkit/upversion branch) Create Release commit and push to gerrit.
22                          If you want to release by latest commit, please 'git pull' before execute this command.
23    -r, --merge-release : (w/master branch) Merge release commit and push to gerrit.
24 """
25
26 def execute(command):
27     if enableDryRun:
28         print(command)
29     else:
30         os.system(command)
31
32 def openFile(fileName, mode):
33     return open(fileName, mode)
34
35 def closeFile(filePtr):
36     filePtr.close()
37
38 def getPath():
39     if "TizenScripts" in os.getcwd():
40         return "../"
41     return ""
42
43 def checkNewPatch():
44     findFirstCommit = False
45     noNewPatch = False
46     maxCommitCount = "500"
47
48     os.system("git log -n " + maxCommitCount + " > logForCheckNewPatch")
49     logForCheckNewPatch = openFile("logForCheckNewPatch", "r")
50     for line in logForCheckNewPatch:
51         if "commit" in line:
52             if findFirstCommit:
53                 break
54             else:
55                 findFirstCommit = True
56         else:
57             if findFirstCommit:
58                 if "[Release] Webkit" in line:
59                     noNewPatch = True
60
61     closeFile(logForCheckNewPatch)
62     os.system("rm logForCheckNewPatch")
63
64     if noNewPatch:
65         print "There is no new patch after previous release."
66         exit()
67
68 def updatePatchVersion(revision, major, minor, issue):
69     path = getPath()
70
71     currentSpec = openFile(path + "packaging/webkit2-efl.spec","r")
72     modifiedSpec = openFile("modifiedSpec","w")
73
74     for line in currentSpec:
75         if "Version:" in line:
76             Version = line.split(".");
77             patchVersion = str(int(Version[2]) + 1)
78
79             changedLine = "Version: " + revision + "_" + major + "." + minor + "." + patchVersion + "." + issue + "\n"
80             modifiedSpec.write(changedLine)
81             print "Modified Version in webkit2-efl.spec to " + major + "." + minor + "." + patchVersion.strip() + "." + issue
82         elif "-DPROJECT_VERSION=" in line:
83             modifiedSpec.write("    -DPROJECT_VERSION=" + revision + "_" + major + "." + minor + "." + patchVersion + "." + issue + " \\" + "\n")
84         else:
85             modifiedSpec.write(line)
86
87     closeFile(currentSpec)
88     closeFile(modifiedSpec)
89
90     if enableDryRun:
91         os.system("rm modifiedSpec")
92     else:
93         os.system("chmod 644 modifiedSpec")
94         os.system("mv modifiedSpec " + path + "packaging/webkit2-efl.spec")
95
96     execute("git add " + path + "packaging/webkit2-efl.spec" )
97
98     return patchVersion
99
100 def getReleaseCommitId(branch):
101     maxCommitCount = "500"
102
103     os.system("git log -n " + maxCommitCount + " " + branch + " > currentLog")
104     currentLog = openFile("currentLog", "r")
105
106     for line in currentLog:
107         if "commit" in line:
108             commitId = line.replace("commit ","").strip()
109         elif line.find("[Release] Webkit2-efl") == 4:
110             break
111
112     closeFile(currentLog)
113     os.system("rm currentLog")
114     os.system("git log " + commitId + " > patchLog")
115
116     return commitId
117
118 def createReleaseCommit():
119     branchName = "devel/webkit/upversion"
120     revision = "152340"
121     majorVersion = "0"
122     minorVersion = "10"
123     issueVersion = "0"
124
125     execute("git checkout " + branchName)
126     checkNewPatch()
127     patchVersion = updatePatchVersion(revision, majorVersion, minorVersion, issueVersion)
128     execute("git commit -m '[Release] Webkit2-efl-" + revision + "_" + majorVersion + "." + minorVersion + "." + patchVersion + "." + issueVersion + "\n[Branch] " + branchName + "'" )
129     execute("git push origin HEAD:refs/for/" + branchName)
130
131     print "[Creating release commit] finished."
132
133 def mergeRelaseCommit():
134     branchName = "w/master"
135
136     execute("git checkout " + branchName)
137     execute("git pull --rebase")
138     releaseCommitId = getReleaseCommitId("devel/webkit/upversion")
139     execute("git merge -m 'Merge commit \'" + releaseCommitId + "\' into " + branchName + "' " + releaseCommitId)
140     execute("git commit --amend -m 'Merge commit \'" + releaseCommitId + "\' into " + branchName + "'")
141     execute("git push origin HEAD:refs/for/" + branchName)
142
143     print "[Package release] finished."
144
145 def main():
146     global enableDryRun
147     enableCreateCommit = False
148     enableRelease = False
149
150     optlist, args = getopt.getopt(sys.argv[1:], 'hncrm:o', [ 'help', 'dry-run', 'create-commit', 'merge-release'])
151     for opt, var in optlist:
152         if opt in ('--help', '-h'):
153             help()
154             exit()
155         if opt in ('--dry-run', '-n'):
156             enableDryRun = True
157         if opt in ('--create-commit', '-c'):
158             enableCreateCommit = True
159         if opt in ('--merge-release', '-r'):
160             enableRelease = True
161
162     if enableCreateCommit and enableRelease:
163         print "ERROR : This options are can't executed simultaneously"
164         exit()
165
166     if enableCreateCommit:
167         createReleaseCommit()
168     elif enableRelease:
169         mergeRelaseCommit()
170     else:
171         help()
172
173 main()