ci: catch duplicate YAML keys in the GameDB

This commit is contained in:
Tyler Wilding 2022-05-22 21:09:50 -04:00 committed by refractionpcsx2
parent 5c790b8540
commit b54facdbd8
3 changed files with 23 additions and 6 deletions

View File

@ -19,9 +19,15 @@ jobs:
- name: Checkout Repository - name: Checkout Repository
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Validate GameDB - name: Validate Contents
env: env:
SCRIPT_DIR: .github/workflows/scripts/validation/lint-gamedb GAMEDB_PATH: ./bin/resources/GameIndex.yaml
SCRIPT_DIR: .github/workflows/scripts/lint/gamedb
run: | run: |
pip install -r "${SCRIPT_DIR}/requirements.txt" pip install -r "${SCRIPT_DIR}/requirements.txt"
python "${SCRIPT_DIR}/lint-gamedb.py" python "${SCRIPT_DIR}/lint.py"
- name: Check Formatting
run: |
npm install -g prettier
prettier --check ./bin/Resources/GameIndex.yaml

View File

@ -1,7 +1,8 @@
import os
import yaml import yaml
# Assumes this is ran from the root of the repository # Assumes this is ran from the root of the repository
file_path = "./bin/resources/GameIndex.yaml" file_path = os.environ['GAMEDB_PATH']
# These settings have to be manually kept in sync with the emulator code unfortunately. # These settings have to be manually kept in sync with the emulator code unfortunately.
# up to date validation should ALWAYS be provided via the application! # up to date validation should ALWAYS be provided via the application!
@ -209,11 +210,21 @@ option_validation_handlers = {
"patches": (lambda serial, key, value: validate_patches(serial, key, value)), "patches": (lambda serial, key, value: validate_patches(serial, key, value)),
} }
class UniqueKeyLoader(yaml.FullLoader):
def construct_mapping(self, node, deep=False):
mapping = set()
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
if key in mapping:
raise ValueError(f"Duplicate {key!r} key found in YAML.")
mapping.add(key)
return super().construct_mapping(node, deep)
print("Opening {}...".format(file_path)) print("Opening {}...".format(file_path))
with open(file_path) as f: with open(file_path, encoding="utf-8") as f:
try: try:
print("Attempting to parse GameDB file...") print("Attempting to parse GameDB file...")
gamedb = yaml.load(f, Loader=yaml.FullLoader) gamedb = yaml.load(f, Loader=UniqueKeyLoader)
except Exception as err: except Exception as err:
print(err) print(err)
print( print(