Added selection for build version
This commit is contained in:
parent
7853bc5a94
commit
397d307f13
49
build.py
49
build.py
@ -17,9 +17,14 @@ def get_entity(route: str, base_url: str = default_base_url):
|
||||
cachefile = cache_path / f"{route.strip(slashes)}.json"
|
||||
return jsongetcache.load_cached(base_url + route, cachefile)
|
||||
|
||||
def get_latest_release(versions: Iterable[ModPackVersion]):
|
||||
return max((version for version in versions if version["type"].lower() == "release"), key=lambda version: version["updated"])
|
||||
def get_latest_release(versions: Iterable[ModPackVersion], version_types: list[str] = ["release"]):
|
||||
return max((version for version in versions if version["type"].lower() in version_types), key=lambda version: version["updated"], default=None)
|
||||
|
||||
def get_version_by_id(versions: Iterable[ModPackVersion], version_id: int):
|
||||
return next((version for version in versions if version["id"] == version_id), None)
|
||||
|
||||
def get_version_by_name(versions: Iterable[ModPackVersion], version_name: str):
|
||||
return next((version for version in versions if version["name"] == version_name), None)
|
||||
|
||||
def get_modpack_route(modpack: ModPackManifest | int):
|
||||
return f"/public/modpack/{modpack if isinstance(modpack, int) else modpack['id']}"
|
||||
@ -63,27 +68,55 @@ def get_installer(modpack: ModPackManifest | int, version: ModPackVersion | int,
|
||||
def parse_arguments():
|
||||
parser = ArgumentParser("build.py", description="FTB Docker image build helper.")
|
||||
parser.add_argument("modpack", type=int, help="Modpack ID")
|
||||
parser.add_argument("--version", "-v", type=int, help="Specific Modpack Version ID, otherwise uses the latest")
|
||||
parser.add_argument("--version", "-v", type=str, help="Specific Modpack Version ID, otherwise uses the latest release")
|
||||
return parser.parse_args()
|
||||
|
||||
def get_version_by_description(modpack: ModPackManifest, version_name: str | None) -> ModPackVersion | None:
|
||||
if version_name is None:
|
||||
return get_version_by_description(modpack, "release")
|
||||
|
||||
if version_name.lower() in ["alpha", "beta", "release"]:
|
||||
return get_latest_release(modpack["versions"], version_types=[version_name.lower()])
|
||||
|
||||
match get_version_by_name(modpack["versions"], version_name):
|
||||
case None:
|
||||
pass
|
||||
case idd_version:
|
||||
return idd_version
|
||||
|
||||
try:
|
||||
match get_version_by_id(modpack["versions"], int(version_name)):
|
||||
case None:
|
||||
pass
|
||||
case idd_version:
|
||||
return idd_version
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = parse_arguments()
|
||||
modpack = get_modpack_manifest(args.modpack)
|
||||
slug = get_modpack_slug(modpack)
|
||||
print("Slug", slug)
|
||||
if args.version is None:
|
||||
args.version = get_latest_release(modpack["versions"])["id"]
|
||||
version = get_version_manifest(modpack, args.version)
|
||||
selected_version = get_version_by_description(modpack, args.version)
|
||||
if selected_version is None:
|
||||
print(f"Available versions for: {modpack['name']}")
|
||||
for version in modpack["versions"]:
|
||||
print(f"- {version['type']} {version['name']} [{version['id']}]")
|
||||
raise Exception(f"No version was found matching \"{args.version}\"")
|
||||
version = get_version_manifest(modpack, selected_version)
|
||||
print(f"{modpack['name']} version {version['name']}: updated {datetime.fromtimestamp(version['updated'])}")
|
||||
java_target = next((target for target in version["targets"] if target["type"] == "runtime" and target["name"] == "java"), None)
|
||||
|
||||
java_target = next((target for target in version["targets"] if target["type"].lower() == "runtime" and target["name"].lower() == "java"), None)
|
||||
if java_target is None:
|
||||
raise Exception(f"{modpack['name']} version {version['name']} has no java target: {' ,'.join(str(x) for x in version['targets'])}")
|
||||
|
||||
# java_version = version_without_build(java_target["version"])
|
||||
print(f"Required java version is version {java_target['version']}")
|
||||
java_version = java_target["version"].replace('+', '_')
|
||||
print(f"Required java version is version {java_version}")
|
||||
# base_image = f"azul/zulu-openjdk:{java_version}-jre"
|
||||
base_image = f"eclipse-temurin:{java_version}-jre"
|
||||
print(f"Using docker base image: {base_image}")
|
||||
|
||||
repo = f"hub.cnml.de/{slug}"
|
||||
semver_version_tags = docker.semver_tags(version["name"])
|
||||
|
Loading…
Reference in New Issue
Block a user