-
Notifications
You must be signed in to change notification settings - Fork 30
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
Check if test_branch exists in at least one repo among the ones in repos file #624
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -654,6 +654,11 @@ def run(args, build_function, blacklisted_package_names=None): | |
info('Attempting to create a well known branch name for all the default branches') | ||
job.run(vcs_cmd + ['custom', '.', '--git', '--args', 'checkout', '-b', '__ci_default']) | ||
|
||
# Check if the branch exists in at least one repo from the given repos file | ||
for filename in repos_filenames: | ||
branch_found = check_branch_exists(filename, args.test_branch) | ||
if not branch_found: | ||
print('Warning: None of the repos in ', filename, ' contain the branch ', args.test_branch) | ||
# Attempt to switch all the repositories to a given branch | ||
info("Attempting to switch all repositories to the '{0}' branch" | ||
.format(args.test_branch)) | ||
|
@@ -777,5 +782,24 @@ def _fetch_repos_file(url, filename, job): | |
with open(filename, 'r') as f: | ||
print(f.read()) | ||
|
||
# Checks if the given branch exists in at least one repo | ||
def check_branch_exists(filename, branch): | ||
# Populate all .git repos | ||
lines = [] | ||
with open(filename) as f: lines = f.readlines() | ||
|
||
urls = [] | ||
for line in lines: | ||
text = line.strip() | ||
if text[-4:] == ".git": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be nice if there is a vcs command we could use instead. I think checking for a ".git" suffix might be too brittle since I don't think it's a requirement that it's there. Also, since the repositories are already cloned locally, it seems a bit redundant to re-parse the repos files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right, this is too brittle. The Actually, I wonder if it would be better to just parse these |
||
urls.append(text.replace("url: ", "")) | ||
|
||
for repo in urls : | ||
# Check if 'branch' exists in 'repo' | ||
ret = os.system("git ls-remote --exit-code --heads " + repo + " " + branch) | ||
if not ret : return True | ||
|
||
return False | ||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How visible is this warning? Does it make the job yellow or do we have to notice it in the log?
IMO, it might be better to just abort the job early since it seems most likely not what the user intended and continuing with the build is probably not worth the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed; if the user specified a branch, but we couldn't find any of them, let's just abort the build early. It's probably not what was intended. We also have to be careful to succeed if the branch name is empty; that is the "normal" state of affairs, in which case we just want to continue on.