Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

icon validator #51

Merged
merged 4 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/scripts/icon_path_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json
import pathlib
import string
from typing import Final


class InvalidStructureException(Exception):
def __init__(self, msg: str):
super().__init__(msg)


class IconValidator:
def __init__(self):
self._SOURCE_DIR: Final[str] = "src"
self._TECH_DIR: Final[str] = "technologies"
self._FULL_TECH_DIR: Final[pathlib.Path] = pathlib.Path(self._SOURCE_DIR).joinpath(self._TECH_DIR)
self._IMAGES_DIR: Final[str] = "images"
self._ICONS_DIR: Final[str] = "icons"
self._FULL_IMAGES_DIR: Final[pathlib.Path] = pathlib.Path(self._SOURCE_DIR).joinpath(self._IMAGES_DIR).joinpath(self._ICONS_DIR)

def validate(self) -> None:
json_icons: set[str] = self.get_json_icons()
for file in self._FULL_IMAGES_DIR.iterdir():
if file.name not in json_icons:
raise InvalidStructureException(f"{file.name} must be used, {file} isn't used!")

def get_json_icons(self) -> set[str]:
letters: list[str] = list(string.ascii_lowercase)
letters.insert(0, '_')
json_icons: set[str] = set()

for letter in letters:
icon_path: pathlib.Path = self._FULL_TECH_DIR.joinpath(f"{letter}.json")
with icon_path.open("r", encoding="utf8") as json_file:
technologies: dict = json.load(json_file)
for tech, data in technologies.items():
if value := data.get("icon"):
json_icons.add(value)
return json_icons


if __name__ == '__main__':
IconValidator().validate()
6 changes: 3 additions & 3 deletions .github/workflows/scripts/technology_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ def _validate(self, tech_name: str, data: Any) -> bool:
return True

def _validate_regex(self, tech_name: str, data: Any) -> bool:
if type(data) == str:
if type(data) is str:
try:
re.compile(data)
except re.error as e:
self._set_custom_error(InvalidRegexException(f"Unable to compile regex '{data}' for tech '{tech_name}', got error: {e.msg}"))
return False
elif type(data) == dict:
elif type(data) is dict:
for _, val in data.items():
valid: bool = self._validate_regex(tech_name, val)
if not valid:
return False
elif type(data) == list:
elif type(data) is list:
for item in data:
valid: bool = self._validate_regex(tech_name, item)
if not valid:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tech_matrix_prep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: get current technology matrix
id: getTechMatrix
Expand Down
42 changes: 30 additions & 12 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [ "3.11" ]
python-version: [ "3.12" ]
steps:
- name: checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -23,13 +23,13 @@ jobs:
needs: validate_structure
strategy:
matrix:
python-version: [ "3.11" ]
python-version: [ "3.12" ]
steps:
- name: checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -41,13 +41,13 @@ jobs:
needs: validate_structure
strategy:
matrix:
python-version: [ "3.11" ]
python-version: [ "3.12" ]
steps:
- name: checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -65,17 +65,35 @@ jobs:
max-parallel: 20
matrix:
file_name: ${{ fromJson(needs.tech_matrix_prep.outputs.technologies) }}
python-version: [ "3.11" ]
python-version: [ "3.12" ]
steps:
- name: checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: run tech validator
run: python3 .github/workflows/scripts/technology_validator.py
env:
TECH_FILE_NAME: ${{ matrix.file_name }}

validate_icon_path:
runs-on: ubuntu-22.04
needs: validate_techs
strategy:
matrix:
python-version: [ "3.12" ]
steps:
- name: checkout repository
uses: actions/checkout@v4

- name: set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: run category validator
run: python3 .github/workflows/scripts/icon_path_validator.py