Better notification service (#13267)
This commit is contained in:
1
.github/workflows/self-scheduled.yml
vendored
1
.github/workflows/self-scheduled.yml
vendored
@@ -355,6 +355,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
CI_SLACK_BOT_TOKEN: ${{ secrets.CI_SLACK_BOT_TOKEN }}
|
CI_SLACK_BOT_TOKEN: ${{ secrets.CI_SLACK_BOT_TOKEN }}
|
||||||
CI_SLACK_CHANNEL_ID: ${{ secrets.CI_SLACK_CHANNEL_ID }}
|
CI_SLACK_CHANNEL_ID: ${{ secrets.CI_SLACK_CHANNEL_ID }}
|
||||||
|
CI_SLACK_CHANNEL_ID_DAILY: ${{ secrets.CI_SLACK_CHANNEL_ID_DAILY }}
|
||||||
|
|
||||||
|
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ def handle_test_results(test_results):
|
|||||||
|
|
||||||
|
|
||||||
def format_for_slack(total_results, results, scheduled: bool):
|
def format_for_slack(total_results, results, scheduled: bool):
|
||||||
print(results)
|
print(total_results, results)
|
||||||
header = {
|
header = {
|
||||||
"type": "header",
|
"type": "header",
|
||||||
"text": {
|
"text": {
|
||||||
@@ -49,20 +49,21 @@ def format_for_slack(total_results, results, scheduled: bool):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
total = (
|
if total_results["failed"] > 0:
|
||||||
{
|
total = {
|
||||||
"type": "section",
|
"type": "section",
|
||||||
"fields": [
|
"fields": [
|
||||||
{"type": "mrkdwn", "text": f"*Failures:*\n❌ {total_results['failed']} failures."},
|
{"type": "mrkdwn", "text": f"*Failures:*\n❌ {total_results['failed']} failures."},
|
||||||
{"type": "mrkdwn", "text": f"*Passed:*\n✅ {total_results['success']} tests passed."},
|
{"type": "mrkdwn", "text": f"*Passed:*\n✅ {total_results['success']} tests passed."},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
if total_results["failed"] > 0
|
else:
|
||||||
else {
|
total = {
|
||||||
"type": "section",
|
"type": "section",
|
||||||
"fields": [{"type": "mrkdwn", "text": f"*Congrats!*\nAll {total_results['success']} tests pass."}],
|
"fields": [
|
||||||
|
{"type": "mrkdwn", "text": "\n🌞 All tests passed."},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
blocks = [header, total]
|
blocks = [header, total]
|
||||||
|
|
||||||
@@ -82,7 +83,7 @@ def format_for_slack(total_results, results, scheduled: bool):
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
elif not scheduled:
|
||||||
for key, result in results.items():
|
for key, result in results.items():
|
||||||
blocks.append(
|
blocks.append(
|
||||||
{"type": "section", "fields": [{"type": "mrkdwn", "text": f"*{key}*\n{result['time_spent']}."}]}
|
{"type": "section", "fields": [{"type": "mrkdwn", "text": f"*{key}*\n{result['time_spent']}."}]}
|
||||||
@@ -148,7 +149,7 @@ if __name__ == "__main__":
|
|||||||
}
|
}
|
||||||
|
|
||||||
client = WebClient(token=os.environ["CI_SLACK_BOT_TOKEN"])
|
client = WebClient(token=os.environ["CI_SLACK_BOT_TOKEN"])
|
||||||
channel_id = os.environ["CI_SLACK_CHANNEL_ID"]
|
channel_id = os.environ["CI_SLACK_CHANNEL_ID_DAILY"] if scheduled else os.environ["CI_SLACK_CHANNEL_ID"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
results = {}
|
results = {}
|
||||||
@@ -180,12 +181,13 @@ if __name__ == "__main__":
|
|||||||
for result_key in test_results_keys:
|
for result_key in test_results_keys:
|
||||||
total[result_key] += job_result[result_key]
|
total[result_key] += job_result[result_key]
|
||||||
|
|
||||||
to_be_sent_to_slack = format_for_slack(total, results, scheduled)
|
if total["failed"] != 0 or scheduled:
|
||||||
|
to_be_sent_to_slack = format_for_slack(total, results, scheduled)
|
||||||
|
|
||||||
result = client.chat_postMessage(
|
result = client.chat_postMessage(
|
||||||
channel=channel_id,
|
channel=channel_id,
|
||||||
blocks=to_be_sent_to_slack["blocks"],
|
blocks=to_be_sent_to_slack["blocks"],
|
||||||
)
|
)
|
||||||
|
|
||||||
for job, job_result in results.items():
|
for job, job_result in results.items():
|
||||||
if len(job_result["failures"]):
|
if len(job_result["failures"]):
|
||||||
|
|||||||
Reference in New Issue
Block a user