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

DM-47418: Add GitHub PR check for Jenkins #44

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

Conversation

aranabhat
Copy link

Github Checks

@aranabhat aranabhat force-pushed the tickets/DM-47418 branch 2 times, most recently from 9f3af9d to ae03b7e Compare February 4, 2025 22:03
@aranabhat aranabhat requested a review from roceb February 4, 2025 22:09
@aranabhat aranabhat force-pushed the tickets/DM-47418 branch 2 times, most recently from 515a94f to fb503e4 Compare February 7, 2025 12:24
@aranabhat
Copy link
Author

aranabhat commented Feb 7, 2025

Example of a 'fail' stack-os-matrix
Example of a 'success' stack-os-matrix
--search for 'pr info' and 'github status' to see updates I've made

If you want to see an example of the checks working in real time, feel free to watch daf_butler dummy PR or afw dummy prs while re-building this build .

@aranabhat aranabhat marked this pull request as ready for review February 7, 2025 13:34
@aranabhat aranabhat requested a review from timj February 7, 2025 13:58
@timj timj changed the title tickets/DM-47418 DM-47418: Add GitHub PR check for Jenkins Feb 7, 2025
# Ensure build directory exists and is writable
build_dir = args.build_dir
if not os.access(build_dir, os.W_OK):
raise Exception(f"Directory {build_dir!r} does not exist or isn't writable.")

# Load PR information saved by prepare.py
pr_info = Builder.load_pr_info(build_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why these are static methods on this class. You might consider a class used to manage the PR info that's used by both build.py and prepare.py.

"""Handles agent label determination and verification."""

def __init__(self):
self.agent = self.verify_agent()
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems maybe a bit much to go through a class and three levels of functions to do this when it's unlikely that the inner methods will be called separately.

def extract_github_repo_info(self, url):
"""Retrieve repo owner and name from URL"""
# Remove the '.git' suffix
if url.endswith(".git"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Look into str.removesuffix().

Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

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

I've made some general comments that I think need to be taken into account and then I will review again. I think your code would be more robust and clearer if the pr_info was a pydantic model.


@staticmethod
def load_pr_info(build_dir):
"""Load PR information saved by prepare.py and parse the list."""
Copy link
Member

Choose a reason for hiding this comment

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

Please add numpydoc docstrings to these new methods.


Parameters
----------
pr_info : dict
Copy link
Member

Choose a reason for hiding this comment

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

This feels like it should be at least a dataclass (preferably a pydantic model). Using a dictionary makes things hard to validate. (Also backticks needed around types).

Copy link
Member

Choose a reason for hiding this comment

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

Also, once it's a pydantic model this leads to other code simplifications since the "post success or failure" code would be methods on the class rather than standalone loops over each PR.


pr_info.extend(matching_pr)

if pr_info:
Copy link
Member

Choose a reason for hiding this comment

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

Switch the pr_info to a pydantic model which can handle the JSON round tripping for you. You do not want to be constructing lists of dicts and writing to json and then reading it back as lists of dicts, you want to define the data model explicitly.

if url.endswith(".git"):
url = url[:-4]

if url.startswith("https://github.com/"):
Copy link
Member

@timj timj Feb 7, 2025

Choose a reason for hiding this comment

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

Please do not try to parse URLs yourself. Please use urllib.urlparse.

Copy link

@roceb roceb left a comment

Choose a reason for hiding this comment

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

Left a few changes but great job overall!

self.agent = self.verify_agent()

def verify_agent(self):
agent = self.agent_label()
Copy link

Choose a reason for hiding this comment

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

You declare agent_label as a staticmethod, but the call it with self. Staticmethods are callable without instantiating the class, and doesn't require self as parameter.

if not os_type or not arch:
return "unknown_agent"

if os_type.startswith("darwin"):
Copy link

Choose a reason for hiding this comment

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

For simplicity reasons, you can use a switch statement to check if its darwin then agent = f"apple_{arch}", and for everything else agent = f"{os_type}_{arch}"

# Attempt the build
retcode = b.build()

except Exception as other_ex:
Copy link

Choose a reason for hiding this comment

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

This will catch all the exception, normally you want to catch one or two. You should look into raising exceptions as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants