-
Notifications
You must be signed in to change notification settings - Fork 2
feat: added template for java binary builder #2
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
16f8213
feat: added template for java binary builder
rohansen856 21d58b9
feat: updated codebase to add map for build systems
rohansen856 68aff83
refactor: updated build function according to reviews
rohansen856 be27d5e
chore: added publish method to jaava builder
rohansen856 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,108 @@ | ||
| # Copyright Contributors to the Mainframe Software Hub for Linux Project. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import os | ||
| import subprocess | ||
| from monitoring.logger import Logger | ||
| from builders.plugins.plugin_interface import ArtifactBuilder | ||
|
|
||
|
|
||
| class JavaBinaryBuilder(ArtifactBuilder): | ||
| def __init__(self): | ||
| self.logger = Logger() | ||
|
|
||
| def build(self, repo_path: str, repo_gh_name: str, artifact: dict) -> str: | ||
| repo_name = os.path.basename(repo_path) | ||
| version = artifact.get("version", "1.0") | ||
|
|
||
| output_path = f"{repo_path}/build/{repo_gh_name}_{version}.jar" | ||
|
|
||
| docker_image = artifact.get("docker_image", "maven:3.9-eclipse-temurin-17") | ||
|
|
||
| try: | ||
| os.makedirs("build", exist_ok=True) | ||
|
|
||
| self.logger.info(f"Building Java artifact for {repo_gh_name}") | ||
|
|
||
| pom_path = os.path.join(repo_path, "pom.xml") | ||
| gradle_path = os.path.join(repo_path, "build.gradle") | ||
| gradle_kts_path = os.path.join(repo_path, "build.gradle.kts") | ||
|
|
||
| is_maven = os.path.exists(pom_path) | ||
| is_gradle = os.path.exists(gradle_path) or os.path.exists(gradle_kts_path) | ||
|
rohansen856 marked this conversation as resolved.
Outdated
|
||
|
|
||
| if not is_maven and not is_gradle: | ||
| raise RuntimeError( | ||
| f"No supported Java build file found in {repo_path}. " | ||
| f"Expected pom.xml or build.gradle(.kts)." | ||
| ) | ||
|
|
||
| if is_maven: | ||
| cmd = ["mvn", "-DskipTests", "clean", "package"] | ||
|
|
||
| expected_build_dir = os.path.join(repo_path, "target") | ||
|
|
||
| else: | ||
| cmd = ["gradle", "clean", "build", "-x", "test"] | ||
|
|
||
| expected_build_dir = os.path.join(repo_path, "build", "libs") | ||
|
|
||
| subprocess.run( | ||
| [ | ||
| "docker", "run", "--rm", | ||
| "-v", f"{repo_path}:{repo_path}", | ||
| "-v", f"{repo_path}:/app", | ||
| "-w", "/app", | ||
| docker_image, | ||
| ] + cmd, | ||
| check=True | ||
| ) | ||
|
|
||
| jar_candidates = [] | ||
| if os.path.isdir(expected_build_dir): | ||
| for f in os.listdir(expected_build_dir): | ||
| if f.endswith(".jar"): | ||
| jar_candidates.append(os.path.join(expected_build_dir, f)) | ||
|
|
||
| if not jar_candidates: | ||
| raise RuntimeError( | ||
| f"No JAR produced. Looked in: {expected_build_dir}. " | ||
| f"TODO: Confirm build output paths / packaging." | ||
| ) | ||
|
|
||
| chosen_jar = jar_candidates[0] | ||
|
|
||
| subprocess.run(["cp", chosen_jar, output_path], check=True) | ||
|
|
||
| self.logger.info(f"Built Java artifact at {output_path}") | ||
| return output_path | ||
|
|
||
| except subprocess.CalledProcessError as e: | ||
| self.logger.error(f"Failed to build Java artifact for {repo_name}: {str(e)}") | ||
| raise | ||
|
|
||
| def publish(self, artifact_path: str, repo_gh_name: str, artifact: dict) -> None: | ||
| from lib.checksum import generate_checksum | ||
|
|
||
| checksum = generate_checksum(artifact_path) | ||
| version = artifact.get("version", "1.0") | ||
|
|
||
| self.logger.info(f"Publishing {artifact_path} with checksum {checksum} for {repo_gh_name}") | ||
|
|
||
| try: | ||
| subprocess.run( | ||
| [ | ||
| "gh", "release", "create", f"v{version}", | ||
| "--title", f"Version {version}", | ||
| "--generate-notes", | ||
| artifact_path, | ||
| f"{artifact_path}.sha256", | ||
| ], | ||
| cwd=os.path.dirname(artifact_path), | ||
| check=True | ||
| ) | ||
| self.logger.info(f"Published {artifact_path} to GitHub Releases") | ||
|
|
||
| except subprocess.CalledProcessError as e: | ||
| self.logger.error(f"Failed to publish {artifact_path}: {str(e)}") | ||
| raise | ||
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.