From 7dfc62b1aec7f6677b45ab3299c5450f6914e1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 25 Aug 2024 14:57:44 -0500 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20Handle=20race=20condition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- latest_changes/main.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/latest_changes/main.py b/latest_changes/main.py index b94d647..a8a6169 100644 --- a/latest_changes/main.py +++ b/latest_changes/main.py @@ -191,6 +191,7 @@ def main() -> None: safe_directory_config_content = "[safe]\n\tdirectory = /github/workspace" dotgitconfig_path = Path.home() / ".gitconfig" dotgitconfig_path.write_text(safe_directory_config_content) + settings = Settings() if settings.input_debug_logs: logging.info(f"Using config: {settings.json()}") @@ -210,6 +211,7 @@ def main() -> None: f"No PR number was found (PR number or workflow input) in the event file at: {settings.github_event_path}" ) sys.exit(1) + pr = repo.get_pull(number) if not pr.merged: logging.info("The PR was not merged, nothing else to do.") @@ -219,6 +221,7 @@ def main() -> None: f"The latest changes files doesn't seem to exist: {settings.input_latest_changes_file}" ) sys.exit(1) + logging.info("Setting up GitHub Actions git user") subprocess.run(["git", "config", "user.name", "github-actions"], check=True) subprocess.run( @@ -242,9 +245,16 @@ def main() -> None: ) settings.input_latest_changes_file.write_text(new_content) logging.info(f"Committing changes to: {settings.input_latest_changes_file}") - subprocess.run(["git", "add", str(settings.input_latest_changes_file)], check=True) + subprocess.run( + ["git", "add", str(settings.input_latest_changes_file)], check=True + ) subprocess.run(["git", "commit", "-m", "📝 Update release notes"], check=True) logging.info(f"Pushing changes: {settings.input_latest_changes_file}") - subprocess.run(["git", "push"], check=True) - break + result = subprocess.run(["git", "push"]) + if result.returncode == 0: + break + # Didn't work, race condition, reset to try again + subprocess.run(["git", "reset", "HEAD^1"], check=True) + subprocess.run(["git", "checkout", "."], check=True) + logging.info("Finished") From 2e600eae4a6c79c538993b807dc0ae8e26329431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 25 Aug 2024 17:56:05 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8D=BB=20Push=20every=205=20min=20to?= =?UTF-8?q?=20force=20a=20race=20condition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- latest_changes/main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/latest_changes/main.py b/latest_changes/main.py index a8a6169..f9bfab2 100644 --- a/latest_changes/main.py +++ b/latest_changes/main.py @@ -2,6 +2,8 @@ import re import subprocess import sys +import time +from datetime import datetime, timezone from pathlib import Path from typing import List, Optional, Union @@ -250,10 +252,20 @@ def main() -> None: ) subprocess.run(["git", "commit", "-m", "📝 Update release notes"], check=True) logging.info(f"Pushing changes: {settings.input_latest_changes_file}") + + # TODO: fix this + now = datetime.now(timezone.utc) + extra_minutes = 5 - (now.minute % 5) + extra_seconds = 60 - now.second + wait_time = extra_seconds + (extra_minutes * 60) + logging.info(f"Waiting for {wait_time} seconds before pushing") + time.sleep(wait_time) + result = subprocess.run(["git", "push"]) if result.returncode == 0: break # Didn't work, race condition, reset to try again + logging.info("That didn't work, resetting before trying again") subprocess.run(["git", "reset", "HEAD^1"], check=True) subprocess.run(["git", "checkout", "."], check=True) From 983921d4937d726c8f7e1f03917585bbe68b0fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 25 Aug 2024 20:21:54 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A5=20Remove=20debugging=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- latest_changes/main.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/latest_changes/main.py b/latest_changes/main.py index f9bfab2..85a52e6 100644 --- a/latest_changes/main.py +++ b/latest_changes/main.py @@ -2,8 +2,6 @@ import re import subprocess import sys -import time -from datetime import datetime, timezone from pathlib import Path from typing import List, Optional, Union @@ -253,14 +251,6 @@ def main() -> None: subprocess.run(["git", "commit", "-m", "📝 Update release notes"], check=True) logging.info(f"Pushing changes: {settings.input_latest_changes_file}") - # TODO: fix this - now = datetime.now(timezone.utc) - extra_minutes = 5 - (now.minute % 5) - extra_seconds = 60 - now.second - wait_time = extra_seconds + (extra_minutes * 60) - logging.info(f"Waiting for {wait_time} seconds before pushing") - time.sleep(wait_time) - result = subprocess.run(["git", "push"]) if result.returncode == 0: break