From ee8785889ca16fa4a5feadb3fd83a02ff2cd7ddf Mon Sep 17 00:00:00 2001 From: Nicholas Tindle Date: Tue, 20 Aug 2024 14:05:30 -0500 Subject: [PATCH] ci: dupe and move file in attempt to figure out why its not accessible --- .github/workflows/workflow-checker.yml | 2 +- autogpt/check_actions_status.py | 85 ++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 autogpt/check_actions_status.py diff --git a/.github/workflows/workflow-checker.yml b/.github/workflows/workflow-checker.yml index 2fd3edaff4d3..f158e0152781 100644 --- a/.github/workflows/workflow-checker.yml +++ b/.github/workflows/workflow-checker.yml @@ -46,6 +46,6 @@ jobs: echo "Current directory before running Python script:" pwd echo "Attempting to run Python script:" - python .github/scripts/check_actions_status.py + python check_actions_status.py env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/autogpt/check_actions_status.py b/autogpt/check_actions_status.py new file mode 100644 index 000000000000..b838e95054a8 --- /dev/null +++ b/autogpt/check_actions_status.py @@ -0,0 +1,85 @@ +import os +import requests +import sys +import time + + +# GitHub API endpoint +api_url = os.environ["GITHUB_API_URL"] +repo = os.environ["GITHUB_REPOSITORY"] +sha = os.environ["GITHUB_SHA"] + +# GitHub token for authentication +github_token = os.environ["GITHUB_TOKEN"] + +# API endpoint for check runs for the specific SHA +endpoint = f"{api_url}/repos/{repo}/commits/{sha}/check-runs" + +# Set up headers for authentication +headers = { + "Authorization": f"token {github_token}", + "Accept": "application/vnd.github.v3+json", +} + +# Make the API request +response = requests.get(endpoint, headers=headers) + +if response.status_code != 200: + print( + f"Error: Unable to fetch check runs data. Status code: {response.status_code}" + ) + sys.exit(1) + +check_runs = response.json()["check_runs"] + +# Flag to track if all other check runs have passed +all_others_passed = True + +# Current run id +current_run_id = os.environ["GITHUB_RUN_ID"] +# Initialize a flag to check if any runs are still in progress +runs_in_progress = True + +while runs_in_progress: + runs_in_progress = False + all_others_passed = True + + for run in check_runs: + if str(run["id"]) != current_run_id: + status = run["status"] + conclusion = run["conclusion"] + + if status == "completed": + if conclusion not in ["success", "skipped", "neutral"]: + all_others_passed = False + print( + f"Check run {run['name']} (ID: {run['id']}) has conclusion: {conclusion}" + ) + else: + runs_in_progress = True + print(f"Check run {run['name']} (ID: {run['id']}) is still {status}.") + all_others_passed = False + + if runs_in_progress: + print( + "Some check runs are still in progress. Waiting 5 seconds before checking again..." + ) + time.sleep(5) + + # Fetch updated check runs data + response = requests.get(endpoint, headers=headers) + if response.status_code != 200: + print( + f"Error: Unable to fetch updated check runs data. Status code: {response.status_code}" + ) + sys.exit(1) + check_runs = response.json()["check_runs"] + +# After the loop, all_others_passed will have the final result + +if all_others_passed: + print("All other completed check runs have passed. This check passes.") + sys.exit(0) +else: + print("Some check runs have failed or have not completed. This check fails.") + sys.exit(1)