Skip to content

Commit

Permalink
Update summarize_fail.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kliao-csa authored Aug 23, 2023
1 parent 02c4bfe commit fd4892e
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions scripts/tools/summarize_fail.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import logging
import os
import pandas as pd
import subprocess

subprocess.run("gh run list -R project-chip/connectedhomeip -b master -s failure --json databaseId,displayTitle,workflowName > run_list.json", shell=True)
df = pd.read_json("run_list.json")
df.columns = ["ID", "Pull Request", "Workflow"]
print("Recent Failures:")
print(df.to_string(index=False))
df.to_csv("recent_fails.csv", index=False)
print()
print("Percentage Frequency:")
frequency = df["Workflow"].value_counts(normalize=True).mul(100).astype(str).reset_index(name="Percentage")
print(frequency.to_string(index=False))
frequency.to_csv("recent_fails_frequency.csv")
print()
for failId in df["ID"].tolist():
os.makedirs(f"fail_logs/{failId}") # Resolve this to actual run name later
subprocess.run(f"gh run view -R project-chip/connectedhomeip {failId} --log-failed > fail_logs/{failId}/raw_output.txt", shell=True)
def process_fail(id, pr, workflow):
os.makedirs(f"logs/{pr}/{workflow}")
subprocess.run(f"gh run view -R project-chip/connectedhomeip {id} --log-failed > logs/{pr}/{workflow}/fail_logs.txt", shell=True)

def main():
logging.info("Gathering recent run failure information into run_list.json.")
subprocess.run("gh run list -R project-chip/connectedhomeip -b master -s failure --json databaseId,displayTitle,workflowName > run_list.json", shell=True)
df = pd.read_json("run_list.json")
df.columns = ["ID", "Pull Request", "Workflow"]
logging.info("Recent Failures:")
logging.info(df.to_string(index=False))
df.to_csv("recent_fails.csv", index=False)
logging.info("Percentage Frequency of Workflow Failures:")
frequency = df["Workflow"].value_counts(normalize=True).mul(100).astype(str).reset_index(name="Percentage")
logging.info(frequency.to_string(index=False))
frequency.to_csv("recent_workflow_fails_frequency.csv")
df.apply(lambda row: process_fail(row["ID"], row["Pull Request"], row["Workflow"]), axis=1)

if __name__ == "__main__":
main()

0 comments on commit fd4892e

Please sign in to comment.