mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-23 22:54:01 -06:00
Merge pull request #18824 from Ultimaker/CURA-10903-warn-for-deleted-files
Add detection for deleted files in printer linter
This commit is contained in:
commit
e37434abef
9 changed files with 56 additions and 6 deletions
|
@ -18,6 +18,7 @@ jobs:
|
|||
|
||||
- uses: technote-space/get-diff-action@v6
|
||||
with:
|
||||
DIFF_FILTER: AMRCD
|
||||
PATTERNS: |
|
||||
resources/+(extruders|definitions)/*.def.json
|
||||
resources/+(intent|quality|variants)/**/*.inst.cfg
|
||||
|
@ -41,6 +42,10 @@ jobs:
|
|||
if: env.GIT_DIFF && !env.MATCHED_FILES
|
||||
run: python printer-linter/src/terminal.py --diagnose --report printer-linter-result/fixes.yml ${{ env.GIT_DIFF_FILTERED }}
|
||||
|
||||
- name: Check Deleted Files(s)
|
||||
if: env.GIT_DIFF
|
||||
run: python printer-linter/src/terminal.py --deleted --report printer-linter-result/comment.md ${{ env.GIT_DIFF_FILTERED }}
|
||||
|
||||
- name: Save PR metadata
|
||||
run: |
|
||||
echo ${{ github.event.number }} > printer-linter-result/pr-id.txt
|
||||
|
|
12
.github/workflows/printer-linter-pr-post.yml
vendored
12
.github/workflows/printer-linter-pr-post.yml
vendored
|
@ -72,6 +72,18 @@ jobs:
|
|||
mkdir printer-linter-result
|
||||
unzip printer-linter-result.zip -d printer-linter-result
|
||||
|
||||
- name: Get Pull Request Number
|
||||
id: pr
|
||||
run: echo "::set-output name=pull_request_number::$(gh pr view --json number -q .number || echo "")"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Run PR Comments
|
||||
uses: peter-evans/create-or-update-comment@v4
|
||||
with:
|
||||
issue-number: ${{ steps.pr.outputs.pull_request_number }}
|
||||
body-path: 'printer-linter-result/comment.md'
|
||||
|
||||
- name: Run clang-tidy-pr-comments action
|
||||
uses: platisd/clang-tidy-pr-comments@bc0bb7da034a8317d54e7fe1e819159002f4cc40
|
||||
with:
|
||||
|
|
|
@ -3,6 +3,7 @@ checks:
|
|||
diagnostic-mesh-file-size: true
|
||||
diagnostic-definition-redundant-override: true
|
||||
diagnostic-resources-macos-app-directory-name: true
|
||||
diagnostic-resource-file-deleted: true
|
||||
diagnostic-material-temperature-defined: true
|
||||
fixes:
|
||||
diagnostic-definition-redundant-override: true
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[project]
|
||||
name = "printerlinter"
|
||||
description = "Cura UltiMaker printer linting tool"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
authors = [
|
||||
{ name = "UltiMaker", email = "cura@ultimaker.com" }
|
||||
]
|
||||
|
|
|
@ -32,3 +32,13 @@ class Diagnostic:
|
|||
},
|
||||
"Level": self.level
|
||||
}
|
||||
|
||||
class GitComment:
|
||||
def __init__(self, comment: str) -> None:
|
||||
"""
|
||||
@param comment: The comment text.
|
||||
"""
|
||||
self.comment = comment
|
||||
|
||||
def toDict(self) -> Dict[str, Any]:
|
||||
return self.comment
|
|
@ -11,7 +11,7 @@ from .linters.directory import Directory
|
|||
def getLinter(file: Path, settings: dict) -> Optional[List[Linter]]:
|
||||
""" Returns a Linter depending on the file format """
|
||||
if not file.exists():
|
||||
return None
|
||||
return [Directory(file, settings)]
|
||||
|
||||
if ".inst" in file.suffixes and ".cfg" in file.suffixes:
|
||||
return [Directory(file, settings), Profile(file, settings)]
|
||||
|
|
|
@ -90,7 +90,7 @@ class Definition(Linter):
|
|||
|
||||
yield Diagnostic(
|
||||
file=self._file,
|
||||
diagnostic_name="diagnostic-definition-redundant-override",
|
||||
diagnostic_name="diagnostic-material-temperature-defined",
|
||||
message=f"Overriding {key} as it belongs to material temperature catagory and shouldn't be placed in machine definitions",
|
||||
level="Warning",
|
||||
offset=found.span(0)[0],
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from pathlib import Path
|
||||
from typing import Iterator
|
||||
|
||||
from ..diagnostic import Diagnostic
|
||||
from ..diagnostic import Diagnostic, GitComment
|
||||
from .linter import Linter
|
||||
|
||||
|
||||
|
@ -11,9 +11,12 @@ class Directory(Linter):
|
|||
super().__init__(file, settings)
|
||||
|
||||
def check(self) -> Iterator[Diagnostic]:
|
||||
if self._settings["checks"].get("diagnostic-resources-macos-app-directory-name", False):
|
||||
if self._file.exists() and self._settings["checks"].get("diagnostic-resources-macos-app-directory-name", False):
|
||||
for check in self.checkForDotInDirName():
|
||||
yield check
|
||||
elif self._settings["checks"].get("diagnostic-resource-file-deleted", False):
|
||||
for check in self.checkFilesDeleted():
|
||||
yield check
|
||||
|
||||
yield
|
||||
|
||||
|
@ -29,3 +32,8 @@ class Directory(Linter):
|
|||
)
|
||||
yield
|
||||
|
||||
def checkFilesDeleted(self) -> Iterator[GitComment]:
|
||||
if not self._file.exists():
|
||||
""" Check if there is a file that is deleted, this causes upgrade scripts to not work properly """
|
||||
yield GitComment( f'File: **{self._file}** must not be deleted as it is not allowed. It will create issues upgrading Cura' )
|
||||
yield
|
|
@ -19,6 +19,7 @@ def main() -> None:
|
|||
parser.add_argument("--report", required=False, type=Path, help="Path where the diagnostic report should be stored")
|
||||
parser.add_argument("--format", action="store_true", help="Format the files")
|
||||
parser.add_argument("--diagnose", action="store_true", help="Diagnose the files")
|
||||
parser.add_argument("--deleted", action="store_true", help="Check for deleted files")
|
||||
parser.add_argument("--fix", action="store_true", help="Attempt to apply the suggested fixes on the files")
|
||||
parser.add_argument("Files", metavar="F", type=Path, nargs="+", help="Files or directories to format")
|
||||
|
||||
|
@ -41,12 +42,26 @@ def main() -> None:
|
|||
settings = yaml.load(f, yaml.FullLoader)
|
||||
|
||||
full_body_check = {"Diagnostics": []}
|
||||
comments_check = {"Error Files": []}
|
||||
|
||||
for file in files:
|
||||
if not path.exists(file):
|
||||
print(f"Can't find the file: {file}")
|
||||
return
|
||||
|
||||
if args.deleted:
|
||||
for file in args.Files:
|
||||
if file not in files:
|
||||
deletedFiles = diagnoseIssuesWithFile(file, settings)
|
||||
comments_check["Error Files"].extend([d.toDict() for d in deletedFiles])
|
||||
|
||||
results = yaml.dump(comments_check, default_flow_style=False, indent=4, width=240)
|
||||
|
||||
if report:
|
||||
report.write_text(results)
|
||||
else:
|
||||
print(results)
|
||||
|
||||
if to_fix or to_diagnose:
|
||||
for file in files:
|
||||
diagnostics = diagnoseIssuesWithFile(file, settings)
|
||||
|
@ -82,7 +97,6 @@ def diagnoseIssuesWithFile(file: Path, settings: dict) -> List[Diagnostic]:
|
|||
|
||||
return linter_results
|
||||
|
||||
|
||||
def applyFixesToFile(file, settings, full_body_check) -> None:
|
||||
if not file.exists():
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue