Skip to content

Commit 99d5ee5

Browse files
rzrydirson
andcommitted
koji: Add supported git branches (eg: {8.3, master} for v8.3-* tags)
make `koji_build` accept builds for v8.3 and from both `master` and `8.3` Preparation for switch `master` to be "next" aka v9 The motivation of change is part of a bigger plan, to prepare a smooth transition to enable bleeding edge development on master branch. Of course maintenance will remain in v8.x branches. Once the master branch needs to be stabilized then a new 9.0 branch can be open (this mean declared in PROTECTED_TARGETS, and also move the `master` branch from `8.3` target to `9.0` for a future cycle) Note that `8.3` git branches are not created yet in repos, it would make sense to open them soon or later, ideally when master branches need to receive feature from next release. Coincidentaly thoses 8.3 branches will be used for maintenance of the LTS release and then developers/RE might consider back-porting fixes from master to 8.3. Extra remarks, from squashed changes About "Handle undeclared branches differently than empty set..." This was not obvious to me that non protected targets are granted. If target is not declared, and then branches name not checked, just presence of commits, more logs provided to users. About "Pylint source, fix redefined-builtin W0622" Fix redefined-builtin mistake on hash (BTW I noticed similar mistakes elsewhere to be fixed in later PR that pylint the script) About "Log exception on missing remote branches", I removed the tuple containing the results because it is useless and not working when there is no result. now it raises an exception (which will be ignored and attempt to look for commit in other branches, a log may be printed to help trouble shoot.) Relate-to: #774 (comment) Co-authored-by: Yann Dirson <yann.dirson@vates.tech> Signed-off-by: Philippe Coval <philippe.coval@vates.tech>
1 parent 3ed14a3 commit 99d5ee5

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

scripts/koji/koji_build.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
TIME_FORMAT = '%Y-%m-%d-%H-%M-%S'
1818

19-
# target -> required branch
19+
# target -> allowed branch(es), For unsupported targets just assign an empty set :"{}"
2020
PROTECTED_TARGETS = {
21-
"v8.2-ci": "8.2",
22-
"v8.2-fasttrack": "8.2",
23-
"v8.2-incoming": "8.2",
24-
"v8.3-ci": "master",
25-
"v8.3-fasttrack": "master",
26-
"v8.3-incoming": "master",
21+
"v8.2-ci": {"8.2"},
22+
"v8.2-fasttrack": {"8.2"},
23+
"v8.2-incoming": {"8.2"},
24+
"v8.3-ci": {"master", "8.3"},
25+
"v8.3-fasttrack": {"master", "8.3"},
26+
"v8.3-incoming": {"master", "8.3"},
2727
}
2828

2929
@contextmanager
@@ -46,20 +46,30 @@ def check_git_repo(dirpath):
4646
with cd(dirpath):
4747
return subprocess.run(['git', 'diff-index', '--quiet', 'HEAD', '--']).returncode == 0
4848

49-
def check_commit_is_available_remotely(dirpath, hash, target, warn):
49+
def check_commit_is_available_remotely(dirpath, sha, target, warn):
5050
with cd(dirpath):
51-
if not subprocess.check_output(['git', 'branch', '-r', '--contains', hash]):
51+
output = subprocess.check_output(['git', 'branch', '-r', '--contains', sha])
52+
if not line:
5253
raise Exception("The current commit is not available in the remote repository")
54+
logging.debug('Commit %s is contained in remote branch: %s', sha, output.decode().strip())
55+
5356
if target is not None and re.match(r'v\d+\.\d+-u-.+', target):
5457
raise Exception("Building with a user target requires using --pre-build or --test-build.\n")
5558
try:
56-
expected_branch = PROTECTED_TARGETS.get(target)
57-
if (
58-
expected_branch is not None
59-
and not is_remote_branch_commit(dirpath, hash, expected_branch)
60-
):
61-
raise Exception(f"The current commit is not the last commit in the remote branch {expected_branch}.\n"
62-
f"This is required when using the protected target {target}.\n")
59+
allowed_branches = PROTECTED_TARGETS.get(target)
60+
if allowed_branches is None:
61+
logging.debug('Target %s is not protected, any branch is allowed', target)
62+
else:
63+
for branch in allowed_branches:
64+
try:
65+
if is_remote_branch_commit(dirpath, sha, branch):
66+
logging.debug('Commit %s is on top of branch %s (target: %s)', sha, branch, target)
67+
break
68+
except Exception as e:
69+
logging.debug('Ignoring %s', e)
70+
else:
71+
raise Exception(f"The current commit is not the last commit of any remote allowed branches: {allowed_branches}.\n"
72+
f"This is required when using the protected target {target}.")
6373
except Exception as e:
6474
if warn:
6575
print(f"warning: {e}", flush=True)
@@ -152,10 +162,12 @@ def push_bumped_release(git_repo, target, test_build_id, pre_build_id):
152162
return commit
153163

154164
def is_remote_branch_commit(git_repo, sha, branch):
165+
""" Return True if commit is on top of an assumed remote branch"""
155166
with cd(git_repo):
156-
remote_sha = (
157-
subprocess.check_output(['git', 'ls-remote', 'origin', f'refs/heads/{branch}']).decode().strip().split()[0]
158-
)
167+
references = subprocess.check_output(['git', 'ls-remote', 'origin', f'refs/heads/{branch}']).decode().strip().split()
168+
if not references:
169+
raise Exception(f'Missing remote branch "{branch}"')
170+
remote_sha = references[0]
159171
return sha == remote_sha
160172

161173
def build_id_of(name, candidate):

0 commit comments

Comments
 (0)