forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport-build-release-status
executable file
·264 lines (216 loc) · 11.3 KB
/
report-build-release-status
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/usr/bin/env python
from optparse import OptionParser
from github import Github
from os.path import expanduser
#
# Posts a message in the github issue that triggered the build
# The structure of the message depends on the option used
#
# -------------------------------------------------------------------------------
# Global Variables
# --------------------------------------------------------------------------------
GH_CMSSW_ORGANIZATION = 'cms-sw'
GH_CMSSW_REPO = 'cmssw'
POST_BUILDING='BUILDING'
POST_TOOL_CONF_BUILDING='TOOL_CONF_BUILDING'
BUILD_OK='BUILD_OK'
TOOL_CONF_OK='TOOL_CONF_OK'
TOOL_CONF_ERROR = 'TOOL_CONF_ERROR'
BUILD_ERROR='BUILD_ERROR'
UPLOADING='UPLOADING'
UPLOAD_OK='UPLOAD_OK'
UPLOAD_ERROR='UPLOAD_ERROR'
CLEANUP_OK='CLEANUP_OK'
CLEANUP_ERROR='CLEANUP_ERROR'
TESTS_OK='TESTS_OK'
RELEASE_NOTES_OK='RELEASE_NOTES_OK'
RELEASE_NOTES_ERROR='RELEASE_NOTES_ERROR'
# this means that there was an error in the script that excecutes the tests,
# it is independent from the tests results
TESTS_ERROR='TESTS_ERROR'
BUILDING_MSG='The build has started for {architecture} in {machine}. \n' \
'You can see the progress here: https://cmssdt.cern.ch/jenkins/job/build-release/{jk_build_number}/console \n' \
'{details}'
BUILDING_TOOL_CONF_MSG='The cmssw-tool-conf build has started for {architecture} in {machine}. \n' \
'You can see the progress here: https://cmssdt.cern.ch/jenkins/job/build-release/{jk_build_number}/console \n' \
'{details}'
BUILD_OK_MSG='The build has finished sucessfully for the architecture {architecture} and is ready to be uploaded. \n' \
'You can start the uploads by writing the comment: "upload all". I will upload all the architectures as soon as the build finishes successfully.\n' \
'You can see the log for the build here: \n' \
'{log_url} \n' \
'Some tests ( runTheMatrix.py -s ) are being run, the results will be posted when done.'
TOOL_CONF_OK_MSG='The cmssw-tool-conf build has finished sucessfully for the architecture {architecture} and it was automatically uploaded. \n' \
'Remember that if you write "+1" I will start to build this and all the architectures as soon as their cmssw-tool-conf finish.\n' \
'You can see the log for the build here: \n' \
'{log_url} \n'
TOOL_CONF_ERROR_MSG='There was an error building cmssw-tool-conf for {architecture} \n' \
'You can see the log for the build here: \n' \
'{log_url} \n'
UPLOADING_MSG='The upload has started for {architecture} in {machine}. \n' \
'You can see the progress here: https://cmssdt.cern.ch/jenkins/job/upload-release/{jk_build_number}/console'
UPLOAD_OK_MSG='The upload has successfully finished for {architecture} \n You can see the log here: \n {log_url} \n' \
'The release is now being installed, you can see the progress here: \n ' \
'https://cmssdt.cern.ch/jenkins/job/release-deploy-afs/ \n' \
'To generate the release notes for the release write "release-notes since \\<previous-release\\>", in the first line of your comment.\n ' \
'I will generate the release notes based on the release that you provide. You don\'t need to provide the architectue ' \
'I will use the production architecture to infer the cmsdist tag.\n' \
'Alternatively, you can just write "release-notes", I will try to guess the previous release.'
UPLOAD_ERROR_MSG='The was error uploading {architecture}. \n You can see the log here: \n {log_url}'
CLEANUP_OK_MSG='The workspace for {architecture} has been deleted \n You can see the log here: \n {log_url} \n'
CLEANUP_ERROR_MSG='There was an error deletng the workspace for {architecture} \n You can see the log here: \n {log_url} \n'
TESTS_OK_MSG='The tests have finished for {architecture} \n You can see the log here: \n {log_url} \n'
TESTS_ERROR_MSG='There was an error when running the tests for {architecture} \n You can see the log here: \n {log_url} \n'
BUILD_ERROR_MSG='The was an error for {architecture}. \n You can see the log here: \n {log_url}'
RELEASE_NOTES_OK_MSG='The release notes are ready: https://github.com/cms-sw/cmssw/releases/tag/{rel_name}'
RELEASE_NOTES_ERROR_MSG='There was an error generating the release notes, please look into the logs'
BUILD_QUEUED_LABEL = 'build-release-queued'
BUILD_STARTED = 'build-release-started'
BASE_BUILD_LOG_URL = 'https://cmssdt.cern.ch/SDT/jenkins-artifacts/auto-build-release/%s-%s/%d'
BASE_UPLOAD_LOG_URL = 'https://cmssdt.cern.ch/SDT/jenkins-artifacts/auto-upload-release/%s-%s/%d'
BASE_CLEANUP_LOG_URL = 'https://cmssdt.cern.ch/SDT/jenkins-artifacts/cleanup-auto-build/%s-%s/%d'
# -------------------------------------------------------------------------------
# Functions
# --------------------------------------------------------------------------------
#
# posts a message to the issue in github
# if dry-run is selected it doesn't post the message and just prints it
#
def post_message( issue, msg ):
if opts.dryRun:
print 'Not posting message (dry-run):\n %s' % msg
else:
print 'Posting message:\n %s' % msg
issue.create_comment( msg )
# Adds a label to the issue in github
# if dry-run is selected it doesn't add the label and just prints it
def add_label( issue, label ):
if opts.dryRun:
print 'Not adding label (dry-run):\n %s' % label
return
print 'Adding label:\n %s' % label
issue.add_to_labels( label )
# Removes a label form the issue
def remove_label( issue, label ):
if opts.dryRun:
print 'Not removing label (dry-run):\n %s' % label
return
if label not in ALL_LABELS:
print 'label ', label, ' does not exist. Not attempting to remove'
return
print 'Removing label: %s' % label
issue.remove_from_labels( label)
#
# removes the labels of the issue
#
def remove_labels( issue ):
if opts.dryRun:
print 'Not removing issue labels (dry-run)'
return
issue.delete_labels()
# Start of execution
# --------------------------------------------------------------------------------
if __name__ == "__main__":
parser = OptionParser( usage="%prog <jenkins-build-number> <hostname> <issue-id> <arch> <release-name> <message-type> [ options ] \n "
"message-type = BUILDING | BUILD_OK | BUILD_ERROR | UPLOADING | UPLOAD_OK | UPLOAD_ERROR | CLEANUP_OK | CLEANUP_ERROR | TESTS_OK | TESTS_ERROR "
"| RELEASE_NOTES_OK | RELEASE_NOTES_ERROR ")
parser.add_option( "-n" , "--dry-run" , dest="dryRun" , action="store_true", help="Do not post on Github", default=False )
parser.add_option( "-d" , "--details" , dest="details" , action="store", help="Add aditional details to the message", default=False )
opts, args = parser.parse_args( )
if len( args ) != 6:
parser.error( "Not enough arguments" )
jenkins_build_number = int( args[ 0 ] )
hostname = args[ 1 ]
issue_id = int( args[ 2 ] )
arch = args[ 3 ]
release_name = args[ 4 ]
action = args[ 5 ]
GH = Github( login_or_token=open( expanduser( "~/.github-token" ) ).read( ).strip( ) )
rate_limit = GH.get_rate_limit().rate
print 'API Rate Limit'
print 'Limit: ', rate_limit.limit
print 'Remaining: ', rate_limit.remaining
print 'Reset time (GMT): ', rate_limit.reset
cmssw_repo = GH.get_repo( GH_CMSSW_ORGANIZATION + '/' + GH_CMSSW_REPO )
issue = cmssw_repo.get_issue( issue_id )
ALL_LABELS = [ l.name for l in cmssw_repo.get_labels() ]
if action == POST_BUILDING:
msg_details = ''
if opts.details:
msg_details = opts.details
msg = BUILDING_MSG.format( architecture=arch, machine=hostname, jk_build_number=jenkins_build_number, details=msg_details )
post_message( issue , msg )
remove_label( issue, arch+'-build-queued' )
new_label = arch+'-building'
add_label( issue, new_label )
elif action == POST_TOOL_CONF_BUILDING:
msg_details = ''
if opts.details:
msg_details = opts.details
msg = BUILDING_TOOL_CONF_MSG.format( architecture=arch, machine=hostname, jk_build_number=jenkins_build_number, details=msg_details )
post_message( issue , msg )
remove_label( issue, arch+'-tool-conf-waiting' )
new_label = arch+'-tool-conf-building'
add_label( issue, new_label )
elif action == BUILD_OK:
results_url = BASE_BUILD_LOG_URL % (release_name,arch,jenkins_build_number)
msg = BUILD_OK_MSG.format( architecture=arch, log_url=results_url )
post_message( issue , msg )
remove_label( issue, arch+'-building' )
add_label( issue, arch+'-build-ok' )
elif action == TOOL_CONF_OK:
results_url = BASE_BUILD_LOG_URL % (release_name,arch,jenkins_build_number)
msg = TOOL_CONF_OK_MSG.format( architecture=arch, log_url=results_url )
post_message( issue , msg )
remove_label( issue, arch+'-tool-conf-building' )
add_label( issue, arch+'-tool-conf-ok' )
elif action == BUILD_ERROR:
results_url = BASE_BUILD_LOG_URL % (release_name,arch,jenkins_build_number)
msg = BUILD_ERROR_MSG.format( architecture=arch, log_url=results_url )
post_message( issue , msg )
remove_label( issue, arch+'-building' )
add_label( issue, arch+'-build-error' )
elif action == TOOL_CONF_ERROR:
results_url = BASE_BUILD_LOG_URL % (release_name,arch,jenkins_build_number)
msg = TOOL_CONF_ERROR_MSG.format( architecture=arch, log_url=results_url )
post_message( issue , msg )
remove_label( issue, arch+'-tool-conf-building' )
add_label( issue, arch+'-tool-conf-error' )
elif action == UPLOADING:
msg = UPLOADING_MSG.format( architecture=arch, machine=hostname, jk_build_number=jenkins_build_number)
post_message( issue , msg )
elif action == UPLOAD_OK:
results_url = BASE_UPLOAD_LOG_URL % (release_name,arch,jenkins_build_number)
msg = UPLOAD_OK_MSG.format( architecture=arch , log_url=results_url )
post_message( issue , msg )
remove_label( issue, arch+'-uploading' )
add_label( issue, arch+'-upload-ok' )
elif action == UPLOAD_ERROR:
results_url = BASE_UPLOAD_LOG_URL % (release_name,arch,jenkins_build_number)
msg = UPLOAD_ERROR_MSG.format( architecture=arch , log_url=results_url )
post_message( issue , msg )
remove_label( issue, arch+'-uploading' )
add_label( issue, arch+'-upload-error' )
elif action == CLEANUP_OK:
results_url = BASE_CLEANUP_LOG_URL % (release_name,arch,jenkins_build_number)
msg = CLEANUP_OK_MSG.format( architecture=arch , log_url=results_url )
post_message( issue , msg )
elif action == CLEANUP_ERROR:
results_url = BASE_CLEANUP_LOG_URL % (release_name,arch,jenkins_build_number)
msg = CLEANUP_ERROR_MSG.format( architecture=arch , log_url=results_url )
post_message( issue , msg )
elif action == TESTS_OK:
results_url = BASE_BUILD_LOG_URL % (release_name,arch,jenkins_build_number)
msg = TESTS_OK_MSG.format( architecture=arch, log_url=results_url )
post_message( issue , msg )
elif action == TESTS_ERROR:
results_url = BASE_BUILD_LOG_URL % (release_name,arch,jenkins_build_number)
msg = TESTS_ERROR_MSG.format( architecture=arch, log_url=results_url )
post_message( issue , msg )
elif action == RELEASE_NOTES_OK:
msg = RELEASE_NOTES_OK_MSG.format( rel_name=release_name )
post_message( issue, msg)
elif action == RELEASE_NOTES_ERROR:
msg = RELEASE_NOTES_ERROR_MSG.format( rel_name=release_name )
post_message( issue, msg)
else:
parser.error( "Message type not recognized" )