Skip to content

Commit

Permalink
fix: Reintroduce sanitize-file-list, fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
FHeilmann committed Jan 4, 2024
1 parent 1adc307 commit 9cc075b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: File Checker
uses: docker://ghcr.io/vorondesign/voron_toolkit_docker:latest
env:
FILE_CHECKER_IGNORE_WARNINGS: false
FILE_CHECKER_IGNORE_WARNINGS: true
FILE_CHECKER_CHECK_LICENSE: true
FILE_CHECKER_CHECK_FILE_SIZE_MB: 2
with:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ name: VoronCI PR Test CI
run-name: "#${{github.event.number}} - ${{github.event.pull_request.title}}"
on:
pull_request:
types: [opened, reopened, synchronize]
types: [opened, reopened, synchronize, labeled]
jobs:
voron_ci:
if: ${{ contains( github.event.pull_request.labels.*.name, 'Ready for CI') }}
env:
VORON_TOOLKIT_OUTPUT_DIR: ${{ github.workspace }}/workflow_output
VORON_TOOLKIT_INPUT_DIR: ${{ github.workspace }}/tests/test_repository_root/printer_mods
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ generate-readme = "voron_toolkit.tools.readme_generator:main"
prepare-sparse-checkout = "voron_toolkit.voronuser_utils.sparse_checkout_helper:main"
set-pr-comment-labels = "voron_toolkit.voronuser_utils.pr_helper:main"
upload-images = "voron_toolkit.utils.imagekit_uploader:main"
sanitize-file-list = "voron_toolkit.utils.file_helper:FileHelper.sanitize_file_list"
8 changes: 4 additions & 4 deletions voron_toolkit/tools/file_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

class WhitespaceChecker:
def __init__(self: Self, args: configargparse.Namespace) -> None:
self.input_dir = args.input_dir
self.check_license = args.check_license
self.check_file_size = args.check_file_size_mb
self.input_dir: Path = Path(Path.cwd(), args.input_dir)
self.check_license: bool = args.check_license
self.check_file_size: int = args.check_file_size_mb
self.return_status: ExtendedResultEnum = ExtendedResultEnum.SUCCESS
self.input_file_list: list[Path] = []
self.result_items: defaultdict[ExtendedResultEnum, list[ItemResult]] = defaultdict(list)
Expand Down Expand Up @@ -57,7 +57,7 @@ def _check_file_size(self: Self) -> None:
for input_file in self.input_file_list:
relative_file_path: str = input_file.relative_to(self.input_dir).as_posix()
if input_file.stat().st_size > self.check_file_size * 1024 * 1024:
logger.error("File '{}' is larger than {} MB!", relative_file_path, self.check_file_size)
logger.warning("File '{}' is larger than {} MB!", relative_file_path, self.check_file_size)
self.result_items[ExtendedResultEnum.WARNING].append(
ItemResult(item=relative_file_path, extra_info=[f"This file is larger than {self.check_file_size} MB!"])
)
Expand Down
2 changes: 1 addition & 1 deletion voron_toolkit/tools/stl_corruption_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _check_stl(self: Self, stl_file_path: Path) -> ExtendedResultEnum:
self._write_fixed_stl_file(stl=stl, path=Path(stl_path_relative))
return ExtendedResultEnum.FAILURE
if stl.stats["type"] != StlType.BINARY:
logger.warning("STL '{}' is not a binary STL: {} !", stl_path_relative, StlType[stl.stats["type"]])
logger.warning("STL '{}' is not a binary STL. Detected Type: '{}' !", stl_path_relative, StlType(int(stl.stats["type"])).name)
self.result_items[ExtendedResultEnum.WARNING].append(
ItemResult(item=stl_file_path.name, extra_info=["STL is not a binary STL. Consider converting it to save space!"])
)
Expand Down
18 changes: 18 additions & 0 deletions voron_toolkit/utils/file_helper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import itertools
import os
from pathlib import Path
from typing import Self

from loguru import logger

from voron_toolkit.utils.github_action_helper import GithubActionHelper
from voron_toolkit.utils.logging import init_logging


class FileHelper:
@classmethod
Expand Down Expand Up @@ -38,3 +42,17 @@ def get_shallow_folders(cls: type[Self], input_dir: Path, max_depth: int, ignore
@classmethod
def get_all_folders(cls: type[Self], _: Path) -> list[Path]:
return []

@classmethod
def sanitize_file_list(cls: type[Self]) -> None:
init_logging(verbose=True)
logger.info("============ Sanitize File List ============")
file_list: list[str] = os.environ.get("FILE_LIST_SANITIZE_INPUT", "").splitlines()
if not file_list:
logger.warning("Input file list from env var 'FILE_LIST_SANITIZE_INPUT' is empty")
return
output_file_list: list[str] = [input_file.replace("[", "\\[").replace("]", "\\]") for input_file in file_list]
gh_helper: GithubActionHelper = GithubActionHelper()
gh_helper.set_output_multiline(output={"FILE_LIST_SANITIZE_OUTPUT": output_file_list})
gh_helper.write_outputs()
logger.success("Sanitize file list success!")
2 changes: 1 addition & 1 deletion voron_toolkit/voronuser_utils/sparse_checkout_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run(self: Self) -> None:
for pr_file in file_list:
file_path = Path(pr_file)
try:
file_path_relative: Path = file_path.relative_to(self.input_dir)
file_path_relative: Path = file_path.relative_to(self.input_dir.relative_to(Path.cwd()))
except ValueError:
logger.warning("File '{}' is not relative to input directory '{}'. Skipping.", file_path, self.input_dir)
continue
Expand Down

0 comments on commit 9cc075b

Please sign in to comment.