From 7ff677f57f3d8f2c191569fb3041e9782bfca796 Mon Sep 17 00:00:00 2001 From: Agnieszka Besz Date: Fri, 31 Jan 2025 16:12:46 +0000 Subject: [PATCH] chore: add global timeout for builds --- .github/workflows/build-unitycloud.yml | 3 ++- scripts/cloudbuild/build.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-unitycloud.yml b/.github/workflows/build-unitycloud.yml index 3822e92a87..d4e31fd5bc 100644 --- a/.github/workflows/build-unitycloud.yml +++ b/.github/workflows/build-unitycloud.yml @@ -237,7 +237,8 @@ jobs: API_KEY: ${{ secrets.UNITY_CLOUD_API_KEY }} ORG_ID: ${{ secrets.UNITY_CLOUD_ORG_ID }} PROJECT_ID: ${{ secrets.UNITY_CLOUD_PROJECT_ID }} - POLL_TIME: 60 # In seconds (int) + POLL_TIME: 60 # Set the polling time in seconds + GLOBAL_TIMEOUT: 10800 # Set the global timeout in seconds (e.g., 3 hours) TARGET: t_${{ matrix.target }} BRANCH_NAME: ${{ github.head_ref || github.ref_name }} COMMIT_SHA: ${{ needs.prebuild.outputs.commit_sha }} diff --git a/scripts/cloudbuild/build.py b/scripts/cloudbuild/build.py index a6fab6bd2e..d3595f9e8f 100644 --- a/scripts/cloudbuild/build.py +++ b/scripts/cloudbuild/build.py @@ -34,6 +34,7 @@ def _extract_member(self, member, targetpath, pwd): URL = utils.create_base_url(os.getenv('ORG_ID'), os.getenv('PROJECT_ID')) HEADERS = utils.create_headers(os.getenv('API_KEY')) POLL_TIME = int(os.getenv('POLL_TIME', '60')) # Seconds +GLOBAL_TIMEOUT = int(os.getenv('GLOBAL_TIMEOUT', '10800')) # Seconds build_healthy = True @@ -538,11 +539,17 @@ def get_clean_build_bool(): # Poll the build stats every {POLL_TIME}s start_time = time.time() while True: + elapsed_time = time.time() - start_time + if elapsed_time > GLOBAL_TIMEOUT: + print(f'Global timeout reached: {datetime.timedelta(seconds=elapsed_time)}. Cancelling build...') + cancel_build(id) + sys.exit(1) + if poll_build(id): - print(f'Runner elapsed time: {datetime.timedelta(seconds=(time.time() - start_time))} | Polling again in {POLL_TIME}s [...]') + print(f'Runner elapsed time: {datetime.timedelta(seconds=elapsed_time)} | Polling again in {POLL_TIME}s [...]') time.sleep(POLL_TIME) else: - print(f'Runner FINAL elapsed time: {datetime.timedelta(seconds=(time.time() - start_time))}') + print(f'Runner FINAL elapsed time: {datetime.timedelta(seconds=elapsed_time)}') break # Handle build artifact