2017-12-04 08:31:57 -06:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import json
|
|
|
|
import datetime
|
|
|
|
import collections
|
2018-02-21 08:25:12 -06:00
|
|
|
import textwrap
|
2018-02-21 08:58:06 -06:00
|
|
|
try:
|
|
|
|
import urllib2
|
|
|
|
except ImportError:
|
|
|
|
import urllib.request as urllib2
|
2017-12-04 08:31:57 -06:00
|
|
|
|
|
|
|
# List of people to ping when the status of a tool changed.
|
|
|
|
MAINTAINERS = {
|
|
|
|
'miri': '@oli-obk @RalfJung @eddyb',
|
2019-02-16 04:56:32 -06:00
|
|
|
'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk @phansch',
|
2018-11-01 16:38:05 -05:00
|
|
|
'rls': '@nrc @Xanewok',
|
2019-02-13 20:11:05 -06:00
|
|
|
'rustfmt': '@nrc @topecongiro',
|
2018-02-21 13:25:23 -06:00
|
|
|
'book': '@carols10cents @steveklabnik',
|
|
|
|
'nomicon': '@frewsxcv @Gankro',
|
|
|
|
'reference': '@steveklabnik @Havvy @matthewjasper @alercah',
|
|
|
|
'rust-by-example': '@steveklabnik @marioidival @projektir',
|
2017-12-04 08:31:57 -06:00
|
|
|
}
|
|
|
|
|
2018-12-19 10:44:46 -06:00
|
|
|
REPOS = {
|
2019-02-21 12:26:45 -06:00
|
|
|
'miri': 'https://github.com/rust-lang/miri',
|
2018-12-19 10:44:46 -06:00
|
|
|
'clippy-driver': 'https://github.com/rust-lang/rust-clippy',
|
|
|
|
'rls': 'https://github.com/rust-lang/rls',
|
|
|
|
'rustfmt': 'https://github.com/rust-lang/rustfmt',
|
|
|
|
'book': 'https://github.com/rust-lang/book',
|
|
|
|
'nomicon': 'https://github.com/rust-lang-nursery/nomicon',
|
|
|
|
'reference': 'https://github.com/rust-lang-nursery/reference',
|
|
|
|
'rust-by-example': 'https://github.com/rust-lang/rust-by-example',
|
|
|
|
}
|
|
|
|
|
2017-12-04 08:31:57 -06:00
|
|
|
|
|
|
|
def read_current_status(current_commit, path):
|
|
|
|
'''Reads build status of `current_commit` from content of `history/*.tsv`
|
|
|
|
'''
|
|
|
|
with open(path, 'rU') as f:
|
|
|
|
for line in f:
|
|
|
|
(commit, status) = line.split('\t', 1)
|
|
|
|
if commit == current_commit:
|
|
|
|
return json.loads(status)
|
|
|
|
return {}
|
|
|
|
|
2018-12-18 06:33:02 -06:00
|
|
|
def issue(
|
|
|
|
tool,
|
|
|
|
maintainers,
|
|
|
|
relevant_pr_number,
|
|
|
|
relevant_pr_user,
|
2018-12-19 10:44:46 -06:00
|
|
|
pr_reviewer,
|
2018-12-18 06:33:02 -06:00
|
|
|
):
|
|
|
|
# Open an issue about the toolstate failure.
|
|
|
|
gh_url = 'https://api.github.com/repos/rust-lang/rust/issues'
|
|
|
|
assignees = [x.strip() for x in maintainers.split('@') if x != '']
|
|
|
|
assignees.append(relevant_pr_user)
|
|
|
|
response = urllib2.urlopen(urllib2.Request(
|
|
|
|
gh_url,
|
|
|
|
json.dumps({
|
2018-12-23 06:27:37 -06:00
|
|
|
'body': textwrap.dedent('''\
|
2018-12-19 10:44:46 -06:00
|
|
|
Hello, this is your friendly neighborhood mergebot.
|
|
|
|
After merging PR {}, I observed that the tool {} no longer builds.
|
|
|
|
A follow-up PR to the repository {} is needed to fix the fallout.
|
2018-12-18 06:33:02 -06:00
|
|
|
|
2018-12-20 07:29:42 -06:00
|
|
|
cc @{}, do you think you would have time to do the follow-up work?
|
|
|
|
If so, that would be great!
|
2018-12-19 08:54:51 -06:00
|
|
|
|
2018-12-19 10:44:46 -06:00
|
|
|
cc @{}, the PR reviewer, and @rust-lang/compiler -- nominating for prioritization.
|
2018-12-19 08:54:51 -06:00
|
|
|
|
2018-12-23 06:27:37 -06:00
|
|
|
''').format(relevant_pr_number, tool, REPOS[tool], relevant_pr_user, pr_reviewer),
|
2018-12-19 10:44:46 -06:00
|
|
|
'title': '`{}` no longer builds after {}'.format(tool, relevant_pr_number),
|
2018-12-18 06:33:02 -06:00
|
|
|
'assignees': assignees,
|
2018-12-18 09:30:40 -06:00
|
|
|
'labels': ['T-compiler', 'I-nominated'],
|
2018-12-18 06:33:02 -06:00
|
|
|
}),
|
|
|
|
{
|
|
|
|
'Authorization': 'token ' + github_token,
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
}
|
|
|
|
))
|
|
|
|
response.read()
|
2017-12-04 08:31:57 -06:00
|
|
|
|
2018-02-21 08:25:12 -06:00
|
|
|
def update_latest(
|
|
|
|
current_commit,
|
|
|
|
relevant_pr_number,
|
|
|
|
relevant_pr_url,
|
2018-12-18 06:33:02 -06:00
|
|
|
relevant_pr_user,
|
2018-12-19 10:44:46 -06:00
|
|
|
pr_reviewer,
|
2018-02-21 08:25:12 -06:00
|
|
|
current_datetime
|
|
|
|
):
|
2017-12-04 08:31:57 -06:00
|
|
|
'''Updates `_data/latest.json` to match build result of the given commit.
|
|
|
|
'''
|
|
|
|
with open('_data/latest.json', 'rb+') as f:
|
|
|
|
latest = json.load(f, object_pairs_hook=collections.OrderedDict)
|
|
|
|
|
|
|
|
current_status = {
|
|
|
|
os: read_current_status(current_commit, 'history/' + os + '.tsv')
|
|
|
|
for os in ['windows', 'linux']
|
|
|
|
}
|
|
|
|
|
|
|
|
slug = 'rust-lang/rust'
|
2018-12-15 07:57:17 -06:00
|
|
|
message = textwrap.dedent('''\
|
|
|
|
📣 Toolstate changed by {}!
|
|
|
|
|
2018-02-21 08:25:12 -06:00
|
|
|
Tested on commit {}@{}.
|
|
|
|
Direct link to PR: <{}>
|
|
|
|
|
2018-12-15 07:57:17 -06:00
|
|
|
''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
|
2017-12-04 08:31:57 -06:00
|
|
|
anything_changed = False
|
|
|
|
for status in latest:
|
|
|
|
tool = status['tool']
|
|
|
|
changed = False
|
2018-12-19 10:44:46 -06:00
|
|
|
build_failed = False
|
2017-12-04 08:31:57 -06:00
|
|
|
|
|
|
|
for os, s in current_status.items():
|
|
|
|
old = status[os]
|
|
|
|
new = s.get(tool, old)
|
|
|
|
status[os] = new
|
|
|
|
if new > old:
|
2018-12-19 09:37:16 -06:00
|
|
|
# things got fixed or at least the status quo improved
|
2017-12-04 08:31:57 -06:00
|
|
|
changed = True
|
2018-12-15 07:57:17 -06:00
|
|
|
message += '🎉 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
|
|
|
|
.format(tool, os, old, new, MAINTAINERS.get(tool))
|
2017-12-04 08:31:57 -06:00
|
|
|
elif new < old:
|
2018-12-19 09:37:16 -06:00
|
|
|
# tests or builds are failing and were not failing before
|
2017-12-04 08:31:57 -06:00
|
|
|
changed = True
|
2018-12-18 06:33:02 -06:00
|
|
|
title = '💔 {} on {}: {} → {}' \
|
|
|
|
.format(tool, os, old, new)
|
|
|
|
message += '{} (cc {}, @rust-lang/infra).\n' \
|
|
|
|
.format(title, MAINTAINERS.get(tool))
|
2018-12-19 09:37:16 -06:00
|
|
|
# only create issues for build failures. Other failures can be spurious
|
|
|
|
if new == 'build-fail':
|
2018-12-19 10:44:46 -06:00
|
|
|
build_failed = True
|
2018-12-19 08:54:51 -06:00
|
|
|
|
2018-12-19 10:44:46 -06:00
|
|
|
if build_failed:
|
2019-02-12 07:48:53 -06:00
|
|
|
try:
|
|
|
|
issue(
|
|
|
|
tool, MAINTAINERS.get(tool),
|
|
|
|
relevant_pr_number, relevant_pr_user, pr_reviewer,
|
|
|
|
)
|
2019-02-15 00:26:27 -06:00
|
|
|
except IOError as e:
|
2019-02-12 07:48:53 -06:00
|
|
|
# network errors will simply end up not creating an issue, but that's better
|
|
|
|
# than failing the entire build job
|
2019-02-15 00:26:27 -06:00
|
|
|
print("I/O error: {0}".format(e))
|
2019-02-12 07:48:53 -06:00
|
|
|
except:
|
2019-02-15 00:26:27 -06:00
|
|
|
print("Unexpected error: {0}".format(sys.exc_info()[0]))
|
2019-02-12 07:48:53 -06:00
|
|
|
raise
|
2017-12-04 08:31:57 -06:00
|
|
|
|
|
|
|
if changed:
|
|
|
|
status['commit'] = current_commit
|
|
|
|
status['datetime'] = current_datetime
|
|
|
|
anything_changed = True
|
|
|
|
|
|
|
|
if not anything_changed:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
f.seek(0)
|
|
|
|
f.truncate(0)
|
|
|
|
json.dump(latest, f, indent=4, separators=(',', ': '))
|
|
|
|
return message
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
cur_commit = sys.argv[1]
|
|
|
|
cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
cur_commit_msg = sys.argv[2]
|
|
|
|
save_message_to_path = sys.argv[3]
|
2018-02-21 08:58:06 -06:00
|
|
|
github_token = sys.argv[4]
|
2017-12-04 08:31:57 -06:00
|
|
|
|
2018-12-19 09:37:16 -06:00
|
|
|
# assume that PR authors are also owners of the repo where the branch lives
|
2018-12-20 07:29:42 -06:00
|
|
|
relevant_pr_match = re.search(
|
2019-02-17 09:19:47 -06:00
|
|
|
r'Auto merge of #([0-9]+) - ([^:]+):[^,]+, r=(\S+)',
|
2018-12-20 07:29:42 -06:00
|
|
|
cur_commit_msg,
|
|
|
|
)
|
2017-12-04 08:31:57 -06:00
|
|
|
if relevant_pr_match:
|
2018-02-21 08:25:12 -06:00
|
|
|
number = relevant_pr_match.group(1)
|
2018-12-18 06:33:02 -06:00
|
|
|
relevant_pr_user = relevant_pr_match.group(2)
|
2018-02-21 08:25:12 -06:00
|
|
|
relevant_pr_number = 'rust-lang/rust#' + number
|
|
|
|
relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
|
2018-12-19 10:44:46 -06:00
|
|
|
pr_reviewer = relevant_pr_match.group(3)
|
2017-12-04 08:31:57 -06:00
|
|
|
else:
|
2018-02-21 08:58:06 -06:00
|
|
|
number = '-1'
|
2019-02-17 09:19:47 -06:00
|
|
|
relevant_pr_user = 'ghost'
|
2017-12-04 08:31:57 -06:00
|
|
|
relevant_pr_number = '<unknown PR>'
|
2018-02-21 08:25:12 -06:00
|
|
|
relevant_pr_url = '<unknown>'
|
2019-02-17 09:19:47 -06:00
|
|
|
pr_reviewer = 'ghost'
|
2018-02-21 08:25:12 -06:00
|
|
|
|
|
|
|
message = update_latest(
|
|
|
|
cur_commit,
|
|
|
|
relevant_pr_number,
|
|
|
|
relevant_pr_url,
|
2018-12-18 06:33:02 -06:00
|
|
|
relevant_pr_user,
|
2018-12-19 10:44:46 -06:00
|
|
|
pr_reviewer,
|
2018-02-21 08:25:12 -06:00
|
|
|
cur_datetime
|
|
|
|
)
|
2018-02-21 08:58:06 -06:00
|
|
|
if not message:
|
2017-12-04 08:31:57 -06:00
|
|
|
print('<Nothing changed>')
|
2018-02-21 08:58:06 -06:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
print(message)
|
2018-12-15 09:44:46 -06:00
|
|
|
|
|
|
|
if not github_token:
|
|
|
|
print('Dry run only, not committing anything')
|
|
|
|
sys.exit(0)
|
|
|
|
|
2018-02-21 08:58:06 -06:00
|
|
|
with open(save_message_to_path, 'w') as f:
|
|
|
|
f.write(message)
|
|
|
|
|
|
|
|
# Write the toolstate comment on the PR as well.
|
|
|
|
gh_url = 'https://api.github.com/repos/rust-lang/rust/issues/{}/comments' \
|
|
|
|
.format(number)
|
|
|
|
response = urllib2.urlopen(urllib2.Request(
|
|
|
|
gh_url,
|
|
|
|
json.dumps({'body': message}),
|
|
|
|
{
|
|
|
|
'Authorization': 'token ' + github_token,
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
}
|
|
|
|
))
|
|
|
|
response.read()
|