-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathRelease.py
More file actions
87 lines (76 loc) · 2.99 KB
/
Copy pathRelease.py
File metadata and controls
87 lines (76 loc) · 2.99 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
#!/usr/bin/env python3
# Release script for MS Windows
#
# * Runs MSBuild to compile GitForce release version
# * Increments the version number and sets the build date in AssemblyInfo.cs file
# * Gets the log of changes since last release and formats changes.txt to be used as a release commit text
#
import sys, time, datetime, os, subprocess, re, shutil
def IncrementVersion(file, change):
# Open the changelist file to write
fch = open(change, "wt")
# Save the original version file since it will be modified
file_backup = file+"~"
if(os.path.exists(file_backup)):
os.remove(file_backup)
os.rename(file, file_backup)
fin = open(file_backup)
fout = open(file, "wt")
# Find version and build date and update them
for line in fin:
if line.find("AssemblyFileVersion")>0:
p = re.compile(r'\W+')
ver = p.split(line)
print('Major = ', ver[3])
print('Minor = ', ver[4])
print('Build = ', ver[5], ' -> ', int(ver[5])+1)
release = ver[3]+'.'+ver[4]+'.'+str(int(ver[5])+1)
line = line.replace(ver[3]+'.'+ver[4]+'.'+ver[5], release)
if line.find("AssemblyProduct")>0:
now = datetime.datetime.now()
format = "%Y/%m/%d"
built = now.strftime(format)
print('Setting the Build date = ', built)
line = "[assembly: AssemblyProduct(\"GitForce built on " + built + "\")]\n"
fout.write(line)
fin.close()
fout.close()
fch.write("### Release " + release + " (" + built + ")\n")
fch.close();
return release
def IncrementVersionXml(file, version):
# Save the original file before modifying it
file_backup = file+"~"
if(os.path.exists(file_backup)):
os.remove(file_backup)
os.rename(file, file_backup)
fin = open(file_backup)
fout = open(file, "wt")
# Find version and build date and update them
for line in fin:
pos = line.find("<version>")
if pos > 0:
line = " " * pos
line = line + "<version>" + version + "</version>\n"
fout.write(line)
fin.close()
fout.close()
version_file = "src/Properties/AssemblyInfo.cs"
changelist_file = "change.txt"
version = IncrementVersion(version_file, changelist_file)
print('Building:')
subprocess.Popen(["MSBuild.exe", "/t:Rebuild", "/p:Configuration=Release"], shell=True).wait()
# Copy released executable
shutil.copy2("src/obj/x86/Release/GitForce.exe", "./") # Here, to the root of the project
# Get the summary of changes and append to the subject
proc = subprocess.Popen(["git", "log", "--format=%B"], stdout=subprocess.PIPE)
stdout = proc.communicate()[0].decode('windows-1252')
stdout = stdout[0:stdout.find("###")]
h = open(changelist_file, "a")
h.write("-------------------------------------------\n")
h.write("SUMMARY OF CHANGES:\n\n")
h.write(stdout)
h.close()
print('-------------------------------------------')
print('Submit ' + version_file)
print('using the description in ' + changelist_file)