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

Move compliance checks to SDK #128

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3081d7d
Move compliance checks to SDK
lvoloshyn-sekoia Aug 5, 2024
fd90341
Fix default path
lvoloshyn-sekoia Aug 5, 2024
f909125
Fixes and improvements
lvoloshyn-sekoia Aug 5, 2024
83dd0cf
Fixes and improvements
lvoloshyn-sekoia Aug 5, 2024
1da1f31
Fix linting
lvoloshyn-sekoia Aug 5, 2024
6f4e736
Fixes for mypy
lvoloshyn-sekoia Aug 5, 2024
31f6019
Fixes for mypy
lvoloshyn-sekoia Aug 5, 2024
f8e2e4e
Fix tests
lvoloshyn-sekoia Aug 5, 2024
a94ea93
Enhance test fixtures
lvoloshyn-sekoia Aug 5, 2024
f36a820
Merge branch 'main' into lv/move_compliance_check_to_sdk
lvoloshyn-sekoia Aug 5, 2024
3a7e674
Improve linting
lvoloshyn-sekoia Aug 5, 2024
dcff650
Merge remote-tracking branch 'origin/lv/move_compliance_check_to_sdk'…
lvoloshyn-sekoia Aug 5, 2024
3686420
Fix test
lvoloshyn-sekoia Aug 5, 2024
794317d
Fix test
lvoloshyn-sekoia Aug 5, 2024
bb3dd89
Omit cov for action tester
lvoloshyn-sekoia Aug 6, 2024
428167f
Move compliance deps in a separate group
lvoloshyn-sekoia Sep 10, 2024
0052d25
Merge branch 'main' into lv/move_compliance_check_to_sdk
lvoloshyn-sekoia Sep 10, 2024
2ea3823
Update deps
lvoloshyn-sekoia Sep 10, 2024
9675651
Exclude compliance checks from coverage
lvoloshyn-sekoia Sep 10, 2024
2e84881
Merge branch 'main' into lv/move_compliance_check_to_sdk
lvoloshyn-sekoia Sep 10, 2024
7f06dbc
Update poetry.lock
lvoloshyn-sekoia Sep 10, 2024
8e1fef2
Merge branch 'main' into lv/move_compliance_check_to_sdk
lvoloshyn-sekoia Sep 20, 2024
46c87b9
Update poetry.lock
lvoloshyn-sekoia Sep 20, 2024
4b9a75d
Merge branch 'main' into lv/move_compliance_check_to_sdk
lvoloshyn-sekoia Oct 7, 2024
d5ef2e8
Update deps
lvoloshyn-sekoia Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes for mypy
lvoloshyn-sekoia committed Aug 5, 2024
commit 6f4e736c03ddcd33804e4302576217b88098e669
22 changes: 11 additions & 11 deletions sekoia_automation/scripts/compliance/validators/__init__.py
Original file line number Diff line number Diff line change
@@ -15,15 +15,15 @@
MODULES_PATH = Path(__file__).parent.parent.parent.parent

__all__ = (
ActionsJSONValidator,
ChangelogValidator,
ConnectorsJSONValidator,
DependenciesValidator,
DockerfileValidator,
LogoValidator,
MainPYValidator,
ManifestValidator,
ModuleValidator,
TestsValidator,
TriggersJSONValidator,
"ActionsJSONValidator",
"ChangelogValidator",
"ConnectorsJSONValidator",
"DependenciesValidator",
"DockerfileValidator",
"LogoValidator",
"MainPYValidator",
"ManifestValidator",
"ModuleValidator",
"TestsValidator",
"TriggersJSONValidator",
)
14 changes: 3 additions & 11 deletions sekoia_automation/scripts/compliance/validators/changelog.py
Original file line number Diff line number Diff line change
@@ -43,15 +43,10 @@ def __init__(
raw: str = "",
title: str = "",
body: str = "",
line_number: int | None = None,
):
self.__raw = raw
self.__title = title
self.__body = body
self.__line_number = line_number

def line_number(self) -> int:
return self.__line_number

def title(self) -> str:
return self.__title
@@ -203,6 +198,8 @@ def get_version_from_element(self, version: ChangeLogElement) -> str:
elif "unreleased" in title.lower():
return "Unreleased"

return ""

def validate_version_semver(
self, version: ChangeLogElement, path: Path, result: CheckResult
):
@@ -268,7 +265,6 @@ def validate_version_sections(
text=version.body(),
start_depth=3,
end_depth=3,
line_offset=version.line_number(),
)

sections = {}
@@ -317,10 +313,6 @@ def parse_changelog_header(
else:
body = text[end:]

elements.append(
ChangeLogElement(
raw=raw, title=title, body=body, line_number=line_number
)
)
elements.append(ChangeLogElement(raw=raw, title=title, body=body))

return elements
16 changes: 10 additions & 6 deletions sekoia_automation/scripts/compliance/validators/helpers.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
from PIL import Image


def transparent_background(image: Image, fuzz: int) -> Image:
def transparent_background(image: Image.Image, fuzz: int) -> Image.Image:
"""
Replace white background into transparent background
"""
@@ -28,8 +28,8 @@ def transparent_background(image: Image, fuzz: int) -> Image:


def resize_canvas(
image: Image, canvas_width: int = 500, canvas_height: int = 500
) -> Image:
image: Image.Image, canvas_width: int = 500, canvas_height: int = 500
) -> Image.Image:
"""
Resize the canvas of the image
"""
@@ -48,7 +48,7 @@ def resize_canvas(
return new_image


def square_canvas(image: Image) -> Image:
def square_canvas(image: Image.Image) -> Image.Image:
"""
Square the canvas of the image
"""
@@ -57,7 +57,9 @@ def square_canvas(image: Image) -> Image:
return resize_canvas(image, max_size, max_size)


def lighten_image(original: Image, size: int, max_iteration: int = 100) -> Image:
def lighten_image(
original: Image.Image, size: int, max_iteration: int = 100
) -> Image.Image:
"""
Downsize the image until its weight is lesser than the supplied parameter
"""
@@ -78,7 +80,9 @@ def lighten_image(original: Image, size: int, max_iteration: int = 100) -> Image
raise Exception("Unable to resize the image in the maximum iteration")


def merge(template: Image, embedded: Image, box: tuple[int, int, int, int]) -> Image:
def merge(
template: Image.Image, embedded: Image.Image, box: tuple[int, int, int, int]
) -> Image.Image:
"""
Put an image in a template
"""
4 changes: 2 additions & 2 deletions sekoia_automation/scripts/compliance/validators/logo.py
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ def check_logo_image(result: CheckResult) -> None:
result.options["logo_path"] = image_path


def has_transparency(img: Image) -> bool:
def has_transparency(img: Image.Image) -> bool:
if img.info.get("transparency", None) is not None:
return True

@@ -93,7 +93,7 @@ def has_transparency(img: Image) -> bool:

elif img.mode == "RGBA":
extrema = img.getextrema()
if extrema[3][0] < 255:
if extrema[3][0] < 255: # type: ignore
return True

return False
6 changes: 4 additions & 2 deletions sekoia_automation/scripts/compliance/validators/main.py
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ def validate(cls, result: CheckResult) -> None:
if len(used_docker_params) != len(unique_used_docker_params):
tmp = set()
duplicated_docker_params = [
x for x in used_docker_params if x in tmp or tmp.add(x)
x for x in used_docker_params if x in tmp or tmp.add(x) # type: ignore
]

for item in duplicated_docker_params:
@@ -64,7 +64,9 @@ def validate(cls, result: CheckResult) -> None:
)
)

docker_params_in_jsons = set(result.options.get("docker_parameters").values())
docker_params_in_jsons = set(
result.options.get("docker_parameters", {}).values()
)
absent_in_main_py = docker_params_in_jsons - unique_used_docker_params
absent_in_jsons = unique_used_docker_params - docker_params_in_jsons