mirror of
https://github.com/Theodor-Springmann-Stiftung/KGPZ.git
synced 2025-12-16 03:15:30 +00:00
BUGFIX: Annotations
This commit is contained in:
12
.github/workflows/XML_lint.yml
vendored
12
.github/workflows/XML_lint.yml
vendored
@@ -25,17 +25,11 @@ jobs:
|
|||||||
pip install lxml
|
pip install lxml
|
||||||
|
|
||||||
- name: XSD-Schema-Validierung
|
- name: XSD-Schema-Validierung
|
||||||
run: python Scripts/lint_validation.py | tee validation_output.txt
|
run: python Scripts/lint_validation.py
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: GitHub-Anmerkungen für XSD-Validierung erstellen
|
- 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:
|
Verweise:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
@@ -1,34 +1,23 @@
|
|||||||
import sys
|
import os
|
||||||
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():
|
def main():
|
||||||
current_file = None
|
if not os.path.exists('schema_validation_errors.txt'):
|
||||||
for line in sys.stdin:
|
print("Keine Schema-Validierungsergebnisse gefunden.")
|
||||||
file, line_num, column, message = parse_error_message(line.strip())
|
return
|
||||||
|
|
||||||
if file:
|
current_file = None
|
||||||
current_file = file
|
with open('schema_validation_errors.txt', 'r') as f:
|
||||||
elif line_num and column and message and current_file:
|
for line in f:
|
||||||
print(f"::error file={current_file},line={line_num},col={column}::{message}")
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
|||||||
XML_DIR = os.path.join(REPO_ROOT, 'XML')
|
XML_DIR = os.path.join(REPO_ROOT, 'XML')
|
||||||
|
|
||||||
def validate_xml(xml_file):
|
def validate_xml(xml_file):
|
||||||
|
errors = []
|
||||||
try:
|
try:
|
||||||
parser = etree.XMLParser(remove_blank_text=True)
|
parser = etree.XMLParser(remove_blank_text=True)
|
||||||
tree = etree.parse(xml_file, parser)
|
tree = etree.parse(xml_file, parser)
|
||||||
@@ -21,38 +22,37 @@ def validate_xml(xml_file):
|
|||||||
schema.assertValid(tree)
|
schema.assertValid(tree)
|
||||||
print(f"Validation erfolgreich: {xml_file}")
|
print(f"Validation erfolgreich: {xml_file}")
|
||||||
else:
|
else:
|
||||||
print(f"Schema-Datei nicht gefunden: {xsd_path} für {xml_file}")
|
errors.append(f"Schema-Datei nicht gefunden: {xsd_path} für {xml_file}")
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
print(f"Keine Schema-Location gefunden in {xml_file}")
|
errors.append(f"Keine Schema-Location gefunden in {xml_file}")
|
||||||
return False
|
|
||||||
|
|
||||||
except etree.DocumentInvalid as e:
|
except etree.DocumentInvalid as e:
|
||||||
print(f"Validierungsfehler in {xml_file}:")
|
errors.append(f"Validierungsfehler in {xml_file}:")
|
||||||
for error in e.error_log:
|
for error in e.error_log:
|
||||||
print(f" Zeile {error.line}, Spalte {error.column}: {error.message}")
|
errors.append(f" Zeile {error.line}, Spalte {error.column}: {error.message}")
|
||||||
return False
|
|
||||||
except etree.XMLSyntaxError as e:
|
except etree.XMLSyntaxError as e:
|
||||||
print(f"XML-Syntaxfehler in {xml_file}:")
|
errors.append(f"XML-Syntaxfehler in {xml_file}:")
|
||||||
print(f" Zeile {e.lineno}, Spalte {e.offset}: {e.msg}")
|
errors.append(f" Zeile {e.lineno}, Spalte {e.offset}: {e.msg}")
|
||||||
return False
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Fehler bei der Verarbeitung von {xml_file}: {str(e)}")
|
errors.append(f"Fehler bei der Verarbeitung von {xml_file}: {str(e)}")
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
return errors
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
validation_failed = False
|
all_errors = []
|
||||||
for root, dirs, files in os.walk(XML_DIR):
|
for root, dirs, files in os.walk(XML_DIR):
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.endswith('.xml'):
|
if file.endswith('.xml'):
|
||||||
xml_file = os.path.join(root, file)
|
xml_file = os.path.join(root, file)
|
||||||
if not validate_xml(xml_file):
|
errors = validate_xml(xml_file)
|
||||||
validation_failed = True
|
all_errors.extend(errors)
|
||||||
|
|
||||||
if validation_failed:
|
if all_errors:
|
||||||
print("Validierung fehlgeschlagen. Bitte korrigieren Sie die oben genannten Fehler.")
|
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)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
print("Alle XML-Dateien wurden erfolgreich validiert.")
|
print("Alle XML-Dateien wurden erfolgreich validiert.")
|
||||||
|
|||||||
Reference in New Issue
Block a user