+ Github annotations

This commit is contained in:
Simon Martens
2024-07-18 11:26:06 +02:00
parent d85f38cee0
commit 416b72da2f
5 changed files with 74 additions and 22 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()