Skip to content

Commit

Permalink
Merge pull request #430 from zestsoftware/reinout-retry-push
Browse files Browse the repository at this point in the history
Allow for 'git push' retry + a bit of documentation, fixes #385
  • Loading branch information
mauritsvanrees authored Jul 25, 2023
2 parents deab40f + dabaf6c commit e5e5e05
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Changelog for zest.releaser

- Updated contributors list.

- Allowing for retry for ``git push``, which might fail because of a protected
branch. Also displaying that possible cause when it occurs. Fixes `issue 385
<https://github.com/zestsoftware/zest.releaser/issues/385>`_.


9.0.0a2 (2023-07-19)
--------------------
Expand Down
6 changes: 5 additions & 1 deletion zest/releaser/baserelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ def _push(self):
default_anwer = self.zest_releaser_config.push_changes()
if utils.ask("OK to push commits to the server?", default=default_anwer):
for push_cmd in push_cmds:
output = execute_command(push_cmd)
output = execute_command(
push_cmd,
allow_retry=True,
fail_message="Perhaps the main branch is protected?",
)
logger.info(output)

def _run_hooks(self, when):
Expand Down
12 changes: 10 additions & 2 deletions zest/releaser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ def execute_command(
result = _execute_command(command, cwd=cwd, extra_environ=extra_environ)
if not allow_retry:
return result
if AUTO_RESPONSE:
# Also don't ask for retry, just return the result.
return result
if Fore.RED not in result:
show_interesting_lines(result)
return result
Expand Down Expand Up @@ -770,15 +773,20 @@ def execute_commands(commands, allow_retry=False, fail_message=""):


def retry_yes_no(command):
"""Ask the user to maybe retry a command."""
"""Ask the user to maybe retry a command.
This is used for the twine upload command and for the final 'git push'.
"""
explanation = """
You have these options for retrying (first character is enough):
Yes: Retry. Do this if it looks like a temporary Internet or PyPI outage.
You can also first edit $HOME/.pypirc and then retry in
case of a credentials problem.
No: Do not retry, but continue with the rest of the process.
Quit: Stop completely. Note that the postrelease step has not
been run yet, you need to do that manually.
finished fully. You need to do the 'git push' and possibly the upload
manually.
?: Show this help."""
explanation = textwrap.dedent(explanation)
question = "Retry this command? [Yes/no/quit/?]"
Expand Down

0 comments on commit e5e5e05

Please sign in to comment.