-
Notifications
You must be signed in to change notification settings - Fork 10
PYTHON-5389: Add Tags to each buildvariant and augment test skipping/tracking policy. #82
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7a03b0e
first stack
Jibola f045cda
Merge branch 'main' of https://github.com/mongodb-labs/ai-ml-pipeline…
Jibola 28e4f7d
add language tags to each buildvariant
Jibola fabe044
add new policy for handling failing tests across different repos
Jibola 088abf7
fix lint
Jibola 3d467f3
Delete first_stack.txt
Jibola 69b644a
Merge branch 'main' of https://github.com/mongodb-labs/ai-ml-pipeline…
Jibola df7a55c
include pre-commit to lint the config.yml file
Jibola 2d2f67c
Merge branch 'main' of https://github.com/mongodb-labs/ai-ml-pipeline…
Jibola 7889fcc
Merge branch 'main' into PYTHON-5389
Jibola bc1f49e
install pyyaml in workflow, update configs to include language, add c…
Jibola 6397a34
Merge branch 'main' into PYTHON-5389
Jibola 3e16bb7
add python tag to mem0
Jibola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Pre-commit hook to check if buildvariant tasks contain required language tags. | ||
""" | ||
|
||
import logging | ||
import sys | ||
import yaml | ||
from pathlib import Path | ||
from typing import List, Dict, Any | ||
|
||
logging.basicConfig() | ||
logger = logging.getLogger(__file__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
|
||
CURRENT_DIR = Path(__file__).parent.resolve() | ||
CONFIG_YML = CURRENT_DIR / "config.yml" | ||
VALID_LANGUAGES = {"python", "golang", "javascript", "csharp"} | ||
|
||
|
||
def load_yaml_file(file_path: str) -> Dict[Any, Any]: | ||
"""Load and parse a YAML file.""" | ||
with open(file_path, "r", encoding="utf-8") as file: | ||
return yaml.safe_load(file) or {} | ||
|
||
|
||
def check_buildvariants(data: Dict[Any, Any]) -> List[str]: | ||
""" | ||
Check if buildvariant tasks contain at least one required language tag | ||
as well as the language within the buildvariant name. | ||
|
||
Example Buildvariant structure in YAML: | ||
buildvariants: | ||
- name: test-semantic-kernel-python-rhel | ||
display_name: Semantic-Kernel RHEL Python | ||
tags: [python] | ||
expansions: | ||
DIR: semantic-kernel-python | ||
run_on: | ||
- rhel87-small | ||
tasks: | ||
- name: test-semantic-kernel-python-local | ||
- name: test-semantic-kernel-python-remote | ||
batchtime: 10080 # 1 week | ||
|
||
Args: | ||
data: Parsed YAML data | ||
|
||
Returns: | ||
List of error messages for tasks missing required tags | ||
""" | ||
errors = [] | ||
|
||
buildvariants = data.get("buildvariants", []) | ||
if not isinstance(buildvariants, list): | ||
return ["'buildvariants' should be a list"] | ||
|
||
for i, buildvariant in enumerate(buildvariants): | ||
if not isinstance(buildvariant, dict): | ||
errors.append(f"buildvariants[{i}] should contain sub-fields") | ||
continue | ||
|
||
buildvariant_name = buildvariant.get("name", "") | ||
if not buildvariant_name: | ||
errors.append(f"buildvariants[{i}] is missing 'name'") | ||
continue | ||
else: | ||
if all([f"-{lang}-" not in buildvariant_name for lang in VALID_LANGUAGES]): | ||
errors.append( | ||
f"buildvariant '{buildvariant_name}' should contain one" | ||
f" '-[{', '.join(VALID_LANGUAGES)}]-' in its name" | ||
f"got: {buildvariant_name}", | ||
) | ||
|
||
buildvariant_display_name = buildvariant.get("display_name", buildvariant_name) | ||
|
||
tags = buildvariant.get("tags", []) | ||
|
||
if not isinstance(tags, list) or len(tags) != 1: | ||
errors.append( | ||
f"'tags' in buildvariant '{buildvariant_display_name}' should be a list of size 1" | ||
) | ||
continue | ||
|
||
if tags[0] not in VALID_LANGUAGES: | ||
errors.append( | ||
f"buildvariant '{buildvariant_display_name}' has invalid tag '{tags[0]}'. " | ||
f"Valid tags are: {', '.join(VALID_LANGUAGES)}" | ||
) | ||
return errors | ||
|
||
|
||
def main(): | ||
"""Main function for the pre-commit hook.""" | ||
total_errors = 0 | ||
|
||
data = load_yaml_file(CONFIG_YML) | ||
if not data: | ||
raise FileNotFoundError(f"Failed to load or parse {CONFIG_YML}") | ||
|
||
errors = check_buildvariants(data) | ||
|
||
if errors: | ||
logger.error("❌ Errors found in %s:", CONFIG_YML) | ||
for error in errors: | ||
logger.error(" - %s", error) | ||
total_errors += len(errors) | ||
|
||
if total_errors > 0: | ||
logger.error("❌ Total errors found: %s", total_errors) | ||
return 1 | ||
else: | ||
logger.info("✅ %s passed AI/ML testing pipeline validation", CONFIG_YML) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.