Repository navigation
GH-46669: [CI][Archery] Automate Zulip and email notifications for Extra CI #47546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9406e99
Initial attempt to automate notifications for CI: Extra
raulcd f35b0c4
Temporarily remove the scheduled time
raulcd f52ecc8
Make it work with fork
raulcd 4760432
Remove unexistent option
raulcd 9257ac1
Add job to ignore
raulcd 9644f8d
Use job name instead of Job id
raulcd 2e27356
Match name and job 'id'
raulcd e4184e6
Intentionally break a job
raulcd 34ed415
Fix
raulcd 355dcd9
Remove some unnecessary things
raulcd fa02d63
Move from arrowci to ci
raulcd 911e5d4
Add webhook as env var
raulcd 16308c1
Add email report and refactor reports to reuse current reporting infr…
raulcd fb20a16
add a couple comments and fix working by changing flag to -t instead …
raulcd 77ff3c5
Fix SMTP server
raulcd 04a0abd
Fix being able to end emails to port 587
raulcd 08c643d
Minor template fix
raulcd bdb577d
Try sending email + zulip notification
raulcd 97c0d85
Add schedule check
raulcd e3f8b9c
Split email and chat steps and order arguments alphabetically
raulcd edfaab4
Temporarily remove check for event_name to validate chat report step …
raulcd 44cd0dc
Add schedule check again
raulcd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import click | ||
|
|
||
| from .core import Workflow | ||
| from ..crossbow.reports import ChatReport, EmailReport, ReportUtils | ||
|
|
||
|
|
||
| @click.group() | ||
| @click.option('--github-token', '-t', default=None, | ||
| envvar=['GH_TOKEN'], | ||
| help='OAuth token for GitHub authentication') | ||
| @click.option('--output-file', metavar='<output>', | ||
| type=click.File('w', encoding='utf8'), default='-', | ||
| help='Capture output result into file.') | ||
| @click.pass_context | ||
| def ci(ctx, github_token, output_file): | ||
| """ | ||
| Tools for CI Extra jobs on GitHub actions. | ||
| """ | ||
| ctx.ensure_object(dict) | ||
| ctx.obj['github_token'] = github_token | ||
| ctx.obj['output'] = output_file | ||
|
|
||
|
|
||
| @ci.command() | ||
| @click.argument('workflow_id', required=True) | ||
| @click.option('--send/--dry-run', default=False, | ||
| help='Just display the report, don\'t send it.') | ||
| @click.option('--repository', '-r', default='apache/arrow', | ||
| help='The repository where the workflow is located.') | ||
| @click.option('--ignore', '-i', default="", | ||
| help='Job name to ignore from the list of jobs.') | ||
| @click.option('--webhook', '-w', envvar=['CHAT_WEBHOOK'], | ||
| help='Zulip/Slack Webhook address to send the report to.') | ||
| @click.option('--extra-message-success', '-s', default=None, | ||
| help='Extra message, will be appended if no failures.') | ||
| @click.option('--extra-message-failure', '-f', default=None, | ||
| help='Extra message, will be appended if there are failures.') | ||
| @click.pass_obj | ||
| def report_chat(obj, workflow_id, send, repository, ignore, webhook, | ||
| extra_message_success, extra_message_failure): | ||
| """ | ||
| Send a chat report to a webhook showing success/failure | ||
| of jobs in a workflow run. | ||
| """ | ||
| output = obj['output'] | ||
|
|
||
| report_chat = ChatReport( | ||
| report=Workflow(workflow_id, repository, | ||
| ignore_job=ignore, gh_token=obj['github_token']), | ||
| extra_message_success=extra_message_success, | ||
| extra_message_failure=extra_message_failure | ||
| ) | ||
| if send: | ||
| ReportUtils.send_message(webhook, report_chat.render("workflow_report")) | ||
| else: | ||
| output.write(report_chat.render("workflow_report")) | ||
|
|
||
|
|
||
| @ci.command() | ||
| @click.argument('workflow_id', required=True) | ||
| @click.option('--sender-name', '-n', | ||
| help='Name to use for report e-mail.') | ||
| @click.option('--sender-email', '-e', | ||
| help='E-mail to use for report e-mail.') | ||
| @click.option('--recipient-email', '-t', | ||
| help='Where to send the e-mail report') | ||
| @click.option('--smtp-user', '-u', | ||
| help='E-mail address to use for SMTP login') | ||
| @click.option('--smtp-password', '-P', envvar=['SMTP_PASSWORD'], | ||
| help='SMTP password to use for report e-mail.') | ||
| @click.option('--smtp-server', '-s', default='smtp.gmail.com', | ||
| help='SMTP server to use for report e-mail.') | ||
| @click.option('--smtp-port', '-p', default=465, | ||
| help='SMTP port to use for report e-mail.') | ||
| @click.option('--send/--dry-run', default=False, | ||
| help='Just display the report, don\'t send it.') | ||
| @click.option('--repository', '-r', default='apache/arrow', | ||
| help='The repository where the workflow is located.') | ||
| @click.option('--ignore', '-i', default="", | ||
| help='Job name to ignore from the list of jobs.') | ||
| @click.pass_obj | ||
| def report_email(obj, workflow_id, sender_name, sender_email, recipient_email, | ||
| smtp_user, smtp_password, smtp_server, smtp_port, send, | ||
| repository, ignore): | ||
| """ | ||
| Send an email report showing success/failure of jobs in | ||
| a Workflow run | ||
| """ | ||
| output = obj['output'] | ||
|
|
||
| email_report = EmailReport( | ||
| report=Workflow(workflow_id, repository, | ||
| ignore_job=ignore, gh_token=obj['github_token']), | ||
| sender_name=sender_name, | ||
| sender_email=sender_email, | ||
| recipient_email=recipient_email | ||
| ) | ||
|
|
||
| if send: | ||
| ReportUtils.send_email( | ||
| smtp_user=smtp_user, | ||
| smtp_password=smtp_password, | ||
| smtp_server=smtp_server, | ||
| smtp_port=smtp_port, | ||
| recipient_email=recipient_email, | ||
| message=email_report.render("workflow_report") | ||
| ) | ||
| else: | ||
| output.write(email_report.render("workflow_report")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from functools import cached_property | ||
|
|
||
| import requests | ||
|
|
||
|
|
||
| class Workflow: | ||
| def __init__(self, workflow_id, repository, ignore_job, gh_token=None): | ||
| self.workflow_id = workflow_id | ||
| self.gh_token = gh_token | ||
| self.repository = repository | ||
| self.ignore_job = ignore_job | ||
| self.headers = { | ||
| 'Accept': 'application/vnd.github.v3+json', | ||
| } | ||
| if self.gh_token: | ||
| self.headers["Authorization"] = f"Bearer {self.gh_token}" | ||
| workflow_resp = requests.get( | ||
| f'https://api.github.com/repos/{repository}/actions/runs/{workflow_id}', | ||
| headers=self.headers | ||
| ) | ||
| if workflow_resp.status_code == 200: | ||
| self.workflow_data = workflow_resp.json() | ||
|
|
||
| else: | ||
| # TODO: We could send an error report instead | ||
| raise Exception( | ||
| f'Failed to fetch workflow data: {workflow_resp.status_code}') | ||
|
|
||
| @property | ||
| def conclusion(self): | ||
| return self.workflow_data.get('conclusion') | ||
|
|
||
| @property | ||
| def jobs_url(self): | ||
| return self.workflow_data.get('jobs_url') | ||
|
|
||
| @property | ||
| def name(self): | ||
| return self.workflow_data.get('name') | ||
|
|
||
| @property | ||
| def url(self): | ||
| return self.workflow_data.get('html_url') | ||
|
|
||
| @cached_property | ||
| def jobs(self): | ||
| jobs = [] | ||
| jobs_resp = requests.get(self.jobs_url, headers=self.headers) | ||
| if jobs_resp.status_code == 200: | ||
| jobs_data = jobs_resp.json() | ||
| for job_data in jobs_data.get('jobs', []): | ||
| if job_data.get('name') != self.ignore_job: | ||
| job = Job(job_data) | ||
| jobs.append(job) | ||
| return jobs | ||
|
|
||
| def failed_jobs(self): | ||
| return [job for job in self.jobs if not job.is_successful()] | ||
|
|
||
| def successful_jobs(self): | ||
| return [job for job in self.jobs if job.is_successful()] | ||
|
|
||
|
|
||
| class Job: | ||
| def __init__(self, job_data): | ||
| self.job_data = job_data | ||
|
|
||
| @property | ||
| def conclusion(self): | ||
| return self.job_data.get('conclusion') | ||
|
|
||
| @property | ||
| def name(self): | ||
| return self.job_data.get('name') | ||
|
|
||
| @property | ||
| def url(self): | ||
| return self.job_data.get('html_url') | ||
|
|
||
| def is_successful(self): | ||
| return self.conclusion == 'success' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
dev/archery/archery/templates/chat_nightly_workflow_report.txt.j2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| {# | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| #} | ||
| *Extra CI GitHub report for <{{ report.url }}|{{ report.name }}>* | ||
| {% if report.failed_jobs() %} | ||
| :x: *{{ report.failed_jobs() | length }} failed jobs* | ||
| {% for job in report.failed_jobs() -%} | ||
| - <{{ job.url }}|{{ job.name }}> | ||
| {% endfor %} | ||
| {%- endif -%} | ||
| {% if report.successful_jobs() %} | ||
|
|
||
| :tada: *{{ report.successful_jobs() | length }} successful jobs* | ||
| {%- endif -%} | ||
|
|
||
| {% if extra_message_success and not report.failed_jobs() %} | ||
|
|
||
| {{ extra_message_success }} | ||
| {%- endif -%} | ||
| {% if extra_message_failure and report.failed_jobs() %} | ||
|
|
||
| {{ extra_message_failure }} | ||
| {% endif %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: We can also use the default 465 (submissions, submission + SSL) port.