Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry set_ref up to 5 times #195

Merged
merged 2 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions homu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ def synchronize(repo_label, repo_cfg, logger, gh, states, repos, db, mergeable_q

def process_config(config):
# Replace environment variables
if type(config) == str:
if type(config) is str:
for var in VARIABLES_RE.findall(config):
try:
config = config.replace("${"+var+"}", os.environ[var])
Expand All @@ -1680,9 +1680,9 @@ def process_config(config):

return config
# Recursively apply the processing
elif type(config) == list:
elif type(config) is list:
return [process_config(item) for item in config]
elif type(config) == dict:
elif type(config) is dict:
return {key: process_config(value) for key, value in config.items()}
# All other values should be returned as-is
else:
Expand Down
35 changes: 28 additions & 7 deletions homu/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from retrying import retry
import random
import string
import time

import bottle
bottle.BaseRequest.MEMFILE_MAX = 1024 * 1024 * 10
Expand Down Expand Up @@ -690,6 +691,13 @@ def report_build_res(succ, url, builder, state, logger, repo_cfg):
)

if state.approved_by and not state.try_:
# The set_ref call below sometimes fails with 422 failed to
# fast forward. We believe this is a spurious error on GitHub's
# side, though it's not entirely clear why. We sleep for 1
# minute before trying it after setting the status to try to
# increase the likelihood it will work, and also retry the
# set_ref a few times.
time.sleep(60)
state.add_comment(comments.BuildCompleted(
approved_by=state.approved_by,
base_ref=state.base_ref,
Expand All @@ -698,31 +706,44 @@ def report_build_res(succ, url, builder, state, logger, repo_cfg):
))
state.change_labels(LabelEvent.SUCCEED)

def set_ref():
def set_ref_inner():
utils.github_set_ref(state.get_repo(), 'heads/' +
state.base_ref, state.merge_sha)
if state.test_on_fork is not None:
utils.github_set_ref(state.get_test_on_fork_repo(),
'heads/' + state.base_ref,
state.merge_sha, force=True)
try:

def set_ref():
try:
set_ref()
set_ref_inner()
except github3.models.GitHubError:
utils.github_create_status(
state.get_repo(),
state.merge_sha,
'success', '',
'Branch protection bypassed',
context='homu')
set_ref()
set_ref_inner()

state.fake_merge(repo_cfg)
error = None
for i in range(0, 5):
try:
set_ref()
state.fake_merge(repo_cfg)
Mark-Simulacrum marked this conversation as resolved.
Show resolved Hide resolved
error = None
except github3.models.GitHubError as e:
error = e
pass
if error is None:
break
else:
time.sleep(10)

except github3.models.GitHubError as e:
if error is not None:
state.set_status('error')
desc = ('Test was successful, but fast-forwarding failed:'
' {}'.format(e))
' {}'.format(error))
utils.github_create_status(state.get_repo(),
state.head_sha, 'error', url,
desc, context='homu')
Expand Down
Loading