chore: monitor structure of the project (#6291)

This commit is contained in:
Piotr Idzik
2025-06-12 17:35:01 +02:00
committed by GitHub
parent 1745d19f09
commit b427b40f56
2 changed files with 49 additions and 0 deletions

22
.github/workflows/project_structure.yml vendored Normal file
View File

@ -0,0 +1,22 @@
---
name: ProjectStructure
'on':
workflow_dispatch:
push:
branches:
- master
pull_request:
jobs:
check_structure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Check project structure
run: python3 .github/workflows/scripts/check_structure.py
...

View File

@ -0,0 +1,27 @@
import pathlib
import sys
def _is_java_file_properly_located(java_file: pathlib.Path) -> bool:
main_parents = java_file.parent.parents
return (
pathlib.Path("src/main/java/com/thealgorithms/") in main_parents
or pathlib.Path("src/test/java/com/thealgorithms/") in main_parents
)
def _find_misplaced_java_files() -> list[pathlib.Path]:
return [
java_file
for java_file in pathlib.Path(".").rglob("*.java")
if not _is_java_file_properly_located(java_file)
]
if __name__ == "__main__":
misplaced_files = _find_misplaced_java_files()
if misplaced_files:
print("The following java files are not located in the correct directory:")
for _ in misplaced_files:
print(_)
sys.exit(1)