diff --git a/.github/workflows/XML_lint.yml b/.github/workflows/XML_lint.yml index fdb32f1..5bd0bdd 100644 --- a/.github/workflows/XML_lint.yml +++ b/.github/workflows/XML_lint.yml @@ -25,8 +25,18 @@ jobs: pip install lxml - name: XSD-Schema-Validierung - run: python Scripts/lint_validation.py + run: python Scripts/lint_validation.py | tee validation_output.txt + continue-on-error: true + + - name: GitHub-Anmerkungen für XSD-Validierung erstellen + run: cat validation_output.txt | python Scripts/annotations_validation.py + - name: Prüfe auf Validierungsfehler + run: | + if grep -q "Validierung fehlgeschlagen" validation_output.txt; then + exit 1 + fi + Verweise: runs-on: ubuntu-latest steps: @@ -44,3 +54,7 @@ jobs: - name: Verweise prüfen run: python Scripts/lint_verweise.py + + - name: GitHub-Anmerkungen für Referenzprüfung erstellen + if: failure() + run: python Scripts/annotations_references.py diff --git a/Scripts/annotations_references.py b/Scripts/annotations_references.py new file mode 100644 index 0000000..ab9a2c4 --- /dev/null +++ b/Scripts/annotations_references.py @@ -0,0 +1,17 @@ +import os + +def main(): + if not os.path.exists('reference_check_errors.txt'): + print("Keine Referenzprüfungs-Ergebnisse gefunden.") + return + + with open('reference_check_errors.txt', 'r') as f: + for line in f: + parts = line.strip().split(', Zeile ') + if len(parts) == 2: + file_path, rest = parts + line_number, message = rest.split(': ', 1) + print(f"::error file={file_path},line={line_number}::{message}") + +if __name__ == "__main__": + main() diff --git a/Scripts/annotations_validation.py b/Scripts/annotations_validation.py new file mode 100644 index 0000000..41f8156 --- /dev/null +++ b/Scripts/annotations_validation.py @@ -0,0 +1,34 @@ +import sys +import re + +def parse_error_message(line): + match = re.match(r"Validierungsfehler in (.*?):\s*", line) + if match: + return match.group(1), None, None, None + + match = re.match(r"\s*Zeile (\d+), Spalte (\d+): (.*)", line) + if match: + return None, int(match.group(1)), int(match.group(2)), match.group(3) + + match = re.match(r"XML-Syntaxfehler in (.*?):\s*", line) + if match: + return match.group(1), None, None, None + + match = re.match(r"\s*Zeile (\d+), Spalte (\d+): (.*)", line) + if match: + return None, int(match.group(1)), int(match.group(2)), match.group(3) + + return None, None, None, None + +def main(): + current_file = None + for line in sys.stdin: + file, line_num, column, message = parse_error_message(line.strip()) + + if file: + current_file = file + elif line_num and column and message and current_file: + print(f"::error file={current_file},line={line_num},col={column}::{message}") + +if __name__ == "__main__": + main() diff --git a/Scripts/lint_verweise.py b/Scripts/lint_verweise.py index 2181746..c382480 100644 --- a/Scripts/lint_verweise.py +++ b/Scripts/lint_verweise.py @@ -11,7 +11,7 @@ def parse_xml_file(filepath): tree = etree.parse(filepath, parser) return tree.getroot() except etree.ParseError as e: - print(f"Error parsing {filepath}: {e}") + print(f"Fehler beim Parsen von {filepath}: {e}") return None def get_all_ids(root, tag): @@ -26,7 +26,7 @@ def check_references(beitrag_root, reference_data, filepath): ref_id = ref.get('ref') if ref_id not in reference_data[ref_type]: line_number = ref.sourceline - errors.append(f"{relative_path}, Line {line_number}: INVALID REFERENCE ({ref_type}:{ref_id})") + errors.append(f"{relative_path}, Zeile {line_number}: UNGÜLTIGER VERWEIS ({ref_type}:{ref_id})") return errors def main(): @@ -51,12 +51,15 @@ def main(): all_errors.sort() if all_errors: - print("Linter found the following errors:") + print("Der Linter hat folgende Fehler gefunden:") for error in all_errors: print(error) - exit(1) # Exit with error code if there are any errors + with open('reference_check_errors.txt', 'w') as f: + for error in all_errors: + f.write(f"{error}\n") + exit(1) # Beenden mit Fehlercode, wenn Fehler gefunden wurden else: - print("No errors found.") + print("Keine Fehler gefunden.") if __name__ == "__main__": main() diff --git a/Scripts/process_linter_output.py b/Scripts/process_linter_output.py deleted file mode 100644 index 5dd0b67..0000000 --- a/Scripts/process_linter_output.py +++ /dev/null @@ -1,16 +0,0 @@ -import os - -def main(): - if not os.path.exists('linter_results.txt'): - print("No linter results found.") - return - - with open('linter_results.txt', 'r') as f: - for line in f: - parts = line.strip().split(':', 2) - if len(parts) == 3: - filename, line_number, error_message = parts - print(f"::error file={filename},line={line_number}::{error_message}") - -if __name__ == "__main__": - main()