]> git.lizzy.rs Git - rust.git/blob - src/tools/publish_toolstate.py
Auto merge of #46916 - michaelwoerister:generate-dead-code-plz, r=alexcrichton
[rust.git] / src / tools / publish_toolstate.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # Copyright 2017 The Rust Project Developers. See the COPYRIGHT
5 # file at the top-level directory of this distribution and at
6 # http://rust-lang.org/COPYRIGHT.
7 #
8 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
9 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
10 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
11 # option. This file may not be copied, modified, or distributed
12 # except according to those terms.
13
14 import sys
15 import re
16 import json
17 import copy
18 import datetime
19 import collections
20
21 # List of people to ping when the status of a tool changed.
22 MAINTAINERS = {
23     'miri': '@oli-obk @RalfJung @eddyb',
24     'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk',
25     'rls': '@nrc',
26     'rustfmt': '@nrc',
27 }
28
29
30 def read_current_status(current_commit, path):
31     '''Reads build status of `current_commit` from content of `history/*.tsv`
32     '''
33     with open(path, 'rU') as f:
34         for line in f:
35             (commit, status) = line.split('\t', 1)
36             if commit == current_commit:
37                 return json.loads(status)
38     return {}
39
40
41 def update_latest(current_commit, relevant_pr_number, current_datetime):
42     '''Updates `_data/latest.json` to match build result of the given commit.
43     '''
44     with open('_data/latest.json', 'rb+') as f:
45         latest = json.load(f, object_pairs_hook=collections.OrderedDict)
46
47         current_status = {
48             os: read_current_status(current_commit, 'history/' + os + '.tsv')
49             for os in ['windows', 'linux']
50         }
51
52         slug = 'rust-lang/rust'
53         message = '📣 Toolstate changed by {}!\n\nTested on commit {}@{}.\n\n' \
54             .format(relevant_pr_number, slug, current_commit)
55         anything_changed = False
56         for status in latest:
57             tool = status['tool']
58             changed = False
59
60             for os, s in current_status.items():
61                 old = status[os]
62                 new = s.get(tool, old)
63                 status[os] = new
64                 if new > old:
65                     changed = True
66                     message += '🎉 {} on {}: {} â†’ {}.\n' \
67                         .format(tool, os, old, new)
68                 elif new < old:
69                     changed = True
70                     message += '💔 {} on {}: {} â†’ {} (cc {}).\n' \
71                         .format(tool, os, old, new, MAINTAINERS[tool])
72
73             if changed:
74                 status['commit'] = current_commit
75                 status['datetime'] = current_datetime
76                 anything_changed = True
77
78         if not anything_changed:
79             return ''
80
81         f.seek(0)
82         f.truncate(0)
83         json.dump(latest, f, indent=4, separators=(',', ': '))
84         return message
85
86
87 if __name__ == '__main__':
88     cur_commit = sys.argv[1]
89     cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
90     cur_commit_msg = sys.argv[2]
91     save_message_to_path = sys.argv[3]
92
93     relevant_pr_match = re.search('#[0-9]+', cur_commit_msg)
94     if relevant_pr_match:
95         relevant_pr_number = 'rust-lang/rust' + relevant_pr_match.group(0)
96     else:
97         relevant_pr_number = '<unknown PR>'
98
99     message = update_latest(cur_commit, relevant_pr_number, cur_datetime)
100     if message:
101         print(message)
102         with open(save_message_to_path, 'w') as f:
103             f.write(message)
104     else:
105         print('<Nothing changed>')