SERVER-83283 Modify copybara script to send slack message on failure (#17021)

GitOrigin-RevId: 95cb69586f2d7f5930c8f22ea8ec6b6617a94080
This commit is contained in:
Juan Gu 2023-11-17 17:31:13 -08:00 committed by MongoDB Bot
parent 07870b62ff
commit a5b4c7acdc
4 changed files with 24 additions and 3 deletions

View File

@ -8,6 +8,7 @@ from typing import Optional
from github import GithubIntegration
from buildscripts.util.read_config import read_config_file
from evergreen.api import RetryingEvergreenApi
def run_command(command): # noqa: D406,D407
@ -73,6 +74,24 @@ def get_installation_access_token(app_id: int, private_key: str,
return None
def send_failure_message_to_slack(expansions):
"""
Send a failure message to a specific Slack channel when the Copybara task fails.
:param expansions: Dictionary containing various expansion data.
"""
current_version_id = expansions.get("version_id", None)
error_msg = (
"Evergreen task '* Copybara Sync Between Repos' failed\n"
f"For more details: <https://spruce.mongodb.com/version/{current_version_id}|here>.")
evg_api = RetryingEvergreenApi.get_api(config_file=".evergreen.yml")
evg_api.send_slack_message(
target="#sdp-triager",
msg=error_msg,
)
def main():
"""Clone the Copybara repo, build its Docker image, and set up and run migrations."""
parser = argparse.ArgumentParser()
@ -131,7 +150,8 @@ def main():
for acceptable_message in acceptable_error_messages):
return
raise
# Send a failure message to #sdp-triager if the Copybara sync task fails.
send_failure_message_to_slack(expansions)
if __name__ == "__main__":

View File

@ -5339,6 +5339,7 @@ tasks:
- *git_get_project
- *set_task_expansion_macros
- *set_up_virtualenv
- func: "configure evergreen api credentials"
- command: expansions.write
params:
file: src/expansions.yml

View File

@ -1,5 +1,5 @@
click ~= 7.0
dataclasses; python_version < "3.7"
GitPython ~= 3.1.7
pydantic ~= 1.7.3
pydantic ~= 1.8.2
structlog ~= 19.2.0

View File

@ -1,5 +1,5 @@
PyKMIP == 0.4.0 # It's now 0.8.0. We're far enough back to have API conflicts.
evergreen.py == 2.1.0
evergreen.py == 3.1.0
jinja2 <= 2.11.3
MarkupSafe == 1.1.0 # See SERVER-57036, this is a transitive dependency of jinja2
mock <= 4.0.3