mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-12 02:32:10 +00:00
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may not be viewable. --> <!-- You can view Contributing.MD for a detailed description of the pull request process. --> ## About The Pull Request Adds support for bubber-related code for the CI checks <!-- Describe The Pull Request. Please be sure every change is documented or this can delay review and even discourage maintainers from merging your PR! --> <!-- Please make sure to actually test your PRs. If you have not tested your PR mention it. --> ## Why It's Good For The Game Helps ensure code sanity. <!-- Argue for the merits of your changes and how they benefit the game, especially if they are controversial and/or far reaching. If you can't actually explain WHY what you are doing will improve the game, then it probably isn't good for the game in the first place. --> ## Proof Of Testing CI checks <!-- Compile and run your code locally. Make sure it works. This is the place to show off your changes! We are not responsible for testing your features. --> --------- Co-authored-by: BongaTheProto <93835010+BongaTheProto@users.noreply.github.com> Co-authored-by: Swift <jackwars4@gmail.com> Co-authored-by: The Sharkening <95130227+StrangeWeirdKitten@users.noreply.github.com> Co-authored-by: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Co-authored-by: Kyle Spier-Swenson <kyleshome@gmail.com> Co-authored-by: thegrb93 <grbrown93@sbcglobal.net> Co-authored-by: SpaceLoveSs13 <68121607+SpaceLoveSs13@users.noreply.github.com> Co-authored-by: projectkepler-RU <99981766+projectkepler-ru@users.noreply.github.com> Co-authored-by: Bubberbot <151680451+Bubberbot@users.noreply.github.com> Co-authored-by: lessthanthree <83487515+lessthnthree@users.noreply.github.com> Co-authored-by: Shadow-Quill <44811257+Shadow-Quill@users.noreply.github.com> Co-authored-by: KathrinBailey <53862927+KathrinBailey@users.noreply.github.com> Co-authored-by: Waterpig <49160555+Majkl-J@users.noreply.github.com> Co-authored-by: snailomi <148835423+snailomi@users.noreply.github.com> Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com> Co-authored-by: Lutowski <136726218+Lutowski@users.noreply.github.com> Co-authored-by: nevimer <77420409+nevimer@users.noreply.github.com>
159 lines
4.2 KiB
Python
159 lines
4.2 KiB
Python
import os
|
|
import re
|
|
import sys
|
|
|
|
define_regex = re.compile(r"(\s+)?#define\s?([A-Z0-9_]+)\(?(.+)\)?")
|
|
|
|
def green(text):
|
|
return "\033[32m" + str(text) + "\033[0m"
|
|
|
|
def red(text):
|
|
return "\033[31m" + str(text) + "\033[0m"
|
|
|
|
# simple way to check if we're running on github actions, or on a local machine
|
|
on_github = os.getenv("GITHUB_ACTIONS") == "true"
|
|
|
|
defines_file = "code/__DEFINES/traits/declarations.dm"
|
|
skyrat_defines_file = "code/__DEFINES/~skyrat_defines/traits/declarations.dm" # SKYRAT EDIT ADDITION
|
|
bubber_defines_file = "code/__DEFINES/~~bubber_defines/traits/declarations.dm" # BUBBER EDIT ADDITION
|
|
globalvars_file = "code/_globalvars/traits/_traits.dm"
|
|
|
|
how_to_fix_message = f"Please ensure that all traits in the {defines_file} file are added in the {globalvars_file} file."
|
|
|
|
def post_error(define_name):
|
|
if on_github:
|
|
print(f"::error file={defines_file},title=Define Sanity::{define_name} is defined in {defines_file} but not added to {globalvars_file}!")
|
|
else:
|
|
print(red(f"- Failure: {define_name} is defined in {defines_file} but not added to {globalvars_file}!"))
|
|
|
|
number_of_defines = 0
|
|
|
|
if not os.path.isfile(defines_file):
|
|
print(red(f"Could not find the defines file '{defines_file}'!"))
|
|
sys.exit(1)
|
|
|
|
# SKYRAT EDIT ADDITION START
|
|
if not os.path.isfile(skyrat_defines_file):
|
|
print(red(f"Could not find the skyrat defines file '{skyrat_defines_file}'!"))
|
|
sys.exit(1)
|
|
# SKYRAT EDIT ADDITION END
|
|
|
|
# BUBBER EDIT ADDITION START
|
|
if not os.path.isfile(bubber_defines_file):
|
|
print(red(f"Could not find the bubber defines file '{bubber_defines_file}'!"))
|
|
sys.exit(1)
|
|
# BUBBER EDIT ADDITION END
|
|
|
|
if not os.path.isfile(globalvars_file):
|
|
print(red(f"Could not find the globalvars file '{globalvars_file}'!"))
|
|
sys.exit(1)
|
|
|
|
defines_to_search_for = []
|
|
missing_defines = []
|
|
scannable_lines = []
|
|
|
|
with open(defines_file, 'r') as file:
|
|
reading = False
|
|
|
|
for line in file:
|
|
line = line.strip()
|
|
|
|
if line == "// BEGIN TRAIT DEFINES":
|
|
reading = True
|
|
continue
|
|
elif line == "// END TRAIT DEFINES":
|
|
break
|
|
elif not reading:
|
|
continue
|
|
|
|
scannable_lines.append(line)
|
|
|
|
for potential_define in scannable_lines:
|
|
match = define_regex.match(potential_define)
|
|
if not match:
|
|
continue
|
|
|
|
number_of_defines += 1
|
|
defines_to_search_for.append(match.group(2))
|
|
|
|
# SKYRAT EDIT ADDITION START
|
|
scannable_lines = []
|
|
with open(skyrat_defines_file, 'r') as file:
|
|
reading = False
|
|
|
|
for line in file:
|
|
line = line.strip()
|
|
|
|
if line == "// BEGIN TRAIT DEFINES":
|
|
reading = True
|
|
continue
|
|
elif line == "// END TRAIT DEFINES":
|
|
break
|
|
elif not reading:
|
|
continue
|
|
|
|
scannable_lines.append(line)
|
|
|
|
for potential_define in scannable_lines:
|
|
match = define_regex.match(potential_define)
|
|
if not match:
|
|
continue
|
|
|
|
number_of_defines += 1
|
|
defines_to_search_for.append(match.group(2))
|
|
# SKYRAT EDIT ADDITION END
|
|
|
|
# BUBBER EDIT ADDITION START
|
|
scannable_lines = []
|
|
with open(bubber_defines_file, 'r') as file:
|
|
reading = False
|
|
|
|
for line in file:
|
|
line = line.strip()
|
|
|
|
if line == "// BEGIN TRAIT DEFINES":
|
|
reading = True
|
|
continue
|
|
elif line == "// END TRAIT DEFINES":
|
|
break
|
|
elif "//" in line or "#define" not in line:
|
|
continue
|
|
elif not reading:
|
|
continue
|
|
|
|
scannable_lines.append(line)
|
|
|
|
for potential_define in scannable_lines:
|
|
match = define_regex.match(potential_define)
|
|
if not match:
|
|
continue
|
|
|
|
number_of_defines += 1
|
|
defines_to_search_for.append(match.group(2))
|
|
# BUBBER EDIT ADDITION END
|
|
|
|
if number_of_defines == 0:
|
|
print(red("No defines found! This is likely an error."))
|
|
sys.exit(1)
|
|
|
|
if number_of_defines <= 450:
|
|
print(red(f"Only found {number_of_defines} defines! Something has likely gone wrong as the number of global traits should not be this low."))
|
|
sys.exit(1)
|
|
|
|
with open(globalvars_file, "r") as file:
|
|
globalvars_file_contents = file.read()
|
|
for define_name in defines_to_search_for:
|
|
searchable_string = "\"" + define_name + "\" = " + define_name
|
|
if not re.search(searchable_string, globalvars_file_contents):
|
|
missing_defines.append(define_name)
|
|
|
|
if len(missing_defines):
|
|
for missing_define in missing_defines:
|
|
post_error(missing_define)
|
|
|
|
print(red(how_to_fix_message))
|
|
sys.exit(1)
|
|
|
|
else:
|
|
print(green(f"All traits were found in both files! (found {number_of_defines} defines)"))
|