Skip to content

Commit 46ab56a

Browse files
authored
add: support for notifying maintainers about the nightly test status (huggingface#7117)
* add: support for notifying maintainers about the nightly test status * add: a tempoerary workflow for validation. * cancel in progress. * runs-on * clean up * add: peft dep * change device. * multiple edits. * remove temp workflow.
1 parent 038ff70 commit 46ab56a

File tree

2 files changed

+159
-2
lines changed

2 files changed

+159
-2
lines changed

.github/workflows/nightly_tests.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
PYTEST_TIMEOUT: 600
1313
RUN_SLOW: yes
1414
RUN_NIGHTLY: yes
15+
SLACK_API_TOKEN: ${{ secrets.SLACK_CIFEEDBACK_BOT_TOKEN }}
1516

1617
jobs:
1718
run_nightly_tests:
@@ -78,7 +79,8 @@ jobs:
7879
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
7980
-s -v -k "not Flax and not Onnx" \
8081
--make-reports=tests_${{ matrix.config.report }} \
81-
tests/
82+
--report-log=${{ matrix.config.report }}.log \
83+
tests/
8284
8385
- name: Run nightly Flax TPU tests
8486
if: ${{ matrix.config.framework == 'flax' }}
@@ -89,6 +91,7 @@ jobs:
8991
python -m pytest -n 0 \
9092
-s -v -k "Flax" \
9193
--make-reports=tests_${{ matrix.config.report }} \
94+
--report-log=${{ matrix.config.report }}.log \
9295
tests/
9396
9497
- name: Run nightly ONNXRuntime CUDA tests
@@ -100,6 +103,7 @@ jobs:
100103
python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
101104
-s -v -k "Onnx" \
102105
--make-reports=tests_${{ matrix.config.report }} \
106+
--report-log=${{ matrix.config.report }}.log \
103107
tests/
104108
105109
- name: Failure short reports
@@ -112,6 +116,12 @@ jobs:
112116
with:
113117
name: ${{ matrix.config.report }}_test_reports
114118
path: reports
119+
120+
- name: Generate Report and Notify Channel
121+
if: always()
122+
run: |
123+
pip install slack_sdk tabulate
124+
python scripts/log_reports.py >> $GITHUB_STEP_SUMMARY
115125
116126
run_nightly_tests_apple_m1:
117127
name: Nightly PyTorch MPS tests on MacOS
@@ -152,7 +162,9 @@ jobs:
152162
HF_HOME: /System/Volumes/Data/mnt/cache
153163
HUGGING_FACE_HUB_TOKEN: ${{ secrets.HUGGING_FACE_HUB_TOKEN }}
154164
run: |
155-
${CONDA_RUN} python -m pytest -n 1 -s -v --make-reports=tests_torch_mps tests/
165+
${CONDA_RUN} python -m pytest -n 1 -s -v --make-reports=tests_torch_mps \
166+
--report-log=tests_torch_mps.log \
167+
tests/
156168
157169
- name: Failure short reports
158170
if: ${{ failure() }}
@@ -164,3 +176,9 @@ jobs:
164176
with:
165177
name: torch_mps_test_reports
166178
path: reports
179+
180+
- name: Generate Report and Notify Channel
181+
if: always()
182+
run: |
183+
pip install slack_sdk tabulate
184+
python scripts/log_reports.py >> $GITHUB_STEP_SUMMARY

scripts/log_reports.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import argparse
2+
import json
3+
import os
4+
from datetime import date
5+
from pathlib import Path
6+
7+
from slack_sdk import WebClient
8+
from tabulate import tabulate
9+
10+
11+
MAX_LEN_MESSAGE = 2900 # slack endpoint has a limit of 3001 characters
12+
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument("--slack_channel_name", default="diffusers-ci-nightly")
15+
16+
17+
def main(slack_channel_name=None):
18+
failed = []
19+
passed = []
20+
21+
group_info = []
22+
23+
total_num_failed = 0
24+
empty_file = False or len(list(Path().glob("*.log"))) == 0
25+
26+
total_empty_files = []
27+
28+
for log in Path().glob("*.log"):
29+
section_num_failed = 0
30+
i = 0
31+
with open(log) as f:
32+
for line in f:
33+
line = json.loads(line)
34+
i += 1
35+
if line.get("nodeid", "") != "":
36+
test = line["nodeid"]
37+
if line.get("duration", None) is not None:
38+
duration = f'{line["duration"]:.4f}'
39+
if line.get("outcome", "") == "failed":
40+
section_num_failed += 1
41+
failed.append([test, duration, log.name.split("_")[0]])
42+
total_num_failed += 1
43+
else:
44+
passed.append([test, duration, log.name.split("_")[0]])
45+
empty_file = i == 0
46+
group_info.append([str(log), section_num_failed, failed])
47+
total_empty_files.append(empty_file)
48+
os.remove(log)
49+
failed = []
50+
text = (
51+
"🌞 There were no failures!"
52+
if not any(total_empty_files)
53+
else "Something went wrong there is at least one empty file - please check GH action results."
54+
)
55+
no_error_payload = {
56+
"type": "section",
57+
"text": {
58+
"type": "plain_text",
59+
"text": text,
60+
"emoji": True,
61+
},
62+
}
63+
64+
message = ""
65+
payload = [
66+
{
67+
"type": "header",
68+
"text": {
69+
"type": "plain_text",
70+
"text": "🤗 Results of the Diffusers scheduled nightly tests.",
71+
},
72+
},
73+
]
74+
if total_num_failed > 0:
75+
for i, (name, num_failed, failed_tests) in enumerate(group_info):
76+
if num_failed > 0:
77+
if num_failed == 1:
78+
message += f"*{name}: {num_failed} failed test*\n"
79+
else:
80+
message += f"*{name}: {num_failed} failed tests*\n"
81+
failed_table = []
82+
for test in failed_tests:
83+
failed_table.append(test[0].split("::"))
84+
failed_table = tabulate(
85+
failed_table,
86+
headers=["Test Location", "Test Case", "Test Name"],
87+
showindex="always",
88+
tablefmt="grid",
89+
maxcolwidths=[12, 12, 12],
90+
)
91+
message += "\n```\n" + failed_table + "\n```"
92+
93+
if total_empty_files[i]:
94+
message += f"\n*{name}: Warning! Empty file - please check the GitHub action job *\n"
95+
print(f"### {message}")
96+
else:
97+
payload.append(no_error_payload)
98+
99+
if len(message) > MAX_LEN_MESSAGE:
100+
print(f"Truncating long message from {len(message)} to {MAX_LEN_MESSAGE}")
101+
message = message[:MAX_LEN_MESSAGE] + "..."
102+
103+
if len(message) != 0:
104+
md_report = {
105+
"type": "section",
106+
"text": {"type": "mrkdwn", "text": message},
107+
}
108+
payload.append(md_report)
109+
action_button = {
110+
"type": "section",
111+
"text": {"type": "mrkdwn", "text": "*For more details:*"},
112+
"accessory": {
113+
"type": "button",
114+
"text": {"type": "plain_text", "text": "Check Action results", "emoji": True},
115+
"url": f"https://github.com/huggingface/diffusers/actions/runs/{os.environ['GITHUB_RUN_ID']}",
116+
},
117+
}
118+
payload.append(action_button)
119+
120+
date_report = {
121+
"type": "context",
122+
"elements": [
123+
{
124+
"type": "plain_text",
125+
"text": f"Nightly test results for {date.today()}",
126+
},
127+
],
128+
}
129+
payload.append(date_report)
130+
131+
print(payload)
132+
133+
client = WebClient(token=os.environ.get("SLACK_API_TOKEN"))
134+
client.chat_postMessage(channel=f"#{slack_channel_name}", text=message, blocks=payload)
135+
136+
137+
if __name__ == "__main__":
138+
args = parser.parse_args()
139+
main(args.slack_channel_name)

0 commit comments

Comments
 (0)