2017-12-04 22:31:57 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-07-23 10:54:30 +02:00
|
|
|
## This script publishes the new "current" toolstate in the toolstate repo (not to be
|
|
|
|
## confused with publishing the test results, which happens in
|
|
|
|
## `src/ci/docker/x86_64-gnu-tools/checktools.sh`).
|
|
|
|
## It is set as callback for `src/ci/docker/x86_64-gnu-tools/repo.sh` by the CI scripts
|
2019-07-23 10:50:45 +02:00
|
|
|
## when a new commit lands on `master` (i.e., after it passed all checks on `auto`).
|
|
|
|
|
2017-12-04 22:31:57 +08:00
|
|
|
import sys
|
|
|
|
import re
|
2019-06-12 07:59:20 -07:00
|
|
|
import os
|
2017-12-04 22:31:57 +08:00
|
|
|
import json
|
|
|
|
import datetime
|
|
|
|
import collections
|
2018-02-21 22:25:12 +08:00
|
|
|
import textwrap
|
2018-02-21 22:58:06 +08:00
|
|
|
try:
|
|
|
|
import urllib2
|
|
|
|
except ImportError:
|
|
|
|
import urllib.request as urllib2
|
2017-12-04 22:31:57 +08:00
|
|
|
|
2019-03-09 14:28:25 +08:00
|
|
|
# List of people to ping when the status of a tool or a book changed.
|
2017-12-04 22:31:57 +08:00
|
|
|
MAINTAINERS = {
|
|
|
|
'miri': '@oli-obk @RalfJung @eddyb',
|
2019-08-28 13:23:00 +02:00
|
|
|
'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk @phansch @flip1995',
|
2019-04-17 22:07:13 +12:00
|
|
|
'rls': '@Xanewok',
|
|
|
|
'rustfmt': '@topecongiro',
|
2018-02-22 03:25:23 +08:00
|
|
|
'book': '@carols10cents @steveklabnik',
|
|
|
|
'nomicon': '@frewsxcv @Gankro',
|
2019-03-28 10:23:15 -07:00
|
|
|
'reference': '@steveklabnik @Havvy @matthewjasper @ehuss',
|
2018-02-22 03:25:23 +08:00
|
|
|
'rust-by-example': '@steveklabnik @marioidival @projektir',
|
2019-03-10 18:02:40 +08:00
|
|
|
'embedded-book': (
|
|
|
|
'@adamgreig @andre-richter @jamesmunns @korken89 '
|
|
|
|
'@ryankurte @thejpster @therealprof'
|
|
|
|
),
|
2019-03-28 10:23:15 -07:00
|
|
|
'edition-guide': '@ehuss @Centril @steveklabnik',
|
2019-08-21 10:16:57 -05:00
|
|
|
'rustc-guide': '@mark-i-m @spastorino @amanjeev'
|
2017-12-04 22:31:57 +08:00
|
|
|
}
|
|
|
|
|
2018-12-19 17:44:46 +01:00
|
|
|
REPOS = {
|
2019-02-21 19:26:45 +01:00
|
|
|
'miri': 'https://github.com/rust-lang/miri',
|
2018-12-19 17:44:46 +01: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',
|
2019-03-09 14:28:25 +08:00
|
|
|
'embedded-book': 'https://github.com/rust-embedded/book',
|
2019-03-28 10:23:15 -07:00
|
|
|
'edition-guide': 'https://github.com/rust-lang-nursery/edition-guide',
|
2019-04-04 13:06:05 -03:00
|
|
|
'rustc-guide': 'https://github.com/rust-lang/rustc-guide',
|
2018-12-19 17:44:46 +01:00
|
|
|
}
|
|
|
|
|
2017-12-04 22:31:57 +08: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 {}
|
|
|
|
|
2019-06-12 07:59:20 -07:00
|
|
|
def gh_url():
|
|
|
|
return os.environ['TOOLSTATE_ISSUES_API_URL']
|
|
|
|
|
|
|
|
def maybe_delink(message):
|
|
|
|
if os.environ.get('TOOLSTATE_SKIP_MENTIONS') is not None:
|
|
|
|
return message.replace("@", "")
|
|
|
|
return message
|
|
|
|
|
2018-12-18 13:33:02 +01:00
|
|
|
def issue(
|
|
|
|
tool,
|
2019-06-18 21:57:31 +02:00
|
|
|
status,
|
2018-12-18 13:33:02 +01:00
|
|
|
maintainers,
|
|
|
|
relevant_pr_number,
|
|
|
|
relevant_pr_user,
|
2018-12-19 17:44:46 +01:00
|
|
|
pr_reviewer,
|
2018-12-18 13:33:02 +01:00
|
|
|
):
|
|
|
|
# Open an issue about the toolstate failure.
|
|
|
|
assignees = [x.strip() for x in maintainers.split('@') if x != '']
|
2019-06-18 21:57:31 +02:00
|
|
|
if status == 'test-fail':
|
|
|
|
status_description = 'has failing tests'
|
|
|
|
else:
|
|
|
|
status_description = 'no longer builds'
|
2019-06-21 13:46:46 +02:00
|
|
|
request = json.dumps({
|
|
|
|
'body': maybe_delink(textwrap.dedent('''\
|
|
|
|
Hello, this is your friendly neighborhood mergebot.
|
|
|
|
After merging PR {}, I observed that the tool {} {}.
|
|
|
|
A follow-up PR to the repository {} is needed to fix the fallout.
|
2018-12-18 13:33:02 +01:00
|
|
|
|
2019-06-21 13:46:46 +02:00
|
|
|
cc @{}, do you think you would have time to do the follow-up work?
|
|
|
|
If so, that would be great!
|
2018-12-19 15:54:51 +01:00
|
|
|
|
2019-06-21 13:46:46 +02:00
|
|
|
cc @{}, the PR reviewer, and @rust-lang/compiler -- nominating for prioritization.
|
2018-12-19 15:54:51 +01:00
|
|
|
|
2019-06-21 13:46:46 +02:00
|
|
|
''').format(
|
|
|
|
relevant_pr_number, tool, status_description,
|
|
|
|
REPOS.get(tool), relevant_pr_user, pr_reviewer
|
|
|
|
)),
|
|
|
|
'title': '`{}` no longer builds after {}'.format(tool, relevant_pr_number),
|
|
|
|
'assignees': assignees,
|
|
|
|
'labels': ['T-compiler', 'I-nominated'],
|
|
|
|
})
|
|
|
|
print("Creating issue:\n{}".format(request))
|
|
|
|
response = urllib2.urlopen(urllib2.Request(
|
|
|
|
gh_url(),
|
|
|
|
request,
|
2018-12-18 13:33:02 +01:00
|
|
|
{
|
|
|
|
'Authorization': 'token ' + github_token,
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
}
|
|
|
|
))
|
|
|
|
response.read()
|
2017-12-04 22:31:57 +08:00
|
|
|
|
2018-02-21 22:25:12 +08:00
|
|
|
def update_latest(
|
|
|
|
current_commit,
|
|
|
|
relevant_pr_number,
|
|
|
|
relevant_pr_url,
|
2018-12-18 13:33:02 +01:00
|
|
|
relevant_pr_user,
|
2018-12-19 17:44:46 +01:00
|
|
|
pr_reviewer,
|
2018-02-21 22:25:12 +08:00
|
|
|
current_datetime
|
|
|
|
):
|
2017-12-04 22:31:57 +08: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 14:57:17 +01:00
|
|
|
message = textwrap.dedent('''\
|
|
|
|
📣 Toolstate changed by {}!
|
|
|
|
|
2018-02-21 22:25:12 +08:00
|
|
|
Tested on commit {}@{}.
|
|
|
|
Direct link to PR: <{}>
|
|
|
|
|
2018-12-15 14:57:17 +01:00
|
|
|
''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
|
2017-12-04 22:31:57 +08:00
|
|
|
anything_changed = False
|
|
|
|
for status in latest:
|
|
|
|
tool = status['tool']
|
|
|
|
changed = False
|
2019-06-21 13:07:44 +02:00
|
|
|
create_issue_for_status = None # set to the status that caused the issue
|
2017-12-04 22:31:57 +08:00
|
|
|
|
|
|
|
for os, s in current_status.items():
|
|
|
|
old = status[os]
|
|
|
|
new = s.get(tool, old)
|
|
|
|
status[os] = new
|
2019-06-21 13:07:44 +02:00
|
|
|
if new > old: # comparing the strings, but they are ordered appropriately!
|
2018-12-19 16:37:16 +01:00
|
|
|
# things got fixed or at least the status quo improved
|
2017-12-04 22:31:57 +08:00
|
|
|
changed = True
|
2018-12-15 14:57:17 +01:00
|
|
|
message += '🎉 {} on {}: {} → {} (cc {}, @rust-lang/infra).\n' \
|
|
|
|
.format(tool, os, old, new, MAINTAINERS.get(tool))
|
2017-12-04 22:31:57 +08:00
|
|
|
elif new < old:
|
2018-12-19 16:37:16 +01:00
|
|
|
# tests or builds are failing and were not failing before
|
2017-12-04 22:31:57 +08:00
|
|
|
changed = True
|
2018-12-18 13:33:02 +01:00
|
|
|
title = '💔 {} on {}: {} → {}' \
|
|
|
|
.format(tool, os, old, new)
|
|
|
|
message += '{} (cc {}, @rust-lang/infra).\n' \
|
|
|
|
.format(title, MAINTAINERS.get(tool))
|
2019-06-18 21:57:31 +02:00
|
|
|
# Most tools only create issues for build failures.
|
|
|
|
# Other failures can be spurious.
|
|
|
|
if new == 'build-fail' or (tool == 'miri' and new == 'test-fail'):
|
2019-06-21 13:07:44 +02:00
|
|
|
create_issue_for_status = new
|
2018-12-19 15:54:51 +01:00
|
|
|
|
2019-06-21 13:07:44 +02:00
|
|
|
if create_issue_for_status is not None:
|
2019-02-12 14:48:53 +01:00
|
|
|
try:
|
|
|
|
issue(
|
2019-06-21 13:07:44 +02:00
|
|
|
tool, create_issue_for_status, MAINTAINERS.get(tool, ''),
|
2019-02-12 14:48:53 +01:00
|
|
|
relevant_pr_number, relevant_pr_user, pr_reviewer,
|
|
|
|
)
|
2019-06-21 19:22:46 +02:00
|
|
|
except urllib2.HTTPError as e:
|
2019-02-12 14:48:53 +01:00
|
|
|
# network errors will simply end up not creating an issue, but that's better
|
|
|
|
# than failing the entire build job
|
2019-06-21 20:47:42 +02:00
|
|
|
print("HTTPError when creating issue for status regression: {0}\n{1}"
|
|
|
|
.format(e, e.read()))
|
2019-06-21 19:22:46 +02:00
|
|
|
except IOError as e:
|
2019-06-21 13:40:57 +02:00
|
|
|
print("I/O error when creating issue for status regression: {0}".format(e))
|
2019-02-12 14:48:53 +01:00
|
|
|
except:
|
2019-06-21 14:07:20 +02:00
|
|
|
print("Unexpected error when creating issue for status regression: {0}"
|
|
|
|
.format(sys.exc_info()[0]))
|
2019-02-12 14:48:53 +01:00
|
|
|
raise
|
2017-12-04 22:31:57 +08: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 22:58:06 +08:00
|
|
|
github_token = sys.argv[4]
|
2017-12-04 22:31:57 +08:00
|
|
|
|
2018-12-19 16:37:16 +01:00
|
|
|
# assume that PR authors are also owners of the repo where the branch lives
|
2018-12-20 14:29:42 +01:00
|
|
|
relevant_pr_match = re.search(
|
2019-02-17 23:19:47 +08:00
|
|
|
r'Auto merge of #([0-9]+) - ([^:]+):[^,]+, r=(\S+)',
|
2018-12-20 14:29:42 +01:00
|
|
|
cur_commit_msg,
|
|
|
|
)
|
2017-12-04 22:31:57 +08:00
|
|
|
if relevant_pr_match:
|
2018-02-21 22:25:12 +08:00
|
|
|
number = relevant_pr_match.group(1)
|
2018-12-18 13:33:02 +01:00
|
|
|
relevant_pr_user = relevant_pr_match.group(2)
|
2018-02-21 22:25:12 +08:00
|
|
|
relevant_pr_number = 'rust-lang/rust#' + number
|
|
|
|
relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
|
2018-12-19 17:44:46 +01:00
|
|
|
pr_reviewer = relevant_pr_match.group(3)
|
2017-12-04 22:31:57 +08:00
|
|
|
else:
|
2018-02-21 22:58:06 +08:00
|
|
|
number = '-1'
|
2019-02-17 23:19:47 +08:00
|
|
|
relevant_pr_user = 'ghost'
|
2017-12-04 22:31:57 +08:00
|
|
|
relevant_pr_number = '<unknown PR>'
|
2018-02-21 22:25:12 +08:00
|
|
|
relevant_pr_url = '<unknown>'
|
2019-02-17 23:19:47 +08:00
|
|
|
pr_reviewer = 'ghost'
|
2018-02-21 22:25:12 +08:00
|
|
|
|
|
|
|
message = update_latest(
|
|
|
|
cur_commit,
|
|
|
|
relevant_pr_number,
|
|
|
|
relevant_pr_url,
|
2018-12-18 13:33:02 +01:00
|
|
|
relevant_pr_user,
|
2018-12-19 17:44:46 +01:00
|
|
|
pr_reviewer,
|
2018-02-21 22:25:12 +08:00
|
|
|
cur_datetime
|
|
|
|
)
|
2018-02-21 22:58:06 +08:00
|
|
|
if not message:
|
2017-12-04 22:31:57 +08:00
|
|
|
print('<Nothing changed>')
|
2018-02-21 22:58:06 +08:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
print(message)
|
2018-12-15 23:44:46 +08:00
|
|
|
|
|
|
|
if not github_token:
|
|
|
|
print('Dry run only, not committing anything')
|
|
|
|
sys.exit(0)
|
|
|
|
|
2018-02-21 22:58:06 +08:00
|
|
|
with open(save_message_to_path, 'w') as f:
|
|
|
|
f.write(message)
|
|
|
|
|
|
|
|
# Write the toolstate comment on the PR as well.
|
2019-06-12 07:59:20 -07:00
|
|
|
issue_url = gh_url() + '/{}/comments'.format(number)
|
2018-02-21 22:58:06 +08:00
|
|
|
response = urllib2.urlopen(urllib2.Request(
|
2019-06-12 07:59:20 -07:00
|
|
|
issue_url,
|
|
|
|
json.dumps({'body': maybe_delink(message)}),
|
2018-02-21 22:58:06 +08:00
|
|
|
{
|
|
|
|
'Authorization': 'token ' + github_token,
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
}
|
|
|
|
))
|
|
|
|
response.read()
|