🔨 add Developer tools/scripts (#828)
* 🔨 add Developer tools
* Update downloader.js
* Update game.js
* Update .pre-commit-config.yaml
* Update sync_versions.yml
* removed: mixed line ending tool
* Update swagger.yml
* Update push-docker.yml
* Update build.yml
---------
Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
This commit is contained in:
parent
70e4ac21df
commit
1af41f8ea5
8 changed files with 303 additions and 0 deletions
51
.github/scripts/check_duplicates.py
vendored
Normal file
51
.github/scripts/check_duplicates.py
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
import sys
|
||||
|
||||
|
||||
def find_duplicate_keys(file_path):
|
||||
"""
|
||||
Finds duplicate keys in a properties file and returns their occurrences.
|
||||
|
||||
This function reads a properties file, identifies any keys that occur more than
|
||||
once, and returns a dictionary with these keys and the line numbers of their occurrences.
|
||||
|
||||
Parameters:
|
||||
file_path (str): The path to the properties file to be checked.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary where each key is a duplicated key in the file, and the value is a list
|
||||
of line numbers where the key occurs.
|
||||
"""
|
||||
with open(file_path, "r", encoding="utf-8") as file:
|
||||
lines = file.readlines()
|
||||
|
||||
keys = {}
|
||||
duplicates = {}
|
||||
|
||||
for line_number, line in enumerate(lines, start=1):
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#") and "=" in line:
|
||||
key = line.split("=", 1)[0].strip()
|
||||
if key in keys:
|
||||
# If the key already exists, add the current line number
|
||||
duplicates.setdefault(key, []).append(line_number)
|
||||
# Also add the first instance of the key if not already done
|
||||
if keys[key] not in duplicates[key]:
|
||||
duplicates[key].insert(0, keys[key])
|
||||
else:
|
||||
# Store the line number of the first instance of the key
|
||||
keys[key] = line_number
|
||||
|
||||
return duplicates
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
failed = False
|
||||
for ar in sys.argv[1:]:
|
||||
duplicates = find_duplicate_keys(ar)
|
||||
if duplicates:
|
||||
for key, lines in duplicates.items():
|
||||
lines_str = ", ".join(map(str, lines))
|
||||
print(f"{key} duplicated in {ar} on lines {lines_str}")
|
||||
failed = True
|
||||
if failed:
|
||||
sys.exit(1)
|
84
.github/scripts/check_tabulator.py
vendored
Normal file
84
.github/scripts/check_tabulator.py
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
"""check_tabulator.py"""
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
|
||||
def check_tabs(file_path):
|
||||
"""
|
||||
Checks for tabs in the specified file.
|
||||
|
||||
Args:
|
||||
file_path (str): The path to the file to be checked.
|
||||
|
||||
Returns:
|
||||
bool: True if tabs are found, False otherwise.
|
||||
"""
|
||||
with open(file_path, "r", encoding="utf-8") as file:
|
||||
content = file.read()
|
||||
|
||||
if "\t" in content:
|
||||
print(f"Tab found in {file_path}")
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def replace_tabs_with_spaces(file_path, replace_with=" "):
|
||||
"""
|
||||
Replaces tabs with a specified number of spaces in the file.
|
||||
|
||||
Args:
|
||||
file_path (str): The path to the file where tabs will be replaced.
|
||||
replace_with (str): The character(s) to replace tabs with. Defaults to two spaces.
|
||||
"""
|
||||
with open(file_path, "r", encoding="utf-8") as file:
|
||||
content = file.read()
|
||||
|
||||
updated_content = content.replace("\t", replace_with)
|
||||
|
||||
with open(file_path, "w", encoding="utf-8") as file:
|
||||
file.write(updated_content)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main function to replace tabs with spaces in the provided files.
|
||||
The replacement character and files to check are taken from command line arguments.
|
||||
"""
|
||||
# Create ArgumentParser instance
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Replace tabs in files with specified characters."
|
||||
)
|
||||
|
||||
# Define optional argument `--replace_with`
|
||||
parser.add_argument(
|
||||
"--replace_with",
|
||||
default=" ",
|
||||
help="Character(s) to replace tabs with. Default is two spaces.",
|
||||
)
|
||||
|
||||
# Define argument for file paths
|
||||
parser.add_argument("files", metavar="FILE", nargs="+", help="Files to process.")
|
||||
|
||||
# Parse arguments
|
||||
args = parser.parse_args()
|
||||
|
||||
# Extract replacement characters and files from the parsed arguments
|
||||
replace_with = args.replace_with
|
||||
files_checked = args.files
|
||||
|
||||
error = False
|
||||
|
||||
for file_path in files_checked:
|
||||
if check_tabs(file_path):
|
||||
replace_tabs_with_spaces(file_path, replace_with)
|
||||
error = True
|
||||
|
||||
if error:
|
||||
print("Error: Originally found tabs in HTML files, now replaced.")
|
||||
sys.exit(1)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
67
.github/scripts/gradle_to_chart.py
vendored
Normal file
67
.github/scripts/gradle_to_chart.py
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
import re
|
||||
import yaml
|
||||
|
||||
# Paths to the files
|
||||
chart_yaml_path = "chart/stirling-pdf/Chart.yaml"
|
||||
gradle_path = "build.gradle"
|
||||
|
||||
|
||||
def get_chart_version(path):
|
||||
"""
|
||||
Reads the appVersion from Chart.yaml.
|
||||
|
||||
Args:
|
||||
path (str): The file path to the Chart.yaml.
|
||||
|
||||
Returns:
|
||||
str: The appVersion if found, otherwise an empty string.
|
||||
"""
|
||||
with open(path, encoding="utf-8") as file:
|
||||
chart_yaml = yaml.safe_load(file)
|
||||
return chart_yaml.get("appVersion", "")
|
||||
|
||||
|
||||
def get_gradle_version(path):
|
||||
"""
|
||||
Extracts the version from build.gradle.
|
||||
|
||||
Args:
|
||||
path (str): The file path to the build.gradle.
|
||||
|
||||
Returns:
|
||||
str: The version if found, otherwise an empty string.
|
||||
"""
|
||||
with open(path, encoding="utf-8") as file:
|
||||
for line in file:
|
||||
if "version =" in line:
|
||||
# Extracts the value after 'version ='
|
||||
return re.search(r'version\s*=\s*[\'"](.+?)[\'"]', line).group(1)
|
||||
return ""
|
||||
|
||||
|
||||
def update_chart_version(path, new_version):
|
||||
"""
|
||||
Updates the appVersion in Chart.yaml with a new version.
|
||||
|
||||
Args:
|
||||
path (str): The file path to the Chart.yaml.
|
||||
new_version (str): The new version to update to.
|
||||
"""
|
||||
with open(path, encoding="utf-8") as file:
|
||||
chart_yaml = yaml.safe_load(file)
|
||||
chart_yaml["appVersion"] = new_version
|
||||
with open(path, "w", encoding="utf-8") as file:
|
||||
yaml.safe_dump(chart_yaml, file)
|
||||
|
||||
|
||||
# Main logic
|
||||
chart_version = get_chart_version(chart_yaml_path)
|
||||
gradle_version = get_gradle_version(gradle_path)
|
||||
|
||||
if chart_version != gradle_version:
|
||||
print(
|
||||
f"Versions do not match. Updating Chart.yaml from {chart_version} to {gradle_version}."
|
||||
)
|
||||
update_chart_version(chart_yaml_path, gradle_version)
|
||||
else:
|
||||
print("Versions match. No update required.")
|
Loading…
Add table
Add a link
Reference in a new issue