Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheThanathor committed Oct 15, 2023
2 parents 2e5f08d + 5f0b408 commit 37e0be9
Show file tree
Hide file tree
Showing 153 changed files with 5,143 additions and 382 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ meta:
- gm4_relocators
# Important notes for people when they download the module. This can be empty
notes: []
# Keywords used by gm4.co's search feature, may be omitted
search_keywords:
- shamir
- enderpuff

# Either null or a link to the YouTube video
video: null
Expand Down
1 change: 1 addition & 0 deletions base/data/gm4/tags/blocks/full_collision.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
"minecraft:polished_andesite",
"minecraft:polished_basalt",
"minecraft:polished_blackstone",
"minecraft:polished_blackstone_bricks",
"minecraft:polished_deepslate",
"minecraft:polished_diorite",
"minecraft:polished_granite",
Expand Down
24 changes: 23 additions & 1 deletion beet-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,34 @@ pipeline:
meta: {copy_files: {data_pack: {LICENSE.md: "../LICENSE.md"}}}
- gm4.plugins.readme_generator
- gm4.plugins.write_mcmeta
- gm4.plugins.output.release
meta:
mecha:
formatting:
layout: preserve
nbt_compact: True
- broadcast: 'lib_*'
extend: 'beet.yaml'
pipeline:
- beet.contrib.lantern_load.base_data_pack
- gm4.plugins.versioning.isolated_library
- gm4.plugins.manifest.write_credits
- require: [beet.contrib.copy_files]
meta:
copy_files:
data_pack:
LICENSE.md: "LICENSE.md"
README.md: "README.md"
pack.png: "pack.png"
- gm4.plugins.module.default_pack_icon
- gm4.plugins.readme_generator.libraries
- gm4.plugins.write_mcmeta
- gm4.plugins.output.release
meta:
mecha:
formatting:
layout: preserve
nbt_compact: True

meta:
autosave:
link: false
88 changes: 46 additions & 42 deletions gm4/plugins/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class ManifestCacheModel(BaseModel):
class ManifestFileModel(BaseModel):
"""describes the structure of the meta.json saved to disk"""
last_commit: str
modules: list[ManifestModuleModel]
modules: list[ManifestModuleModel] # straight list for website backward compat
libraries: dict[str, ManifestModuleModel]
contributors: Any


Expand Down Expand Up @@ -136,59 +137,63 @@ def update_patch(ctx: Context):
logger = parent_logger.getChild("update_patch")
skin_cache = JsonFile(source_path="gm4/skin_cache.json").data

modules = ManifestCacheModel.parse_obj(ctx.cache["gm4_manifest"].json).modules
manifest_cache = ManifestCacheModel.parse_obj(ctx.cache["gm4_manifest"].json)

if manifest_file.exists():
manifest = ManifestFileModel.parse_obj(json.loads(manifest_file.read_text()))
last_commit = manifest.last_commit
released_modules: dict[str, ManifestModuleModel] = {m.id:m for m in manifest.modules if m.version}
released_modules |= manifest.libraries
else:
logger.debug("No existing meta.json manifest file was located")
last_commit = None
released_modules = {}

for id in modules:
module = modules[id]
released = released_modules.get(id, None)

publish_date = released.publish_date if released else None
module.publish_date = publish_date or datetime.datetime.now().date().isoformat()

deps = _traverse_includes(id) | {"base"}
deps_dirs = [element for sublist in [[f"{d}/data", f"{d}/*py"] for d in deps] for element in sublist]

# add watches to skins this module uses from other modules. NOTE this could be done in a more extendable way in the future, rather than "hardcoded"
skin_dep_dirs: list[str] = []
for skin_ref in skin_cache["nonnative_references"].get(id, []):
d = skin_cache["skins"][skin_ref]["parent_module"]
ns, path = skin_ref.split(":")
skin_dep_dirs.append(f"{d}/data/{ns}/skins/{path}.png")

watch_dirs = deps_dirs+skin_dep_dirs

diff = run(["git", "diff", last_commit, "--shortstat", "--", f"{id}/data", f"{id}/*.py"] + watch_dirs) if last_commit else True

if not diff and released:
# No changes were made, keep the same patch version
module.version = released.version
elif not released:
# First release
module.version = module.version.replace("X", "0")
logger.debug(f"First release of {id}")
else:
# Changes were made, bump the patch
version = Version(module.version)
last_ver = Version(released.version)
for packs in (manifest_cache.modules, manifest_cache.libraries):
for id in packs:
pack = packs[id]
released = released_modules.get(id, None)

publish_date = released.publish_date if released else None
pack.publish_date = publish_date or datetime.datetime.now().date().isoformat()

deps = _traverse_includes(id)
if packs is manifest_cache.modules:
deps |= {"base"} # scan the base directory if this is a module
deps_dirs = [element for sublist in [[f"{d}/data", f"{d}/*py"] for d in deps] for element in sublist]

# add watches to skins this module uses from other modules. NOTE this could be done in a more extendable way in the future, rather than "hardcoded"
skin_dep_dirs: list[str] = []
for skin_ref in skin_cache["nonnative_references"].get(id, []):
d = skin_cache["skins"][skin_ref]["parent_module"]
ns, path = skin_ref.split(":")
skin_dep_dirs.append(f"{d}/data/{ns}/skins/{path}.png")

if version.minor > last_ver.minor or version.major > last_ver.major: # type: ignore
version.patch = 0
watch_dirs = deps_dirs+skin_dep_dirs

diff = run(["git", "diff", last_commit, "--shortstat", "--", f"{id}/data", f"{id}/*.py"] + watch_dirs) if last_commit else True

if not diff and released:
# No changes were made, keep the same patch version
pack.version = released.version
elif not released:
# First release
pack.version = pack.version.replace("X", "0")
logger.debug(f"First release of {id}")
else:
version.patch = last_ver.patch + 1 # type: ignore
logger.info(f"Updating {id} patch to {version.patch}")
# Changes were made, bump the patch
version = Version(pack.version)
last_ver = Version(released.version)

if version.minor > last_ver.minor or version.major > last_ver.major: # type: ignore
version.patch = 0
else:
version.patch = last_ver.patch + 1 # type: ignore
logger.info(f"Updating {id} patch to {version.patch}")

module.version = str(version)
pack.version = str(version)

ctx.cache["gm4_manifest"].json["modules"] = {id:m.dict() for id, m in modules.items()}
ctx.cache["gm4_manifest"].json = manifest_cache.dict()

@cache
def _traverse_includes(project_id: str) -> set[str]:
Expand All @@ -213,7 +218,6 @@ def write_meta(ctx: Context):
manifest_file = release_dir / "meta.json"
manifest = ctx.cache["gm4_manifest"].json.copy()
manifest["modules"] = list(manifest["modules"].values()) # convert modules dict down to list for backwards compatability
manifest.pop("libraries")
manifest.pop("base")
manifest_file.write_text(json.dumps(manifest, indent=2))

Expand Down Expand Up @@ -260,7 +264,7 @@ def write_updates(ctx: Context):
if init is None:
return

manifest =ManifestCacheModel.parse_obj(ctx.cache["gm4_manifest"].json)
manifest = ManifestCacheModel.parse_obj(ctx.cache["gm4_manifest"].json)
modules = manifest.modules

score = f"{ctx.project_id.removeprefix('gm4_')} gm4_modules"
Expand Down
Loading

0 comments on commit 37e0be9

Please sign in to comment.