#!/usr/bin/env python3 """Report only allowlisted metadata from a private Rust command log.""" import hashlib from pathlib import Path import re import sys def report_compile(output): output = re.sub(r'\x1b\[[0-9;]*[A-Za-z]', '', output) stages = re.findall(r'^GP_WINDOWS_BUILD_STAGE=(core|gui|bundle|installer)\r?$', output, re.MULTILINE) if stages: print(f'::error::Windows build stage: {stages[-1]}.') locations = re.findall(r'(?:-->\s+|panicked at )([^\r\n]+?):([0-9]+):([0-9]+)', output) for path, line, column in sorted(set(locations)): path = path.replace('\\', '/') for prefix in ('/source/gpgui/', '/source/gp/'): if prefix in path: path = path.split(prefix, 1)[1] fingerprint = hashlib.sha256(path.encode()).hexdigest() print(f'::error::Rust source location fingerprint: {fingerprint} {line}:{column}') codes = sorted(set(re.findall(r'error\[E[0-9]{4}\]', output))) if codes: print(f'::error::Rust diagnostic codes: {" ".join(codes)}.') categories = [ ('No space left on device', 'insufficient disk space'), (r'signal: 9, SIGKILL|ld terminated with signal 9|Killed signal terminated program', 'compiler or linker killed by SIGKILL'), (r'undefined reference to|undefined symbol:', 'unresolved linker symbols'), ('proc macro panicked', 'procedural macro failed'), (r'Review runtime license notices for|Required runtime notice is missing', 'runtime library notices require review'), ('Unresolved Windows runtime dependency:', 'Windows runtime dependency is missing'), (r'out of memory|paging file is too small|os error 1455', 'memory exhausted'), ] for pattern, description in categories: if re.search(pattern, output): print(f'::error::Rust compilation: {description}.') def report_tests(output): names = set(re.findall(r'^test (.+?) \.\.\. FAILED\r?$', output, re.MULTILINE)) for fingerprint in sorted(hashlib.sha256(name.encode()).hexdigest() for name in names): print(f'::error::Rust test failure fingerprint: {fingerprint}') panics = re.findall( r"^thread '([^'\r\n]+)'(?: \([0-9]+\))? panicked at [^\r\n]+:([0-9]+):([0-9]+):\r?$", output, re.MULTILINE) locations = {(hashlib.sha256(name.encode()).hexdigest(), int(line), int(column)) for name, line, column in panics} for fingerprint, line, column in sorted(locations): print(f'::error::Rust test panic location: {fingerprint} {line}:{column}') overdue = set(re.findall(r'^test (.+?) has been running for over 60 seconds\r?$', output, re.MULTILINE)) for fingerprint in sorted(hashlib.sha256(name.encode()).hexdigest() for name in overdue): print(f'::error::Rust overdue test fingerprint: {fingerprint}') running = re.findall(r'^\s+Running (.+?) \(([^\r\n]+)\)\r?$', output, re.MULTILINE) if running: source, executable = running[-1] basename = re.sub(r'-[0-9a-f]{16}$', '', Path(executable).name) identity = f'{" ".join(source.split())} ({basename})' fingerprint = hashlib.sha256(identity.encode()).hexdigest() print(f'::error::Rust last running target fingerprint: {fingerprint}') def main(): if len(sys.argv) != 3 or sys.argv[1] not in ('compile', 'tests'): print('Usage: private-ci-diagnostics.py compile|tests LOGFILE', file=sys.stderr) return 2 try: output = Path(sys.argv[2]).read_text(errors='replace') except OSError: print('Private Rust diagnostic log is unavailable.', file=sys.stderr) return 1 if sys.argv[1] == 'compile': report_compile(output) else: report_tests(output) return 0 if __name__ == '__main__': sys.exit(main())