Skip to content

Commit

Permalink
Start working on testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kwk committed Mar 22, 2024
1 parent b2ec4bc commit 5285f02
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 9 deletions.
15 changes: 15 additions & 0 deletions snapshot_manager/snapshot_manager/github_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,18 @@ def create_labels_for_strategies(self, labels: list[str], **kw_args):

def create_labels_for_archs(self, labels: list[str], **kw_args):
self._create_labels(labels=labels, prefix="arch/", color="C5DEF5", *kw_args)

def create_labels_for_in_testing(self, labels: list[str], **kw_args):
self._create_labels(
labels=labels, prefix="in_testing/", color="C2E0C6", *kw_args
)

def create_labels_for_tested_on(self, labels: list[str], **kw_args):
self._create_labels(
labels=labels, prefix="tested_on/", color="0E8A16", *kw_args
)

def create_labels_for_failed_on(self, labels: list[str], **kw_args):
self._create_labels(
labels=labels, prefix="failed_on/", color="D93F0B", *kw_args
)
69 changes: 60 additions & 9 deletions snapshot_manager/snapshot_manager/snapshot_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def check_todays_builds(self):
)
return

all_chroots = self.copr.get_copr_chroots()

logging.info("Get build states from copr")
states = self.copr.get_build_states_from_copr_monitor(
copr_ownername=self.config.copr_ownername,
Expand All @@ -50,7 +52,7 @@ def check_todays_builds(self):

logging.info("Add a build matrix")
comment_body += build_status.markdown_build_status_matrix(
chroots=self.copr.get_copr_chroots(),
chroots=all_chroots,
packages=self.config.packages,
build_states=states,
)
Expand Down Expand Up @@ -88,6 +90,9 @@ def check_todays_builds(self):
self.github.create_labels_for_projects(project_labels)
self.github.create_labels_for_archs(arch_labels)
self.github.create_labels_for_strategies(strategy_labels)
self.github.create_labels_for_in_testing(all_chroots)
self.github.create_labels_for_tested_on(all_chroots)
self.github.create_labels_for_failed_on(all_chroots)

# Remove old labels from issue if they no longer apply. This is greate
# for restarted builds for example to make all builds green and be able
Expand Down Expand Up @@ -118,18 +123,64 @@ def check_todays_builds(self):
logging.info(f"Adding label: {label}")
issue.add_to_labels(label)

# TODO(kwk): Once only tested_on/<CHROOT> labels are assigned to the
# issue we can turn this to True.
num_builds_to_succeed = len(
all_chroots
) # The wording is misleading this is the number of chroots that need successful builds
num_tests_to_run = len(all_chroots)
all_tests_succeeded = True
labels_on_issue = [label.name for label in issue.labels]

for chroot in all_chroots:
logging.info(f"Check if all builds in chroot {chroot} have succeeded")
builds_succeeded = self.copr.has_all_good_builds(
copr_ownername=self.config.copr_ownername,
copr_projectname=self.config.copr_projectname,
required_chroots=[chroot],
required_packages=self.config.packages,
states=states,
)

if not builds_succeeded:
all_tests_succeeded = False
continue

num_builds_to_succeed -= 1

logging.info(f"All builds in chroot {chroot} have succeeded!")
if f"in_testing/{chroot}" in labels_on_issue:
logging.info(
f"Chroot {chroot} is currently in testing! Not kicking off new tests."
)
all_tests_succeeded = False
elif f"tested_on/{chroot}" in labels_on_issue:
logging.info(
f"Chroot {chroot} has passed tests testing! Not kicking off new tests."
)
num_tests_to_run -= 1
elif f"failed_on/{chroot}" in labels_on_issue:
logging.info(
f"Chroot {chroot} has unsuccessful tests! Not kicking off new tests."
)
num_tests_to_run -= 1
all_tests_succeeded = False
else:
logging.info(f"Kicking off new tests for chroot {chroot}.")
all_tests_succeeded = False
issue.add_to_labels(f"in_testing/{chroot}")
# TODO(kwk): Add testing-farm code here.

logging.info("Checking if issue can be closed")
all_good = self.copr.has_all_good_builds(
copr_ownername=self.config.copr_ownername,
copr_projectname=self.config.copr_projectname,
required_chroots=self.copr.get_copr_chroots(),
required_packages=self.config.packages,
states=states,
)
if all_good:
building_is_done = num_builds_to_succeed == 0
testing_is_done = num_tests_to_run == 0 and all_tests_succeeded

if building_is_done and testing_is_done:
msg = f"@{self.config.maintainer_handle}, all required packages have been successfully built in all required chroots. We'll close this issue for you now as completed. Congratulations!"
logging.info(msg)
issue.create_comment(body=msg)
issue.edit(state="closed", state_reason="completed")
else:
logging.info("Cannot close issue yet.")

logging.info(f"Updated today's issue: {issue.html_url}")

0 comments on commit 5285f02

Please sign in to comment.