diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 07223c24da..4828463213 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -102,3 +102,13 @@ repos: additional_dependencies: ["ruamel.yaml"] files: .*\.activity\.yml types: [yaml] + + - id: check_yaml_content_activities_unique_uuid + name: Check activity.yml files for unique uuid + description: | + This hook checks activity.yml files for unique uuid + entry: python3 Tools/Hooks/check_yaml_content_activities_unique_uuid.py + language: python + files: .*\.activity\.yml + types: [yaml] + pass_filenames: false diff --git a/Tools/Hooks/check_yaml_content_activities_unique_uuid.py b/Tools/Hooks/check_yaml_content_activities_unique_uuid.py new file mode 100755 index 0000000000..206172630f --- /dev/null +++ b/Tools/Hooks/check_yaml_content_activities_unique_uuid.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 + +# Leka - LekaOS +# Copyright 2020 APF France handicap +# SPDX-License-Identifier: Apache-2.0 + +from pathlib import Path +import sys + +DIRECTORY_PATH = 'Modules/ContentKit/Resources/Content' + +path = Path(DIRECTORY_PATH) +activity_files = path.rglob('*.activity.yml') + +uuids_files = {} +duplicates_found = False + +for file in activity_files: + uuid = file.name.split('-', 1)[0] + if uuid in uuids_files: + uuids_files[uuid].append(file) + else: + uuids_files[uuid] = [file] + +for uuid, files in uuids_files.items(): + if len(files) > 1: + duplicates_found = True + print(f"❌ Duplicate UUID: {uuid}") + for file in files: + print(f" - {file}") + print() + +if duplicates_found: + sys.exit(1) +else: + sys.exit(0)