Skip to content

Commit 7cfc3da

Browse files
committed
[cpp] Fix all-jobs-are-green-job
1 parent 0045cf6 commit 7cfc3da

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ jobs:
166166
with:
167167
python-version: '3.11'
168168
- run: pip install requests
169-
- run: python utils/scripts/get-workflow-summary.py ${{ github.run_id }} >> $GITHUB_STEP_SUMMARY
169+
- run: python utils/scripts/get-workflow-summary.py DataDog/system-tests ${{ github.run_id }} -o $GITHUB_STEP_SUMMARY
170170
env:
171171
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
172172

Diff for: utils/scripts/get-workflow-summary.py

+43-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import argparse
12
from collections import defaultdict
3+
import logging
24
import os
35
import sys
46

@@ -34,11 +36,14 @@ def get_jobs(session, repo_slug: str, run_id: int) -> list:
3436
return jobs
3537

3638

37-
def main(repo_slug: str, run_id: int) -> None:
39+
def main(repo_slug: str, run_id: int, output: str) -> None:
40+
logging.info(f"Getting workflow summary for https://github.com/{repo_slug}/actions/runs/{run_id}")
3841
environ = get_environ()
3942

4043
has_failure = False
4144

45+
result: list[str] = []
46+
4247
with requests.Session() as session:
4348
if "GH_TOKEN" in environ:
4449
session.headers["Authorization"] = environ["GH_TOKEN"]
@@ -49,9 +54,11 @@ def main(repo_slug: str, run_id: int) -> None:
4954

5055
for job in jobs:
5156
if job["name"] in ("all-jobs-are-green", "fancy-report"):
57+
logging.info(f"Skipping job {job['name']}")
5258
continue
5359

5460
if job["conclusion"] not in ["skipped", "success"]:
61+
logging.info(f"Job {job['name']} conclusion: {job['conclusion']}")
5562
has_failure = True
5663

5764
if job["conclusion"] != "failure":
@@ -62,16 +69,48 @@ def main(repo_slug: str, run_id: int) -> None:
6269
failing_steps[step["name"]].append((job, step))
6370

6471
for step_name, items in failing_steps.items():
65-
print(f"❌ **Failures for `{step_name}`**\n")
72+
result.append(f"❌ **Failures for `{step_name}`**\n")
6673
for job, step in sorted(items, key=lambda x: x[0]["name"]):
6774
url = job["html_url"]
68-
print(f"* [{job['name']}]({url}#step:{step['number']})")
75+
result.append(f"* [{job['name']}]({url}#step:{step['number']})")
76+
77+
result.append("")
6978

79+
if output:
80+
logging.info(f"Writing output to {output}")
81+
with open(output, "w") as f:
82+
f.write("\n".join(result))
83+
else:
84+
logging.info("Writing output to stdout")
85+
print("\n".join(result))
7086
print()
7187

7288
if has_failure:
7389
sys.exit(1)
7490

7591

7692
if __name__ == "__main__":
77-
main("DataDog/system-tests", int(sys.argv[1]))
93+
parser = argparse.ArgumentParser(
94+
prog="get-workflow-summary", description="List all failing step of a github workflow, and pretty print them"
95+
)
96+
97+
parser.add_argument("repo_slug", type=str, help="Repo slug of the workflow")
98+
99+
parser.add_argument("run_id", type=int, help="Run Id of the workflow")
100+
101+
parser.add_argument(
102+
"--output",
103+
"-o",
104+
type=str,
105+
default="",
106+
help="Output file. If not provided, output to stdout",
107+
)
108+
args = parser.parse_args()
109+
110+
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s", stream=sys.stderr)
111+
112+
main(
113+
repo_slug=args.repo_slug,
114+
run_id=args.run_id,
115+
output=args.output,
116+
)

0 commit comments

Comments
 (0)