Skip to content

Commit

Permalink
🐛 Fix race condition with retries, when more than one latest-changes …
Browse files Browse the repository at this point in the history
…is running (#69)
  • Loading branch information
tiangolo authored Aug 26, 2024
1 parent 6d8b6f1 commit 54e8124
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions latest_changes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}")
Expand All @@ -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.")
Expand All @@ -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(
Expand All @@ -242,9 +245,18 @@ 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
logging.info("That didn't work, resetting before trying again")
subprocess.run(["git", "reset", "HEAD^1"], check=True)
subprocess.run(["git", "checkout", "."], check=True)

logging.info("Finished")

0 comments on commit 54e8124

Please sign in to comment.