Skip to content

Commit

Permalink
Adds CI to verify maps are within 255x255x1 (#25369)
Browse files Browse the repository at this point in the history
* Adds CI to verify maps are within 255x255x1

* Ooops platform agnostic

* Webedit to fight autoformat

* Time that shit

---------

Signed-off-by: AffectedArc07 <[email protected]>
  • Loading branch information
AffectedArc07 authored May 25, 2024
1 parent bd0e547 commit 0420e9a
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 8 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: CI
on:
push:
branches:
- master
- master
pull_request:
branches:
- master
- master
merge_group:

jobs:
Expand Down Expand Up @@ -49,6 +49,7 @@ jobs:
python tools/ci/illegal_dme_files.py ${GITHUB_WORKSPACE}
python tools/ci/define_sanity.py
python tools/ci/restrict_file_types.py
python tools/ci/check_map_sizes.py
python tools/ci/verify_sql_version.py
python tools/ci/no_duplicate_definitions.py
python -m tools.ci.check_icon_conflicts
Expand Down Expand Up @@ -134,9 +135,9 @@ jobs:
name: Windows RUSTG Validation
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8.2' # Script was made for 3.8.2
architecture: 'x86' # This MUST be x86
- run: python tools/ci/validate_rustg_windows.py
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8.2' # Script was made for 3.8.2
architecture: 'x86' # This MUST be x86
- run: python tools/ci/validate_rustg_windows.py
91 changes: 91 additions & 0 deletions tools/ci/check_map_sizes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import glob
import os
import sys
import subprocess
import platform
import json
import time

parent_directory = "_maps/**/*.dmm"

MAX_X_SIZE = 255
MAX_Y_SIZE = 255
MAX_Z_SIZE = 1

how_to_fix_message = f"Please make sure maps are <= {MAX_X_SIZE}x{MAX_Y_SIZE}x{MAX_Z_SIZE}."

def green(text):
return "\033[32m" + str(text) + "\033[0m"

def red(text):
return "\033[31m" + str(text) + "\033[0m"

def blue(text):
return "\033[34m" + str(text) + "\033[0m"

def post_error(file, map_data, github_error_style):
if github_error_style:
print(f"::error file={file},title=Map Size::{file} is >{MAX_X_SIZE}x{MAX_Y_SIZE}x{MAX_Z_SIZE} (Found: {map_data['x']},{map_data['y']},{map_data['z']})!")
else:
print(f"- Failure: {red(file)} is is >{MAX_X_SIZE}x{MAX_Y_SIZE}x{MAX_Z_SIZE} (Found: {map_data['x']},{map_data['y']},{map_data['z']})")

def do_dmmtools_call(file):
# Windows - hopefully local
exec_path = None
if platform.system() == 'Windows':
exec_path = "dmm-tools.exe"
# Linux - CI
else:
exec_path = "tools/github-actions/nanomap-renderer"

exec_args = f"{exec_path} map-info \"{file}\""
result = subprocess.run(exec_args, shell=True, capture_output=True, text=True)

res_obj = json.loads(result.stdout)

return_obj = {
"x": res_obj[file]["size"][0],
"y": res_obj[file]["size"][1],
"z": res_obj[file]["size"][2]
}

return return_obj

def main():
start = time.time()
# simple way to check if we're running on github actions, or on a local machine
on_github = os.getenv("GITHUB_ACTIONS") == "true"

maps_greater_than_allowed = []

map_count = 0

for map_file in glob.glob(parent_directory, recursive=True):
map_count += 1
# Open the map in the nanomap dmm tools - it works
map_data = do_dmmtools_call(map_file)

if map_data["x"] > MAX_X_SIZE or map_data["y"] > MAX_Y_SIZE or map_data["z"] > MAX_Z_SIZE:
maps_greater_than_allowed.append((map_file, map_data))

if len(maps_greater_than_allowed):
for error in maps_greater_than_allowed:
post_error(error[0], error[1], on_github)

print(red(how_to_fix_message))

end = time.time()
print(f"\ncheck_map_sizes.py completed in {(end - start):.2f}s\n")

sys.exit(1)

else:
print(green(f"No oversized maps found (checked {map_count} maps)."))

end = time.time()
print(f"\ncheck_map_sizes.py completed in {(end - start):.2f}s\n")

if __name__ == "__main__":
main()


0 comments on commit 0420e9a

Please sign in to comment.