-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
Aggeregate test summary files in CircleCI workflow runs #34989
Changes from 79 commits
729f61f
573455d
d788ffa
337956e
8367992
97efbd0
17ac09a
e95bc11
c24625f
b8f2f76
01037c6
f29dc9b
6086f9d
6bf6dca
95dac99
6f41cd8
4329c26
31ff1a1
1a1a10d
16b7459
9833fac
48234c7
f0d2bba
ad3b42c
a012473
00d5976
aa65c71
49e9e3f
1841f56
67935a6
0ea4bb1
3fc2af7
9d143f5
3e2ff0c
55aa01c
b3d8212
75da5b8
428b937
a355972
6f94ad8
339e0f3
931bd56
ea08752
a89920b
1bf1088
dab6281
5a9978a
84cb015
ef53bf4
fbc3390
2ac2158
f0b3c5d
cc6600a
12852e4
eb0125d
3be7105
c9ef06e
64bf5e0
c93e34c
d471968
eda984c
90f3a0a
553e163
af2ddf2
a1f7c63
f285200
9d45dbc
6ea3002
977d27e
4a1d93a
74be7c0
f7ab430
9200176
358f86c
dd7fee4
99c89d6
3818ab0
ce760fa
a4586f0
fa07279
3ce5700
d14de3d
aa16edc
b9d4bfb
c174645
ef7f6a8
0e6d198
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright 2024 The HuggingFace Team. All rights reserved. | ||
# | ||
# Licensed 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 argparse | ||
import json | ||
import os | ||
import requests | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--workflow_id', type=str, required=True) | ||
args = parser.parse_args() | ||
workflow_id = args.workflow_id | ||
|
||
r = requests.get(f"https://circleci.com/api/v2/workflow/{workflow_id}/job", headers={"Circle-Token": os.environ.get('CIRCLE_TOKEN', "")}) | ||
jobs = r.json()["items"] | ||
|
||
os.makedirs("outputs", exist_ok=True) | ||
|
||
workflow_summary = {} | ||
# for each job, download artifacts | ||
for job in jobs: | ||
|
||
project_slug = job["project_slug"] | ||
if job["name"].startswith(("tests_", "examples_", "pipelines_")): | ||
|
||
url = f'https://circleci.com/api/v2/project/{project_slug}/{job["job_number"]}/artifacts' | ||
r = requests.get(url, headers={"Circle-Token": os.environ.get('CIRCLE_TOKEN', "")}) | ||
job_artifacts = r.json()["items"] | ||
|
||
os.makedirs(job["name"], exist_ok=True) | ||
os.makedirs(f'outputs/{job["name"]}', exist_ok=True) | ||
|
||
job_test_summaries = {} | ||
for artifact in job_artifacts: | ||
if artifact["path"].startswith("reports/") and artifact["path"].endswith("/summary_short.txt"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using the junit.xlm will be more "foolproof" than regex parsing no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no regex in this script. Regarding
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok sounds good! |
||
node_index = artifact["node_index"] | ||
url = artifact["url"] | ||
r = requests.get(url, headers={"Circle-Token": os.environ.get('CIRCLE_TOKEN', "")}) | ||
test_summary = r.text | ||
job_test_summaries[node_index] = test_summary | ||
|
||
summary = {} | ||
for node_index, node_test_summary in job_test_summaries.items(): | ||
for line in node_test_summary.splitlines(): | ||
if line.startswith("PASSED "): | ||
test = line[len("PASSED "):] | ||
summary[test] = "passed" | ||
elif line.startswith("FAILED "): | ||
test = line[len("FAILED "):].split()[0] | ||
summary[test] = "failed" | ||
# failed before passed | ||
summary = {k: v for k, v in sorted(summary.items(), key=lambda x: (x[1], x[0]))} | ||
workflow_summary[job["name"]] = summary | ||
|
||
# collected version | ||
with open(f'outputs/{job["name"]}/test_summary.json', "w") as fp: | ||
json.dump(summary, fp, indent=4) | ||
|
||
new_workflow_summary = {} | ||
for job_name, job_summary in workflow_summary.items(): | ||
for test, status in job_summary.items(): | ||
if test not in new_workflow_summary: | ||
new_workflow_summary[test] = {} | ||
new_workflow_summary[test][job_name] = status | ||
|
||
for test, result in new_workflow_summary.items(): | ||
new_workflow_summary[test] = {k: v for k, v in sorted(result.items())} | ||
new_workflow_summary = {k: v for k, v in sorted(new_workflow_summary.items())} | ||
|
||
with open(f'outputs/test_summary.json', "w") as fp: | ||
json.dump(new_workflow_summary, fp, indent=4) |
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.
In circle-ci can't we just use something like
with
or require? It will automatically wait for therun_test
to run, and then fetch results?(It could even be a github action no?)
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.
Job 2
require
Job 1: if job 1 failed, job 2 won't be triggered (sad 😢 ).when: always
can't apply for jobs in a workflow (only steps in a job) for CircleCI.That is why such wait is implemented (although I don't like it).
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.
OK then you can merge but I would like for this test to not block merge
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.
You mean if this new job fails, it shouldn't block the merge?
I will see if I can configure this 🤔
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.
I am just doing
d14de3d
to make sure the
run
steps will always success.