-
Notifications
You must be signed in to change notification settings - Fork 832
fix: exclude standalone examples from mise run format
#1931
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
+89
−3
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # [MISE] description="Verify standalone example POMs won't break spotless" | ||
|
|
||
| """Check that standalone example modules don't break 'mise run format'. | ||
|
|
||
| Example modules are intentionally standalone (no <parent> from the project) | ||
| so users can copy them. But they're included in the Maven reactor via the | ||
| examples-and-integration-tests profile. If 'mise run format' doesn't | ||
| exclude them, spotless:apply fails because the plugin isn't declared. | ||
|
|
||
| This lint verifies that every standalone example POM is excluded from | ||
| the format task in mise.toml. | ||
| """ | ||
|
|
||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| ROOT = Path(__file__).resolve().parents[3] | ||
| EXAMPLES_DIR = ROOT / "examples" | ||
|
|
||
|
|
||
| def find_standalone_example_poms() -> list[Path]: | ||
| """Find example pom.xml files that don't inherit from the project parent.""" | ||
| standalone = [] | ||
| for pom in sorted(EXAMPLES_DIR.rglob("pom.xml")): | ||
| if "target" in pom.parts: | ||
| continue | ||
| text = pom.read_text(encoding="utf-8") | ||
| # Check if this POM has a <parent> with the project's groupId/artifactId | ||
| has_project_parent = bool( | ||
| re.search( | ||
| r"<parent>\s*<groupId>io\.prometheus</groupId>\s*" | ||
| r"<artifactId>client_java</artifactId>", | ||
| text, | ||
| ) | ||
| ) | ||
| if not has_project_parent: | ||
| standalone.append(pom) | ||
| return standalone | ||
|
|
||
|
|
||
| def format_task_excludes_examples() -> bool: | ||
| """Check that the format task in mise.toml excludes standalone examples.""" | ||
| mise_toml = ROOT / "mise.toml" | ||
| text = mise_toml.read_text(encoding="utf-8") | ||
| # Look for the format task run command | ||
| match = re.search(r'\[tasks\.format\].*?run\s*=\s*"([^"]*)"', text, re.DOTALL) | ||
| if not match: | ||
| return False | ||
| run_cmd = match.group(1) | ||
| # The command should deactivate the examples-and-integration-tests profile | ||
| return "!examples-and-integration-tests" in run_cmd | ||
|
|
||
|
|
||
| def main() -> int: | ||
| standalone = find_standalone_example_poms() | ||
| if not standalone: | ||
| return 0 | ||
|
|
||
| if format_task_excludes_examples(): | ||
| return 0 | ||
|
|
||
| print("ERROR: Standalone example POMs found but 'mise run format'") | ||
| print("does not exclude the examples-and-integration-tests profile.") | ||
| print() | ||
| print("Standalone example POMs (no project parent):") | ||
| for pom in standalone: | ||
| print(f" {pom.relative_to(ROOT)}") | ||
| print() | ||
| print("Fix: ensure the format task in mise.toml deactivates the") | ||
| print("examples-and-integration-tests profile, e.g.:") | ||
| print(" -P '!examples-and-integration-tests'") | ||
| return 1 | ||
|
|
||
|
|
||
| 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
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.
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.
👍