-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathib-create-tag.py
executable file
·121 lines (102 loc) · 3.3 KB
/
ib-create-tag.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
""":"
python_cmd="python3"
python -V >/dev/null 2>&1 && python_cmd="python"
exec ${python_cmd} $0 ${1+"$@"}
"""
from __future__ import print_function
import datetime
import time
from _py2with3compatibility import HTTPError
from os.path import dirname, abspath
from socket import setdefaulttimeout
import sys
from cms_static import (
GH_CMSSW_ORGANIZATION,
GH_CMSSW_REPO,
)
from github_utils import (
get_git_tag,
create_git_tag,
get_commits,
find_tags,
)
from categories import CMSSW_ORP
setdefaulttimeout(120)
SCRIPT_DIR = dirname(abspath(sys.argv[0]))
def currenttz():
tm = time.localtime()
return datetime.timezone(datetime.timedelta(seconds=tm.tm_gmtoff), tm.tm_zone)
IBS_WITH_HEAD_COMMITS = ["CMSSW_5_3_HI_X"]
if __name__ == "__main__":
from optparse import OptionParser
parser = OptionParser(
usage="%prog [-n|--dry-run] [-N|--release-name] [-d|--day] [-H|--hour] [-b|--branch]"
)
parser.add_option(
"-n",
"--dry-run",
dest="dryRun",
action="store_true",
help="Do not modify Github",
default=False,
)
parser.add_option(
"-N",
"--release-name",
dest="release_name",
action="store",
help="CMSSW Release name",
)
parser.add_option(
"-d", "--date", dest="date", action="store", help="CMSSW IB date (YYYY-MM-DD)"
)
parser.add_option("-H", "--hour", dest="hour", action="store", help="CMSSW IB hour (HH)")
parser.add_option(
"-M", "--minute", dest="minute", action="store", help="CMSSW IB minute (MM)", default="00"
)
parser.add_option("-b", "--branch", dest="branch", action="store", help="CMSSW branch")
parser.add_option("-q", "--queue", dest="queue", action="store", help="CMSSW IB queue")
opts, args = parser.parse_args()
RELEASE_NAME = opts.release_name # "CMSSW_13_0_X_2023-02-02-1100"
ib_date = (
datetime.datetime.strptime(
"%s %s:%s" % (opts.date, opts.hour, opts.minute), "%Y-%m-%d %H:%M"
)
.replace(tzinfo=currenttz())
.astimezone(datetime.timezone.utc)
)
RELEASE_BRANCH = opts.branch # "master"
QUEUE = opts.queue # "CMSSW_13_0_X"
repo = "%s/%s" % (GH_CMSSW_ORGANIZATION, GH_CMSSW_REPO)
commit_url = "https://api.github.com/repos/%s/commits/" % repo
try:
ref = get_git_tag(repo, RELEASE_NAME)
HEAD_SHA = ref["object"]["sha"]
except HTTPError:
commits_ = get_commits(repo, RELEASE_BRANCH, until=ib_date, per_page=100)
if not commits_:
sys.exit(1)
head = None
for commit_ in commits_:
if (len(commit_["parents"]) == 1) and (not QUEUE in IBS_WITH_HEAD_COMMITS):
continue
if commit_["url"].startswith(commit_url):
head = commit_
break
if head is None:
sys.exit(1)
HEAD_SHA = head["sha"]
if not opts.dryRun:
create_git_tag(
repo,
RELEASE_NAME,
HEAD_SHA,
)
else:
print("Tag head: ", HEAD_SHA)
tags = find_tags(repo, QUEUE + "_20")
RELEASE_LIST = [
t["ref"].replace("refs/tags/", "") for t in tags if t["object"]["sha"] == HEAD_SHA
]
print(" ".join(RELEASE_LIST[::-1]))