From 363632097233bb5d5d771da6912b0ddec1118b37 Mon Sep 17 00:00:00 2001 From: Rob Lemley Date: Fri, 25 Oct 2024 00:06:36 +0000 Subject: [PATCH] Bug 1921559 - Email thunderbird-drivers when promoting build on comm-release. r=thunderbird-build-system-reviewers,coreycbryant Differential Revision: https://phabricator.services.mozilla.com/D224024 --HG-- extra : moz-landing-system : lando --- build/mach_initialize.py | 2 + python/mach_commands.py | 86 +++++++++++++++++++ python/rocbuild/rocbuild/machutil.py | 29 +++++++ python/sites/tb_common.txt | 4 + .../transforms/release_started.py | 13 ++- .../kinds/release-notify-started/kind.yml | 9 +- 6 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 python/mach_commands.py create mode 100644 python/rocbuild/rocbuild/machutil.py diff --git a/build/mach_initialize.py b/build/mach_initialize.py index a84ebb3c3c..a72c5a89ac 100644 --- a/build/mach_initialize.py +++ b/build/mach_initialize.py @@ -70,9 +70,11 @@ def initialize(topsrcdir, args=()): "tb-l10n-x-channel": MachCommandReference("comm/python/l10n/mach_commands.py"), "tb-rust": MachCommandReference("comm/rust/mach_commands.py"), "tb-storybook": MachCommandReference("comm/mail/components/storybook/mach_commands.py"), + "tb-release": MachCommandReference("comm/python/mach_commands.py"), } MACH_COMMANDS.update(COMM_MACH_COMMANDS) + # Gets added afterward since it's adding a new subcommand to "mach release" driver = mach_init.initialize(topsrcdir, args) return driver diff --git a/python/mach_commands.py b/python/mach_commands.py new file mode 100644 index 0000000000..3116f446ba --- /dev/null +++ b/python/mach_commands.py @@ -0,0 +1,86 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import os + +from mozilla_version.gecko import GeckoVersion + +from mach.decorators import Command, CommandArgument, SubCommand + + +@Command("tb-release", category="thunderbird", virtualenv_name="tb_common") +def tb_release(command_context): + pass + + +@SubCommand( + "tb-release", + "send-buglist-email-thunderbird", + description="Send an email with the bugs since the last release.", +) +@CommandArgument( + "--address", + required=True, + action="append", + dest="addresses", + help="The email address to send the bug list to " "(may be specified more than once.", +) +@CommandArgument( + "--version", + type=GeckoVersion.parse, + required=True, + help="The version being built.", +) +@CommandArgument("--product", required=True, help="The product being built.") +@CommandArgument("--repo", required=True, help="The repo being built.") +@CommandArgument("--revision", required=True, help="The revision being built.") +@CommandArgument("--build-number", required=True, help="The build number") +@CommandArgument("--task-group-id", help="The task group of the build.") +@CommandArgument("--prefix-message", help="A message to insert into the email body.") +def buglist_email( + command_context, + addresses, + product, + version, + repo, + revision, + build_number, + task_group_id, + prefix_message, +): + import base64 + + from mozrelease.buglist_creator import create_bugs_url + + from rocbuild.machutil import setup_logging + from rocbuild.notify import email_notification + + setup_logging(command_context) + + email_buglist_string = create_bugs_url(product, version, revision, repo=repo) + + if prefix_message is not None: + _msg = base64.b64decode(bytes(prefix_message.encode("utf-8"))).decode() + release_prefix_msg = f"\n{_msg}\n" + else: + release_prefix_msg = "" + + content = """\ +A new build has been started: +{release_prefix_msg} +Commit: [{revision}]({repo}/rev/{revision}) +Task group: [{task_group_id}]({root_url}/tasks/groups/{task_group_id}) + +{email_buglist_string} + """.format( + release_prefix_msg=release_prefix_msg, + repo=repo, + revision=revision, + root_url=os.environ["TASKCLUSTER_ROOT_URL"], + task_group_id=task_group_id, + email_buglist_string=email_buglist_string, + ) + print(content) + subject = "[Thunderbird] Build of {} {} build {}".format(product, version, build_number) + email_notification(subject, content, addresses) diff --git a/python/rocbuild/rocbuild/machutil.py b/python/rocbuild/rocbuild/machutil.py new file mode 100644 index 0000000000..4193282706 --- /dev/null +++ b/python/rocbuild/rocbuild/machutil.py @@ -0,0 +1,29 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import logging +import sys + + +def setup_logging(command_context, quiet=False, verbose=True): + """ + Set up Python logging for all loggers, sending results to stderr (so + that command output can be redirected easily) and adding the typical + mach timestamp. + """ + # remove the old terminal handler + old = command_context.log_manager.replace_terminal_handler(None) + + # re-add it, with level and fh set appropriately + if not quiet: + level = logging.DEBUG if verbose else logging.INFO + command_context.log_manager.add_terminal_logging( + fh=sys.stderr, + level=level, + write_interval=old.formatter.write_interval, + write_times=old.formatter.write_times, + ) + + # all of the taskgraph logging is unstructured logging + command_context.log_manager.enable_unstructured() diff --git a/python/sites/tb_common.txt b/python/sites/tb_common.txt index 8511ca6dc9..323e789ce8 100644 --- a/python/sites/tb_common.txt +++ b/python/sites/tb_common.txt @@ -7,6 +7,10 @@ vendored:comm/third_party/python/fluent.migratetb vendored:third_party/python/compare_locales vendored:third_party/python/fluent.migrate vendored:third_party/python/fluent.syntax +vendored:third_party/python/mohawk vendored:third_party/python/packaging +vendored:third_party/python/slugid +vendored:third_party/python/taskcluster +vendored:third_party/python/taskcluster_urls vendored:third_party/python/toml vendored:third_party/python/typing_extensions diff --git a/taskcluster/comm_taskgraph/transforms/release_started.py b/taskcluster/comm_taskgraph/transforms/release_started.py index ce0cfa9fab..97b8e9ea5d 100644 --- a/taskcluster/comm_taskgraph/transforms/release_started.py +++ b/taskcluster/comm_taskgraph/transforms/release_started.py @@ -5,6 +5,7 @@ Add notifications via taskcluster-notify for release tasks """ +import base64 from pipes import quote as shell_quote from taskgraph.transforms.base import TransformSequence @@ -21,9 +22,14 @@ def add_notifications(config, jobs): resolve_keyed_by(job, "emails", label, project=config.params["project"]) emails = [email.format(config=config.__dict__) for email in job.pop("emails")] + resolve_keyed_by(job, "prefix-message", label, project=config.params["project"]) + prefix_message = "" + if msg := job.pop("prefix-message"): + prefix_message = base64.b64encode(bytes(msg.encode("utf-8"))).decode() + command = [ - "release", - "send-buglist-email", + "tb-release", + "send-buglist-email-thunderbird", "--version", config.params["version"], "--product", @@ -34,6 +40,8 @@ def add_notifications(config, jobs): str(config.params["build_number"]), "--repo", config.params["comm_head_repository"], + "--prefix-message", + prefix_message, ] for address in emails: command += ["--address", address] @@ -46,6 +54,7 @@ def add_notifications(config, jobs): job["scopes"] = ["notify:email:{}".format(address) for address in emails] job["run"] = { "using": "mach", + "comm-checkout": True, "sparse-profile": "mach", "mach": {"task-reference": " ".join(map(shell_quote, command))}, } diff --git a/taskcluster/kinds/release-notify-started/kind.yml b/taskcluster/kinds/release-notify-started/kind.yml index 8ded9d2c7e..1c42bb7897 100644 --- a/taskcluster/kinds/release-notify-started/kind.yml +++ b/taskcluster/kinds/release-notify-started/kind.yml @@ -21,9 +21,16 @@ task-defaults: max-run-time: 600 emails: by-project: - comm-(beta|esr.*): ["thunderbird-drivers@mozilla.org"] + comm-(beta|release|esr.*): ["thunderbird-drivers@mozilla.org"] try-comm-central: ["{config[params][owner]}"] default: [] + prefix-message: + by-project: + comm-release: | + **This is a preview release of Thunderbird's monthly releases.** + + Thunderbird monthly releases are not considered stable for general use. + default: null tasks: thunderbird: