This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
97 lines (74 loc) · 4.02 KB
/
run.py
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
96
97
import shutil, os.path, json, datetime, re, glob, requests, os
import subprocess as sp
INTERNAL_DATE_FORMAT = "%Yw%W"
VERSION_PATTERN = r"<version>(.*)</version>"
DEPLOY_ITEMS = ("examples", "matsim", "contribs", ) # do not delete that dangling comma or it will not work if there's only one entry
# Default values
state = {
"last_release_commit" : "unknown",
"last_release_date" : "1990w00"
}
# Check if state is there and load it if so
if os.path.exists("state.json"):
with open("state.json") as f:
state.update(json.load(f))
# Clean up MATSim
if os.path.exists("matsim-libs"):
print("Deleting old checkout ...")
shutil.rmtree("matsim-libs")
# Clone MATSim
sp.check_call(["git", "clone", "--depth", "1", "https://github.com/matsim-org/matsim-libs.git"])
# Find current commit
current_commit = sp.check_output(["git", "rev-parse", "HEAD"], cwd = "matsim-libs").decode("utf-8").strip()
print("Current commit is:", current_commit)
last_release_date = datetime.datetime.strptime(state["last_release_date"], INTERNAL_DATE_FORMAT)
current_date = datetime.datetime.today().strftime(INTERNAL_DATE_FORMAT)
# We neither need a new release if the day has not passed yet, nor if there have
# not been any changes since the last release
if not current_date == last_release_date:
if not current_commit == state["last_release_commit"]:
# At this point a new release is requested
with open("matsim-libs/pom.xml") as f:
match = re.search(VERSION_PATTERN, f.read())
current_version = match.group(1)
if not current_version.endswith("-SNAPSHOT"):
raise RuntimeError("The commit checked out from github does not include a SNAPSHOT version!")
updated_version = current_version.replace("-SNAPSHOT", "-" + current_date)
current_version_string = "<version>%s</version>" % current_version
updated_version_string = "<version>%s</version>" % updated_version
print("SNAPSHOT version is:", current_version)
print("Updated (weekly) version is:", updated_version)
print("Current commit is:", current_commit, flush=True)
# check URL in following form: https://repo.matsim.org/repository/matsim/org/matsim/matsim/13.0/matsim-13.0.jar.md5
# check for the .md5 file as this is known to be small, in the case it already exists
result = requests.get("https://repo.matsim.org/repository/matsim/org/matsim/matsim/" + updated_version + "/matsim-" + updated_version + ".jar.md5")
if not result.status_code == 404:
raise RuntimeError("Version already exists or could not get informaton from Maven repository " + str(result.status_code))
sp.check_call(["mvn", "versions:set", "-DnewVersion="+updated_version, "-DoldVersion=*", "-DgroupId=*", "-DartifactId=*"], cwd = "matsim-libs")
print("Installing maven artifacts ...", flush=True)
sp.check_call([
"mvn", "install", "--batch-mode", "--fail-at-end",
"-Dmaven.test.redirectTestOutputToFile",
"-Dmatsim.preferLocalDtds=true"], cwd = "matsim-libs")
print("Deploying maven artifacts ...", flush=True)
# deploy non-recursively the parent project
sp.check_call([
"mvn", "deploy", "--batch-mode", "--fail-at-end",
"--settings", "../settings.xml",
"-DskipTests=true", "--non-recursive"], cwd = "matsim-libs")
# deploy selected sub-projects
for item in DEPLOY_ITEMS:
sp.check_call([
"mvn", "deploy", "--batch-mode", "--fail-at-end",
"--settings", "../../settings.xml",
"-DskipTests=true"], cwd = "matsim-libs/%s" % item)
with open("state.json", "w+") as f:
state["last_release_commit"] = current_commit
state["last_release_date"] = current_date
json.dump(state, f)
print("Published version:", updated_version)
else:
print("No changes since last release -> no new release necessary")
else:
print("You're too early. The day has not passed.")
#