aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Burgess IV <gbiv@google.com>2021-12-09 00:28:14 -0800
committerCommit Bot <commit-bot@chromium.org>2021-12-13 18:41:52 +0000
commite8d03f7ea49a9ee46d672ed9ad3582ab591fd9f1 (patch)
treef61cae9ea699b3c17ee4a9ac5570e09ec3a88d99
parent443e0b362f02045134713114bb34a4afad8090da (diff)
downloadtoolchain-utils-e8d03f7ea49a9ee46d672ed9ad3582ab591fd9f1.tar.gz
rust_watch: report bugs for new minor or major versions of rustc
Now that we have new bug reporting bits, using them seems cool. File bugs for uprevving to each new (non-patch) version, so we no longer have to. BUG=None TEST=Unittests Change-Id: I2b458cfd92bcdfda2f4bd8fbac319c1d05c44b47 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3324374 Reviewed-by: Bob Haarman <inglorion@chromium.org> Commit-Queue: George Burgess <gbiv@chromium.org> Tested-by: George Burgess <gbiv@chromium.org>
-rwxr-xr-xrust_tools/rust_watch.py110
-rwxr-xr-xrust_tools/rust_watch_test.py107
2 files changed, 107 insertions, 110 deletions
diff --git a/rust_tools/rust_watch.py b/rust_tools/rust_watch.py
index b2c94acd..db6ae71b 100755
--- a/rust_tools/rust_watch.py
+++ b/rust_tools/rust_watch.py
@@ -19,10 +19,9 @@ import shutil
import subprocess
import sys
import time
-from typing import Any, Dict, Iterable, List, Optional, Tuple, NamedTuple
+from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple
-from cros_utils import email_sender
-from cros_utils import tiny_render
+from cros_utils import bugs, email_sender, tiny_render
def gentoo_sha_to_link(sha: str) -> str:
@@ -223,43 +222,63 @@ def atomically_write_state(state_file: pathlib.Path, state: State) -> None:
temp_file.rename(state_file)
-def maybe_compose_email(old_state: State, newest_release: RustReleaseVersion,
- new_gentoo_commits: List[GitCommit]
- ) -> Optional[Tuple[str, List[tiny_render.Piece]]]:
+def file_bug(title: str, body: str) -> None:
+ """Files a bug against gbiv@ with the given title/body."""
+ bugs.CreateNewBug(
+ bugs.WellKnownComponents.CrOSToolchainPublic,
+ title,
+ body,
+ # To either take or reassign depending on the rotation.
+ assignee='gbiv@google.com',
+ )
+
+
+def maybe_compose_bug(
+ old_state: State,
+ newest_release: RustReleaseVersion,
+) -> Optional[Tuple[str, str]]:
+ """Creates a bug to file about the new release, if doing is desired."""
+ if newest_release == old_state.last_seen_release:
+ return None
+
+ title = f'New rustc release detected: v{newest_release}'
+ body = ('A new release has been detected; we should probably roll to it. '
+ "Please see go/crostc-rust-rotation for who's turn it is.")
+ return title, body
+
+
+def maybe_compose_email(
+ new_gentoo_commits: List[GitCommit]
+) -> Optional[Tuple[str, List[tiny_render.Piece]]]:
"""Creates an email given our new state, if doing so is appropriate."""
+ if not new_gentoo_commits:
+ return None
+
subject_pieces = []
body_pieces = []
- if newest_release > old_state.last_seen_release:
- subject_pieces.append('new rustc release detected')
- body_pieces.append(f'Rustc tag for v{newest_release} was found.')
+ # Separate the sections a bit for prettier output.
+ if body_pieces:
+ body_pieces += [tiny_render.line_break, tiny_render.line_break]
- if new_gentoo_commits:
- # Separate the sections a bit for prettier output.
- if body_pieces:
- body_pieces += [tiny_render.line_break, tiny_render.line_break]
+ if len(new_gentoo_commits) == 1:
+ subject_pieces.append('new rust ebuild commit detected')
+ body_pieces.append('commit:')
+ else:
+ subject_pieces.append('new rust ebuild commits detected')
+ body_pieces.append('commits (newest first):')
+
+ commit_lines = []
+ for commit in new_gentoo_commits:
+ commit_lines.append([
+ tiny_render.Link(
+ gentoo_sha_to_link(commit.sha),
+ commit.sha[:12],
+ ),
+ f': {commit.subject}',
+ ])
- if len(new_gentoo_commits) == 1:
- subject_pieces.append('new rust ebuild commit detected')
- body_pieces.append('commit:')
- else:
- subject_pieces.append('new rust ebuild commits detected')
- body_pieces.append('commits (newest first):')
-
- commit_lines = []
- for commit in new_gentoo_commits:
- commit_lines.append([
- tiny_render.Link(
- gentoo_sha_to_link(commit.sha),
- commit.sha[:12],
- ),
- f': {commit.subject}',
- ])
-
- body_pieces.append(tiny_render.UnorderedList(commit_lines))
-
- if not subject_pieces:
- return None
+ body_pieces.append(tiny_render.UnorderedList(commit_lines))
subject = '[rust-watch] ' + '; '.join(subject_pieces)
return subject, body_pieces
@@ -274,9 +293,9 @@ def main(argv: List[str]) -> None:
parser.add_argument('--state_dir',
required=True,
help='Directory to store state in.')
- parser.add_argument('--skip_email',
+ parser.add_argument('--skip_side_effects',
action='store_true',
- help="Don't send an email.")
+ help="Don't send an email or file a bug.")
parser.add_argument(
'--skip_state_update',
action='store_true',
@@ -319,14 +338,25 @@ def main(argv: List[str]) -> None:
prior_state.last_gentoo_sha)
logging.info('New commits: %r', new_commits)
- maybe_email = maybe_compose_email(prior_state, most_recent_release,
- new_commits)
+ maybe_bug = maybe_compose_bug(prior_state, most_recent_release)
+ maybe_email = maybe_compose_email(new_commits)
+
+ if maybe_bug is None:
+ logging.info('No bug to file')
+ else:
+ title, body = maybe_bug
+ if opts.skip_side_effects:
+ logging.info('Skipping sending bug with title %r and contents\n%s',
+ title, body)
+ else:
+ logging.info('Writing new bug')
+ file_bug(title, body)
if maybe_email is None:
- logging.info('No updates to send')
+ logging.info('No email to send')
else:
title, body = maybe_email
- if opts.skip_email:
+ if opts.skip_side_effects:
logging.info('Skipping sending email with title %r and contents\n%s',
title, tiny_render.render_html_pieces(body))
else:
diff --git a/rust_tools/rust_watch_test.py b/rust_tools/rust_watch_test.py
index a00f3ddc..30bacbb9 100755
--- a/rust_tools/rust_watch_test.py
+++ b/rust_tools/rust_watch_test.py
@@ -13,16 +13,15 @@ import time
import unittest
import unittest.mock
-import rust_watch
from cros_utils import tiny_render
+import rust_watch
+
class Test(unittest.TestCase):
"""Tests."""
-
def _silence_logs(self):
"""Silences all log output until the end of the current test."""
-
def should_log(_record):
return 0
@@ -38,8 +37,8 @@ class Test(unittest.TestCase):
def test_release_version_json_round_trips(self):
ver = rust_watch.RustReleaseVersion(1, 2, 3)
- self.assertEqual(
- rust_watch.RustReleaseVersion.from_json(ver.to_json()), ver)
+ self.assertEqual(rust_watch.RustReleaseVersion.from_json(ver.to_json()),
+ ver)
def test_state_json_round_trips(self):
state = rust_watch.State(
@@ -96,34 +95,14 @@ class Test(unittest.TestCase):
rust_watch.GitCommit('abc123', 'newer commit'),
])
- def test_compose_email_on_a_new_release(self):
- new_release = rust_watch.maybe_compose_email(
- old_state=rust_watch.State(
- last_seen_release=rust_watch.RustReleaseVersion(1, 0, 0),
- last_gentoo_sha='',
- ),
- newest_release=rust_watch.RustReleaseVersion(1, 1, 0),
- new_gentoo_commits=[],
- )
-
- self.assertEqual(new_release, ('[rust-watch] new rustc release detected',
- ['Rustc tag for v1.1.0 was found.']))
-
def test_compose_email_on_a_new_gentoo_commit(self):
sha_a = 'a' * 40
- new_commit = rust_watch.maybe_compose_email(
- old_state=rust_watch.State(
- last_seen_release=rust_watch.RustReleaseVersion(1, 0, 0),
- last_gentoo_sha='',
+ new_commit = rust_watch.maybe_compose_email(new_gentoo_commits=[
+ rust_watch.GitCommit(
+ sha=sha_a,
+ subject='summary_a',
),
- newest_release=rust_watch.RustReleaseVersion(1, 0, 0),
- new_gentoo_commits=[
- rust_watch.GitCommit(
- sha=sha_a,
- subject='summary_a',
- ),
- ],
- )
+ ], )
self.assertEqual(new_commit,
('[rust-watch] new rust ebuild commit detected', [
@@ -139,60 +118,48 @@ class Test(unittest.TestCase):
])
]))
- def test_compose_email_on_multiple_events(self):
- sha_a = 'a' * 40
- new_commit_and_release = rust_watch.maybe_compose_email(
+ def test_compose_email_composes_nothing_when_no_new_updates_exist(self):
+ self.assertIsNone(rust_watch.maybe_compose_email(new_gentoo_commits=()))
+
+ def test_compose_bug_creates_bugs_on_new_versions(self):
+ title, body = rust_watch.maybe_compose_bug(
+ old_state=rust_watch.State(
+ last_seen_release=rust_watch.RustReleaseVersion(1, 0, 0),
+ last_gentoo_sha='',
+ ),
+ newest_release=rust_watch.RustReleaseVersion(1, 0, 1),
+ )
+ self.assertEqual(title, 'New rustc release detected: v1.0.1')
+ self.assertTrue(body.startswith('A new release has been detected;'))
+
+ title, body = rust_watch.maybe_compose_bug(
old_state=rust_watch.State(
last_seen_release=rust_watch.RustReleaseVersion(1, 0, 0),
last_gentoo_sha='',
),
newest_release=rust_watch.RustReleaseVersion(1, 1, 0),
- new_gentoo_commits=[
- rust_watch.GitCommit(
- sha=sha_a,
- subject='summary_a',
- ),
- ],
)
+ self.assertEqual(title, 'New rustc release detected: v1.1.0')
+ self.assertTrue(body.startswith('A new release has been detected;'))
- self.assertEqual(
- new_commit_and_release,
- ('[rust-watch] new rustc release detected; new rust ebuild commit '
- 'detected', [
- 'Rustc tag for v1.1.0 was found.',
- tiny_render.line_break,
- tiny_render.line_break,
- 'commit:',
- tiny_render.UnorderedList([
- [
- tiny_render.Link(
- rust_watch.gentoo_sha_to_link(sha_a),
- sha_a[:12],
- ),
- ': summary_a',
- ],
- ]),
- ]))
+ title, body = rust_watch.maybe_compose_bug(
+ old_state=rust_watch.State(
+ last_seen_release=rust_watch.RustReleaseVersion(1, 0, 0),
+ last_gentoo_sha='',
+ ),
+ newest_release=rust_watch.RustReleaseVersion(2, 0, 0),
+ )
+ self.assertEqual(title, 'New rustc release detected: v2.0.0')
+ self.assertTrue(body.startswith('A new release has been detected;'))
- def test_compose_email_composes_nothing_when_no_new_updates_exist(self):
+ def test_compose_bug_does_nothing_when_no_new_updates_exist(self):
self.assertIsNone(
- rust_watch.maybe_compose_email(
+ rust_watch.maybe_compose_bug(
old_state=rust_watch.State(
last_seen_release=rust_watch.RustReleaseVersion(1, 0, 0),
last_gentoo_sha='',
),
newest_release=rust_watch.RustReleaseVersion(1, 0, 0),
- new_gentoo_commits=[],
- ))
-
- self.assertIsNone(
- rust_watch.maybe_compose_email(
- old_state=rust_watch.State(
- last_seen_release=rust_watch.RustReleaseVersion(1, 1, 0),
- last_gentoo_sha='',
- ),
- newest_release=rust_watch.RustReleaseVersion(1, 0, 0),
- new_gentoo_commits=[],
))