diff --git a/.github/workflows/self-scheduled.yml b/.github/workflows/self-scheduled.yml index bd5aee0ae9..a1ad79b430 100644 --- a/.github/workflows/self-scheduled.yml +++ b/.github/workflows/self-scheduled.yml @@ -355,6 +355,7 @@ jobs: env: CI_SLACK_BOT_TOKEN: ${{ secrets.CI_SLACK_BOT_TOKEN }} CI_SLACK_CHANNEL_ID: ${{ secrets.CI_SLACK_CHANNEL_ID }} + CI_SLACK_CHANNEL_ID_DAILY: ${{ secrets.CI_SLACK_CHANNEL_ID_DAILY }} run: | diff --git a/utils/notification_service.py b/utils/notification_service.py index 94d7b1f230..735b06c0d1 100644 --- a/utils/notification_service.py +++ b/utils/notification_service.py @@ -39,7 +39,7 @@ def handle_test_results(test_results): def format_for_slack(total_results, results, scheduled: bool): - print(results) + print(total_results, results) header = { "type": "header", "text": { @@ -49,20 +49,21 @@ def format_for_slack(total_results, results, scheduled: bool): }, } - total = ( - { + if total_results["failed"] > 0: + total = { "type": "section", "fields": [ {"type": "mrkdwn", "text": f"*Failures:*\nāŒ {total_results['failed']} failures."}, {"type": "mrkdwn", "text": f"*Passed:*\nāœ… {total_results['success']} tests passed."}, ], } - if total_results["failed"] > 0 - else { + else: + total = { "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] @@ -82,7 +83,7 @@ def format_for_slack(total_results, results, scheduled: bool): ], } ) - else: + elif not scheduled: for key, result in results.items(): blocks.append( {"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"]) - 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: results = {} @@ -180,12 +181,13 @@ if __name__ == "__main__": for result_key in test_results_keys: 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( - channel=channel_id, - blocks=to_be_sent_to_slack["blocks"], - ) + result = client.chat_postMessage( + channel=channel_id, + blocks=to_be_sent_to_slack["blocks"], + ) for job, job_result in results.items(): if len(job_result["failures"]):