-
Stephan Korsholm authoredbb00ab22
#!/usr/bin/env python3
import os
import sys
import zipfile
from shutil import copyfile
from shutil import rmtree
from shutil import copytree
from shutil import rmtree
import subprocess
import argparse
def ossystem(command: str):
exit_status = os.system(command)
if exit_status != 0:
print(f"'{command}' failed!")
sys.exit(1)
def getVersion() -> str:
version = subprocess.check_output("xmllint --xpath '/*[local-name()=\"project\"]/*[local-name()=\"properties\"]/*[local-name()=\"revision\"]/text()' pom.xml", shell=True)
version = version.decode('utf8')
version = version.replace(" ", "_")
version = version.replace("\n", "")
return version
def getReleaseArchiveName(version: str) -> str:
return 'seamcat-release-' + version + '.zip'
def getSourcePackageFolderAndNameBase() -> tuple[str, str]:
return getSourcePackageFolderAndName(getVersion())
def getSourcePackageFolderAndName(version: str) -> tuple[str, str]:
source = "source-" + version
sourceZipName = source + ".zip"
return (source, sourceZipName)
def getTempFolderName() -> str:
return "temp"
def getSeamcatApplicationName() -> str:
return "SEAMCAT-" + getVersion().upper() + ".jar"
def makeRelease():
version = getVersion()
## first: clean up source code and
## package in zip file
source, sourceZipName = getSourcePackageFolderAndName(version)
isExist = os.path.exists(source)
if isExist:
rmtree(source)
os.makedirs(source)
copyfile("release-pom.xml", source + "/pom.xml")
copytree("app", source + "/app")
isExist = os.path.exists(source + "/app/dependency-reduced-pom.xml")
if isExist:
os.remove(source + "/app/dependency-reduced-pom.xml")
copytree("model", source + "/model")
copytree("persistence", source + "/persistence")
copytree("core", source + "/core")
copytree("commandline", source + "/commandline")
isExist = os.path.exists(source + "/commandline/dependency-reduced-pom.xml")
if isExist:
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
os.remove(source + "/commandline/dependency-reduced-pom.xml")
ossystem("cd " + source + "; mvn clean")
def zipdir(path, ziph):
# ziph is zipfile handle
for root, dirs, files in os.walk(path):
for file in files:
ziph.write(os.path.join(root, file))
zipf = zipfile.ZipFile(sourceZipName, 'w', zipfile.ZIP_DEFLATED)
zipdir(source + "/", zipf)
zipf.close()
rmtree(source)
## second: run maven install
ossystem("mvn clean")
ossystem("mvn compile")
ossystem("mvn install -DskipTests")
## third produce release zip file containing
## all release artifacts
seamcatApplicationName = getSeamcatApplicationName()
seamcatJavadocName = "SEAMCAT-MODEL-JAVADOC-" + version.upper() + ".jar"
seamcatModelName = "SEAMCAT-MODEL-" + version.upper() + ".jar"
seamcatCommandlineName = "SEAMCAT-COMMANDLINE-" + version.upper() + ".jar"
seamcatRealeaseName = getReleaseArchiveName(version)
zipf = zipfile.ZipFile(seamcatRealeaseName, 'w', zipfile.ZIP_DEFLATED)
ossystem("cp app/target/seamcat-application-*.jar " + seamcatApplicationName)
zipf.write(seamcatApplicationName)
ossystem("mv model/target/seamcat-model-*javadoc.jar " + seamcatJavadocName)
zipf.write(seamcatJavadocName)
ossystem("cp model/target/seamcat-model-*.jar " + seamcatModelName)
zipf.write(seamcatModelName)
ossystem("cp commandline/target/seamcat-commandline-*.jar " + seamcatCommandlineName)
zipf.write(seamcatCommandlineName)
zipf.write(sourceZipName)
zipf.close()
os.remove(seamcatApplicationName)
os.remove(seamcatModelName)
os.remove(seamcatJavadocName)
os.remove(seamcatCommandlineName)
os.remove(sourceZipName)
def checkRelease(releaseArchive: str, compileSource: bool):
tempFolderName = getTempFolderName()
isExist = os.path.exists(tempFolderName)
if isExist:
rmtree(tempFolderName)
sourceFolder, sourceZipName = getSourcePackageFolderAndNameBase()
os.makedirs(tempFolderName)
os.chdir(tempFolderName)
ossystem("pwd")
ossystem("unzip ../" + releaseArchive)
if compileSource:
ossystem("unzip " + sourceZipName)
os.chdir(sourceFolder)
ossystem("mvn compile")
def testRelease(releaseArchiveName: str):
checkRelease(getReleaseArchiveName(getVersion()), False)
tempFolderName = getTempFolderName()
ossystem("java -cp SEAMCAT-5.5.0-ALPHA-4.jar org.seamcat.CommandLine Workspace=\"../core/src/test/resources/integrationtests/WS_PMSE_HH-LTE UE_Cell_UT.sws\" Result=\"Test_OFDMA_DL_1.swr\"")
ossystem("! java -cp SEAMCAT-5.5.0-ALPHA-4.jar org.seamcat.CommandLine Workspace=\"../core/src/test/resources/integrationtests/Test_GenericResultsTerrain.sws\" Result=\"Test_GenericResultsTerrain.swr\" tformat=ASTER_GEOTIFF tpath=\"../core/src/test/resources/terrainData/geotiff\" 2>&1 | grep \"vendorName == null\"")
ossystem("! java -cp SEAMCAT-COMMANDLINE-5.5.0-ALPHA-4.jar org.seamcat.CommandLine Workspace=\"../core/src/test/resources/integrationtests/Test_GenericResultsTerrain.sws\" Result=\"Test_GenericResultsTerrain.swr\" tformat=ASTER_GEOTIFF tpath=\"../core/src/test/resources/terrainData/geotiff\" 2>&1 | grep \"vendorName == null\"")
print("test finished")
parser = argparse.ArgumentParser("release.py")
parser.add_argument('-m', '--make', help="Build the release.", action='store_true')
parser.add_argument('-c', '--check', help="Check the release.", action='store_true')
parser.add_argument('-t', '--test', help="Test the release.", action='store_true')
args = parser.parse_args()
if len(sys.argv) == 1:
parser.print_help()
sys.exit()
if (args.make):
makeRelease()
if (args.check):
checkRelease(getReleaseArchiveName(getVersion()), True)
if (args.test):
testRelease(getReleaseArchiveName(getVersion()))