Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions release.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ def print_output(output):
for line in output.split('\n'):
print(">", line)

def cmd(action, cmd, *args, **kwargs):
if isinstance(cmd, basestring) and not kwargs.get("shell", False):
cmd = cmd.split()
def cmd(action, cmd_arg, *args, **kwargs):
if isinstance(cmd_arg, basestring) and not kwargs.get("shell", False):
cmd_arg = cmd_arg.split()

allow_failure = kwargs.pop("allow_failure", False)
num_retries = kwargs.pop("num_retries", 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kinds of failures are we trying to mask here? Frequently retries also require delays between retries.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a sleep in the new PR


stdin_log = ""
if "stdin" in kwargs and isinstance(kwargs["stdin"], basestring):
Expand All @@ -109,16 +111,23 @@ def cmd(action, cmd, *args, **kwargs):
stdin.seek(0)
kwargs["stdin"] = stdin

print(action, cmd, stdin_log)
print(action, cmd_arg, stdin_log)
try:
output = subprocess.check_output(cmd, *args, stderr=subprocess.STDOUT, **kwargs)
output = subprocess.check_output(cmd_arg, *args, stderr=subprocess.STDOUT, **kwargs)
print_output(output)
except subprocess.CalledProcessError as e:
print_output(e.output)

if num_retries > 0:
kwargs['num_retries'] = num_retries - 1
kwargs['allow_failure'] = allow_failure
print("Retrying... %d remaining retries" % (num_retries - 1))
return cmd(action, cmd_arg, *args, **kwargs)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably fine currently given max number of retries we specify, but would really be preferable to do this iteratively (which also doesn't require copying/mgmt of kwargs like this).


if allow_failure:
return


print("*************************************************")
print("*** First command failure occurred here. ***")
print("*** Will now try to clean up working state. ***")
Expand Down Expand Up @@ -153,7 +162,7 @@ def regexReplace(path, pattern, replacement):

def user_ok(msg):
ok = raw_input(msg)
return ok.lower() == 'y'
return ok.strip().lower() == 'y'

def sftp_mkdir(dir):
basedir, dirname = os.path.split(dir)
Expand Down Expand Up @@ -628,7 +637,7 @@ def select_gpg_key():
sftp_cmds = """
put %s %s
""" % (local_path, remote_path)
cmd("Uploading artifacts in %s to your Apache home directory" % root, "sftp -b - %s@home.apache.org" % apache_id, stdin=sftp_cmds)
cmd("Uploading artifacts in %s to your Apache home directory" % root, "sftp -b - %s@home.apache.org" % apache_id, stdin=sftp_cmds, num_retries=3)

with open(os.path.expanduser("~/.gradle/gradle.properties")) as f:
contents = f.read()
Expand Down