BUGFIX: Annotations

This commit is contained in:
Simon Martens
2024-07-18 11:36:00 +02:00
parent ad10f37240
commit 12c9e45917
3 changed files with 38 additions and 55 deletions

View File

@@ -25,18 +25,12 @@ jobs:
pip install lxml
- name: XSD-Schema-Validierung
run: python Scripts/lint_validation.py | tee validation_output.txt
continue-on-error: true
run: python Scripts/lint_validation.py
- name: GitHub-Anmerkungen für XSD-Validierung erstellen
run: cat validation_output.txt | python Scripts/annotations_validation.py
if: failure()
run: 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:

View File

@@ -1,34 +1,23 @@
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
import os
def main():
if not os.path.exists('schema_validation_errors.txt'):
print("Keine Schema-Validierungsergebnisse gefunden.")
return
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}")
with open('schema_validation_errors.txt', 'r') as f:
for line in f:
if line.startswith("Validierungsfehler in ") or line.startswith("XML-Syntaxfehler in "):
current_file = line.split("in ", 1)[1].strip()[:-1]
elif line.strip().startswith("Zeile"):
parts = line.strip().split(", ")
line_num = parts[0].split(" ")[1]
col_num = parts[1].split(" ")[1]
message = ": ".join(parts[2:])
print(f"::error file={current_file},line={line_num},col={col_num}::{message}")
else:
print(f"::error file={current_file}::{line.strip()}")
if __name__ == "__main__":
main()

View File

@@ -5,6 +5,7 @@ REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
XML_DIR = os.path.join(REPO_ROOT, 'XML')
def validate_xml(xml_file):
errors = []
try:
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(xml_file, parser)
@@ -21,38 +22,37 @@ def validate_xml(xml_file):
schema.assertValid(tree)
print(f"Validation erfolgreich: {xml_file}")
else:
print(f"Schema-Datei nicht gefunden: {xsd_path} für {xml_file}")
return False
errors.append(f"Schema-Datei nicht gefunden: {xsd_path} für {xml_file}")
else:
print(f"Keine Schema-Location gefunden in {xml_file}")
return False
errors.append(f"Keine Schema-Location gefunden in {xml_file}")
except etree.DocumentInvalid as e:
print(f"Validierungsfehler in {xml_file}:")
errors.append(f"Validierungsfehler in {xml_file}:")
for error in e.error_log:
print(f" Zeile {error.line}, Spalte {error.column}: {error.message}")
return False
errors.append(f" Zeile {error.line}, Spalte {error.column}: {error.message}")
except etree.XMLSyntaxError as e:
print(f"XML-Syntaxfehler in {xml_file}:")
print(f" Zeile {e.lineno}, Spalte {e.offset}: {e.msg}")
return False
errors.append(f"XML-Syntaxfehler in {xml_file}:")
errors.append(f" Zeile {e.lineno}, Spalte {e.offset}: {e.msg}")
except Exception as e:
print(f"Fehler bei der Verarbeitung von {xml_file}: {str(e)}")
return False
errors.append(f"Fehler bei der Verarbeitung von {xml_file}: {str(e)}")
return True
return errors
def main():
validation_failed = False
all_errors = []
for root, dirs, files in os.walk(XML_DIR):
for file in files:
if file.endswith('.xml'):
xml_file = os.path.join(root, file)
if not validate_xml(xml_file):
validation_failed = True
errors = validate_xml(xml_file)
all_errors.extend(errors)
if validation_failed:
print("Validierung fehlgeschlagen. Bitte korrigieren Sie die oben genannten Fehler.")
if all_errors:
print("Validierung fehlgeschlagen. Bitte korrigieren Sie die folgenden Fehler:")
with open('schema_validation_errors.txt', 'w') as f:
for error in all_errors:
print(error)
f.write(f"{error}\n")
exit(1)
else:
print("Alle XML-Dateien wurden erfolgreich validiert.")