Update HACS
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from ..enums import RepositoryFile
|
||||
from ..repositories.base import HacsRepository
|
||||
from .base import ActionValidationBase, ValidationException
|
||||
|
||||
@@ -13,7 +12,10 @@ async def async_setup_validator(repository: HacsRepository) -> Validator:
|
||||
class Validator(ActionValidationBase):
|
||||
"""Validate the repository."""
|
||||
|
||||
more_info = "https://hacs.xyz/docs/publish/include#check-archived"
|
||||
allow_fork = False
|
||||
|
||||
async def async_validate(self):
|
||||
"""Validate the repository."""
|
||||
if RepositoryFile.HACS_JSON not in [x.filename for x in self.repository.tree]:
|
||||
raise ValidationException(f"The repository has no '{RepositoryFile.HACS_JSON}' file")
|
||||
if self.repository.data.archived:
|
||||
raise ValidationException("The repository is archived")
|
||||
@@ -1,9 +1,9 @@
|
||||
"""Base class for validation."""
|
||||
from __future__ import annotations
|
||||
|
||||
from time import monotonic
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ..enums import HacsCategory
|
||||
from ..exceptions import HacsException
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -17,7 +17,9 @@ class ValidationException(HacsException):
|
||||
class ActionValidationBase:
|
||||
"""Base class for action validation."""
|
||||
|
||||
category: str = "common"
|
||||
categories: list[HacsCategory] = []
|
||||
allow_fork: bool = True
|
||||
more_info: str = "https://hacs.xyz/docs/publish/action"
|
||||
|
||||
def __init__(self, repository: HacsRepository) -> None:
|
||||
self.hacs = repository.hacs
|
||||
@@ -34,18 +36,18 @@ class ActionValidationBase:
|
||||
|
||||
async def execute_validation(self, *_, **__) -> None:
|
||||
"""Execute the task defined in subclass."""
|
||||
self.hacs.log.info("<Validation %s> Starting validation", self.slug)
|
||||
|
||||
start_time = monotonic()
|
||||
self.failed = False
|
||||
|
||||
try:
|
||||
await self.async_validate()
|
||||
except ValidationException as exception:
|
||||
self.failed = True
|
||||
self.hacs.log.error("<Validation %s> failed: %s", self.slug, exception)
|
||||
self.hacs.log.error(
|
||||
"<Validation %s> failed: %s (More info: %s )",
|
||||
self.slug,
|
||||
exception,
|
||||
self.more_info,
|
||||
)
|
||||
|
||||
else:
|
||||
self.hacs.log.debug(
|
||||
"<Validation %s> took %.3f seconds to complete", self.slug, monotonic() - start_time
|
||||
)
|
||||
self.hacs.log.info("<Validation %s> completed", self.slug)
|
||||
|
||||
31
custom_components/hacs/validate/brands.py
Normal file
31
custom_components/hacs/validate/brands.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from custom_components.hacs.enums import HacsCategory
|
||||
|
||||
from ..repositories.base import HacsRepository
|
||||
from .base import ActionValidationBase, ValidationException
|
||||
|
||||
URL = "https://brands.home-assistant.io/domains.json"
|
||||
|
||||
|
||||
async def async_setup_validator(repository: HacsRepository) -> Validator:
|
||||
"""Set up this validator."""
|
||||
return Validator(repository=repository)
|
||||
|
||||
|
||||
class Validator(ActionValidationBase):
|
||||
"""Validate the repository."""
|
||||
|
||||
more_info = "https://hacs.xyz/docs/publish/include#check-brands"
|
||||
categories = [HacsCategory.INTEGRATION]
|
||||
|
||||
async def async_validate(self):
|
||||
"""Validate the repository."""
|
||||
|
||||
response = await self.hacs.session.get(URL)
|
||||
content = await response.json()
|
||||
|
||||
if self.repository.data.domain not in content["custom"]:
|
||||
raise ValidationException(
|
||||
"The repository has not been added as a custom domain to the brands repo"
|
||||
)
|
||||
@@ -12,6 +12,9 @@ async def async_setup_validator(repository: HacsRepository) -> Validator:
|
||||
class Validator(ActionValidationBase):
|
||||
"""Validate the repository."""
|
||||
|
||||
more_info = "https://hacs.xyz/docs/publish/include#check-repository"
|
||||
allow_fork = False
|
||||
|
||||
async def async_validate(self):
|
||||
"""Validate the repository."""
|
||||
if not self.repository.data.description:
|
||||
30
custom_components/hacs/validate/hacsjson.py
Normal file
30
custom_components/hacs/validate/hacsjson.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from voluptuous.error import Invalid
|
||||
|
||||
from ..enums import RepositoryFile
|
||||
from ..repositories.base import HacsRepository
|
||||
from ..utils.validate import HACS_MANIFEST_JSON_SCHEMA
|
||||
from .base import ActionValidationBase, ValidationException
|
||||
|
||||
|
||||
async def async_setup_validator(repository: HacsRepository) -> Validator:
|
||||
"""Set up this validator."""
|
||||
return Validator(repository=repository)
|
||||
|
||||
|
||||
class Validator(ActionValidationBase):
|
||||
"""Validate the repository."""
|
||||
|
||||
more_info = "https://hacs.xyz/docs/publish/include#check-hacs-manifest"
|
||||
|
||||
async def async_validate(self):
|
||||
"""Validate the repository."""
|
||||
if RepositoryFile.HACS_JSON not in [x.filename for x in self.repository.tree]:
|
||||
raise ValidationException(f"The repository has no '{RepositoryFile.HACS_JSON}' file")
|
||||
|
||||
content = await self.repository.async_get_hacs_json(self.repository.ref)
|
||||
try:
|
||||
HACS_MANIFEST_JSON_SCHEMA(content)
|
||||
except Invalid as exception:
|
||||
raise ValidationException(exception) from exception
|
||||
29
custom_components/hacs/validate/images.py
Normal file
29
custom_components/hacs/validate/images.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from ..enums import HacsCategory
|
||||
from ..repositories.base import HacsRepository
|
||||
from .base import ActionValidationBase, ValidationException
|
||||
|
||||
IGNORED = ["-shield", "img.shields.io", "buymeacoffee.com"]
|
||||
|
||||
|
||||
async def async_setup_validator(repository: HacsRepository) -> Validator:
|
||||
"""Set up this validator."""
|
||||
return Validator(repository=repository)
|
||||
|
||||
|
||||
class Validator(ActionValidationBase):
|
||||
"""Validate the repository."""
|
||||
|
||||
categories = [HacsCategory.PLUGIN, HacsCategory.THEME]
|
||||
more_info = "https://hacs.xyz/docs/publish/include#check-images"
|
||||
|
||||
async def async_validate(self):
|
||||
"""Validate the repository."""
|
||||
info = await self.repository.async_get_info_file_contents()
|
||||
for line in info.split("\n"):
|
||||
if "<img" in line or "![" in line:
|
||||
if [ignore for ignore in IGNORED if ignore in line]:
|
||||
continue
|
||||
return
|
||||
raise ValidationException("The repository does not have issues enabled")
|
||||
@@ -12,6 +12,8 @@ async def async_setup_validator(repository: HacsRepository) -> Validator:
|
||||
class Validator(ActionValidationBase):
|
||||
"""Validate the repository."""
|
||||
|
||||
more_info = "https://hacs.xyz/docs/publish/include#check-info"
|
||||
|
||||
async def async_validate(self):
|
||||
"""Validate the repository."""
|
||||
filenames = [x.filename.lower() for x in self.repository.tree]
|
||||
@@ -1,7 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from ..enums import RepositoryFile
|
||||
from voluptuous.error import Invalid
|
||||
|
||||
from ..enums import HacsCategory, RepositoryFile
|
||||
from ..repositories.base import HacsRepository
|
||||
from ..repositories.integration import HacsIntegrationRepository
|
||||
from ..utils.validate import INTEGRATION_MANIFEST_JSON_SCHEMA
|
||||
from .base import ActionValidationBase, ValidationException
|
||||
|
||||
|
||||
@@ -13,7 +17,9 @@ async def async_setup_validator(repository: HacsRepository) -> Validator:
|
||||
class Validator(ActionValidationBase):
|
||||
"""Validate the repository."""
|
||||
|
||||
category = "integration"
|
||||
repository: HacsIntegrationRepository
|
||||
more_info = "https://hacs.xyz/docs/publish/include#check-manifest"
|
||||
categories = [HacsCategory.INTEGRATION]
|
||||
|
||||
async def async_validate(self):
|
||||
"""Validate the repository."""
|
||||
@@ -21,3 +27,9 @@ class Validator(ActionValidationBase):
|
||||
raise ValidationException(
|
||||
f"The repository has no '{RepositoryFile.MAINIFEST_JSON}' file"
|
||||
)
|
||||
|
||||
content = await self.repository.async_get_integration_manifest(self.repository.ref)
|
||||
try:
|
||||
INTEGRATION_MANIFEST_JSON_SCHEMA(content)
|
||||
except Invalid as exception:
|
||||
raise ValidationException(exception) from exception
|
||||
|
||||
21
custom_components/hacs/validate/issues.py
Normal file
21
custom_components/hacs/validate/issues.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from ..repositories.base import HacsRepository
|
||||
from .base import ActionValidationBase, ValidationException
|
||||
|
||||
|
||||
async def async_setup_validator(repository: HacsRepository) -> Validator:
|
||||
"""Set up this validator."""
|
||||
return Validator(repository=repository)
|
||||
|
||||
|
||||
class Validator(ActionValidationBase):
|
||||
"""Validate the repository."""
|
||||
|
||||
more_info = "https://hacs.xyz/docs/publish/include#check-repository"
|
||||
allow_fork = False
|
||||
|
||||
async def async_validate(self):
|
||||
"""Validate the repository."""
|
||||
if not self.repository.data.has_issues:
|
||||
raise ValidationException("The repository does not have issues enabled")
|
||||
@@ -3,13 +3,14 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from importlib import import_module
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from custom_components.hacs.repositories.base import HacsRepository
|
||||
|
||||
from ..enums import HacsGitHubRepo
|
||||
from ..repositories.base import HacsRepository
|
||||
from .base import ActionValidationBase
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -26,7 +27,7 @@ class ValidationManager:
|
||||
self._validatiors: dict[str, ActionValidationBase] = {}
|
||||
|
||||
@property
|
||||
def validatiors(self) -> dict[str, ActionValidationBase]:
|
||||
def validatiors(self) -> list[ActionValidationBase]:
|
||||
"""Return all list of all tasks."""
|
||||
return list(self._validatiors.values())
|
||||
|
||||
@@ -46,7 +47,6 @@ class ValidationManager:
|
||||
self._validatiors[task.slug] = task
|
||||
|
||||
await asyncio.gather(*[_load_module(task) for task in validator_modules])
|
||||
self.hacs.log.debug("Loaded %s validators for %s", len(self.validatiors), repository)
|
||||
|
||||
async def async_run_repository_checks(self, repository: HacsRepository) -> None:
|
||||
"""Run all validators for a repository."""
|
||||
@@ -55,21 +55,28 @@ class ValidationManager:
|
||||
|
||||
await self.async_load(repository)
|
||||
|
||||
await asyncio.gather(
|
||||
*[
|
||||
validator.execute_validation()
|
||||
for validator in self.validatiors or []
|
||||
if (
|
||||
validator.category == "common" or validator.category == repository.data.category
|
||||
)
|
||||
]
|
||||
is_pull_from_fork = (
|
||||
not os.getenv("INPUT_REPOSITORY")
|
||||
and os.getenv("GITHUB_REPOSITORY") != repository.data.full_name
|
||||
)
|
||||
|
||||
total = len(self.validatiors)
|
||||
failed = len([x for x in self.validatiors if x.failed])
|
||||
validatiors = [
|
||||
validator
|
||||
for validator in self.validatiors or []
|
||||
if (
|
||||
(not validator.categories or repository.data.category in validator.categories)
|
||||
and validator.slug not in os.getenv("INPUT_IGNORE", "").split(" ")
|
||||
and (not is_pull_from_fork or validator.allow_fork)
|
||||
)
|
||||
]
|
||||
|
||||
await asyncio.gather(*[validator.execute_validation() for validator in validatiors])
|
||||
|
||||
total = len(validatiors)
|
||||
failed = len([x for x in validatiors if x.failed])
|
||||
|
||||
if failed != 0:
|
||||
repository.logger.error("%s %s/%s checks failed", repository.string, failed, total)
|
||||
exit(1)
|
||||
else:
|
||||
repository.logger.debug("%s All (%s) checks passed", repository.string, total)
|
||||
repository.logger.info("%s All (%s) checks passed", repository.string, total)
|
||||
|
||||
@@ -12,7 +12,10 @@ async def async_setup_validator(repository: HacsRepository) -> Validator:
|
||||
class Validator(ActionValidationBase):
|
||||
"""Validate the repository."""
|
||||
|
||||
more_info = "https://hacs.xyz/docs/publish/include#check-repository"
|
||||
allow_fork = False
|
||||
|
||||
async def async_validate(self):
|
||||
"""Validate the repository."""
|
||||
if not self.repository.data.topics:
|
||||
raise ValidationException("The repository has no topics")
|
||||
raise ValidationException("The repository has no valid topics")
|
||||
Reference in New Issue
Block a user