Skip to content

Commit

Permalink
use query string to filter workflows (#209)
Browse files Browse the repository at this point in the history
Signed-off-by: MregXN <[email protected]>
  • Loading branch information
MregXN authored Oct 24, 2023
1 parent 0f9923b commit e2e3a83
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions test-crawler/workflow_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def __init__(self, repo, workflow_name, access_token):
"Authorization": f"token {access_token}",
}
self.runs_len = 0
self.in_progress_num = 0
self.success_num = 0
self.failure_num = 0
self.failure_id = []
Expand All @@ -35,30 +34,25 @@ def __init__(self, repo, workflow_name, access_token):
self.components_tests_dict = {}

def scan_workflow(self):
url = f"https://api.github.com/repos/{self.repo}/actions/workflows/{self.workflow_name}/runs"
url = f"https://api.github.com/repos/{self.repo}/actions/workflows/{self.workflow_name}/runs?branch=master&event=schedule&status=completed"
response = requests.get(url, headers=self.headers, params=GITHUB_API_PARAMETER)
runs = json.loads(response.text)["workflow_runs"]

# ingore the workflows triggered manually
scheduled_runs = [r for r in runs if r["event"] == "schedule"]
self.runs_len = len(scheduled_runs)
print(f"Successfully get {self.runs_len} scheduled runs")

for run in scheduled_runs:
if run["status"] == "in_progress":
self.in_progress_num += 1
else:
if run["conclusion"] == "success":
self.success_num += 1
# get all components of each test in first success workflow
if self.success_num == 1:
self.get_components_tests_dict(run["id"])
elif run["conclusion"] == "failure":
self.failure_num += 1
self.failure_id.append(run["id"])
self.runs_len = len(runs)
print(f"Successfully get {self.runs_len} scheduled runs.")

for run in runs:
if run["conclusion"] == "success":
self.success_num += 1
# get all components of each test in first success workflow
if self.success_num == 1:
self.get_components_tests_dict(run["id"])
elif run["conclusion"] == "failure":
self.failure_num += 1
self.failure_id.append(run["id"])

print(
f"{self.in_progress_num} runs are still in progress, {self.success_num} runs success and {self.failure_num} runs fail"
f"{self.success_num} runs success and {self.failure_num} runs fail"
)

pass_rate_string = f"Pass rate of {self.workflow_name} is " + "{:.2%}\n".format(
Expand All @@ -67,7 +61,7 @@ def scan_workflow(self):

with open(TESTS_OUTPUT_TARGET, "w") as file:
file.write(f"Successfully get {self.runs_len} scheduled runs" + "\n")
file.write(f"{self.in_progress_num} runs are still in progress, {self.success_num} runs success and {self.failure_num} runs fail"+ "\n")
file.write(f"{self.success_num} runs success and {self.failure_num} runs fail"+ "\n")
file.write(pass_rate_string + "\n")
print(pass_rate_string)

Expand Down

0 comments on commit e2e3a83

Please sign in to comment.