From 327d91602469bef3421bd78113b0f8246eb8d6bb Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Sun, 25 Oct 2026 19:20:46 +0100 Subject: [PATCH] CI: Reorganize the warnings report for readability - Lead with a one-line verdict for the files changed by the PR, and flag builds whose log is missing. - List warnings in changed files grouped by file, with links to the source lines at the PR head commit and the builds that reported them ("all compilers" when every compiler build did). - Separate compiler warnings from clang-tidy findings; clang-tidy's re-reported compiler diagnostics are left to the compiler builds. - Move whole-project breakdowns (by type, by file) into collapsed sections, and link the workflow run in the footer. Co-Authored-By: Claude Opus 5.5 --- .github/actions/save-build-log/action.yml | 8 +- .github/scripts/warnings_report.py | 280 ++++++++++++++++------ .github/workflows/ci.yml | 7 +- .github/workflows/clang-tidy.yml | 1 + 4 files changed, 227 insertions(+), 69 deletions(-) diff --git a/.github/actions/save-build-log/action.yml b/.github/actions/save-build-log/action.yml index 4a113e6..a70c34c 100644 --- a/.github/actions/save-build-log/action.yml +++ b/.github/actions/save-build-log/action.yml @@ -1,7 +1,7 @@ name: Save build log description: > Upload build.log (from the workspace root) as a "build-log-" artifact, together with - the platform title and the workspace path, for the warnings report in ci.yml. + the platform title, category and workspace path, for the warnings report in ci.yml. inputs: id: @@ -10,6 +10,10 @@ inputs: title: description: Platform / compiler name shown in the report required: true + category: + description: '"compiler" or "clang-tidy"' + required: false + default: compiler runs: using: composite @@ -18,10 +22,12 @@ runs: shell: bash env: TITLE: ${{ inputs.title }} + CATEGORY: ${{ inputs.category }} run: | mkdir -p build-log-artifact if [ -f build.log ]; then mv build.log build-log-artifact/; fi printf '%s\n' "$TITLE" > build-log-artifact/title.txt + printf '%s\n' "$CATEGORY" > build-log-artifact/category.txt # Path as printed by the compiler (D:/a/... on Windows). ws="$GITHUB_WORKSPACE" if command -v cygpath > /dev/null; then ws=$(cygpath -m "$ws"); fi diff --git a/.github/scripts/warnings_report.py b/.github/scripts/warnings_report.py index e0079cb..fb38bf0 100644 --- a/.github/scripts/warnings_report.py +++ b/.github/scripts/warnings_report.py @@ -11,15 +11,17 @@ Generate a Markdown report of compiler / clang-tidy warnings from CI build logs. Each build log directory (as saved by .github/actions/save-build-log) contains: build.log - Build output. title.txt - Platform / compiler name shown in the report. + category.txt - "compiler" or "clang-tidy". workspace.txt - Source root path, as printed by the compiler on that platform. Warnings are deduplicated (the same header warning is printed once per translation unit, and the same warning may be reported by several platforms), restricted to project files (dependencies, system headers and generated files -are skipped), and split into "in changed files" and "total". +are skipped), and split into "in files changed by the PR" and "total". Usage: - warnings_report.py --logs-dir DIR [--changed-files FILE] > report.md + warnings_report.py --logs-dir DIR [--changed-files FILE] + [--repo OWNER/NAME --sha SHA] [--run-url URL] > report.md """ import argparse @@ -37,15 +39,28 @@ WARNING_RE = re.compile( # Repository paths whose warnings are not ours. EXCLUDED_PREFIXES = ("dependencies/", "build/") -# Maximum number of warnings listed, to keep the comment within GitHub's size limit. -MAX_LISTED = 150 +# Maximum number of warnings listed for changed files. +MAX_LISTED = 200 + +# GitHub's comment limit is 65536 characters. +MAX_REPORT_SIZE = 60000 MARKER = "" +COMPILER = "compiler" +CLANG_TIDY = "clang-tidy" + Warning = collections.namedtuple("Warning", "file line col msg flag") +class BuildLog: + def __init__(self, title, category, warnings): + self.title = title + self.category = category + self.warnings = warnings # set of Warning, or None if the log is missing + + def normalize_path(path): path = path.replace("\\", "/") if re.match(r"^[A-Za-z]:/", path): @@ -65,18 +80,18 @@ def to_repo_path(file, workspace): return file +def read_text(path, default=""): + return path.read_text(encoding="utf-8").strip() if path.exists() else default + + def parse_log(log_dir): - """Return (title, set of warnings), or (title, None) if the log is missing.""" - title = log_dir.name.removeprefix("build-log-") - title_file = log_dir / "title.txt" - if title_file.exists(): - title = title_file.read_text(encoding="utf-8").strip() or title - workspace_file = log_dir / "workspace.txt" - workspace = normalize_path(workspace_file.read_text(encoding="utf-8").strip()) if workspace_file.exists() else "" + title = read_text(log_dir / "title.txt") or log_dir.name.removeprefix("build-log-") + category = read_text(log_dir / "category.txt", COMPILER) + workspace = normalize_path(read_text(log_dir / "workspace.txt")) log_file = log_dir / "build.log" if not log_file.exists(): - return title, None + return BuildLog(title, category, None) found = set() for raw in log_file.read_text(encoding="utf-8", errors="replace").splitlines(): @@ -87,18 +102,197 @@ def parse_log(log_dir): if file is None or file.startswith(EXCLUDED_PREFIXES): continue flag = (m.group("flag") or "").replace(",-warnings-as-errors", "") + if category == CLANG_TIDY and (flag.startswith("-W") or flag.startswith("clang-diagnostic-")): + continue # compiler diagnostics; these are reported by the compiler builds found.add(Warning(file, int(m.group("line")), int(m.group("col")), m.group("msg").strip(), flag)) - return title, found + return BuildLog(title, category, found) def escape(text): - return text.replace("|", "\\|").replace("`", "'").replace("<", "<") + return text.replace("|", "\\|").replace("`", "'").replace("<", "<").replace(">", ">") + + +def plural(n, word): + return f"{n} {word}" if n == 1 else f"{n} {word}s" + + +class Report: + def __init__(self, logs, changed, repo, sha, run_url): + self.logs = logs + self.changed = changed + self.repo = repo + self.sha = sha + self.run_url = run_url + + # Unique warnings per category, with the build titles that reported each. + self.reported_by = {COMPILER: collections.defaultdict(list), CLANG_TIDY: collections.defaultdict(list)} + for log in logs: + for w in log.warnings or (): + self.reported_by[log.category][w].append(log.title) + + def logs_of(self, category): + return [log for log in self.logs if log.category == category] + + def unique(self, category): + return sorted(self.reported_by[category]) + + def in_changed(self, warnings): + return [w for w in warnings if w.file in self.changed] if self.changed is not None else [] + + def link(self, w): + text = f"{w.line}:{w.col}" + if self.repo and self.sha: + return f"[{text}](https://github.com/{self.repo}/blob/{self.sha}/{w.file}#L{w.line})" + return text + + def reporters(self, category, w): + titles = self.reported_by[category][w] + available = [log.title for log in self.logs_of(category) if log.warnings is not None] + if category == COMPILER and len(available) > 1 and len(titles) == len(available): + return "all compilers" + return ", ".join(titles) + + def headline(self): + lines = [] + compiler = self.unique(COMPILER) + tidy = self.unique(CLANG_TIDY) + if self.changed is not None: + c, t = len(self.in_changed(compiler)), len(self.in_changed(tidy)) + if c == 0 and t == 0: + lines.append("### ✅ No warnings in files changed by this PR") + else: + parts = [] + if c: + parts.append(plural(c, 'compiler warning')) + if t: + parts.append(plural(t, 'clang-tidy warning')) + lines.append(f"### ⚠️ {' and '.join(parts)} in files changed by this PR") + else: + lines.append("### Warnings report") + lines.append("") + lines.append(f"Whole project: {plural(len(compiler), 'compiler warning')}, " + f"{plural(len(tidy), 'clang-tidy warning')} (unique).") + + missing = [log.title for log in self.logs if log.warnings is None] + if missing: + lines += ["", f"> [!WARNING]\n> No build log from: {escape(', '.join(missing))} " + "(the build failed early or was cancelled), so their warnings are not included."] + return lines + + def platform_table(self, category, total_label): + logs = self.logs_of(category) + if not logs: + return [] + with_changed = self.changed is not None + header = ["| Build | In changed files | Total |", "|---|---:|---:|"] if with_changed \ + else ["| Build | Total |", "|---|---:|"] + rows = [] + for log in logs: + if log.warnings is None: + cells = ["–", "❌ no log"] if with_changed else ["❌ no log"] + else: + cells = ([str(len(self.in_changed(log.warnings)))] if with_changed else []) + [str(len(log.warnings))] + rows.append(f"| {escape(log.title)} | " + " | ".join(cells) + " |") + if len(logs) > 1: + unique = self.unique(category) + cells = ([f"**{len(self.in_changed(unique))}**"] if with_changed else []) + [f"**{len(unique)}**"] + rows.append(f"| **{total_label}** | " + " | ".join(cells) + " |") + return header + rows + [""] + + def changed_files_section(self): + items = [(COMPILER, w) for w in self.in_changed(self.unique(COMPILER))] + items += [(CLANG_TIDY, w) for w in self.in_changed(self.unique(CLANG_TIDY))] + if not items: + return [] + + by_file = collections.defaultdict(list) + for category, w in items: + by_file[w.file].append((category, w)) + + out = ["#### Warnings in changed files", ""] + listed = 0 + for file in sorted(by_file): + entries = sorted(by_file[file], key=lambda e: (e[1].line, e[1].col, e[0])) + out += [f"
{escape(file)} ({len(entries)})", "", + "| Line | Warning | Type | Reported by |", "|---|---|---|---|"] + for category, w in entries: + if listed >= MAX_LISTED: + break + flag = f"`{w.flag}`" if w.flag else "" + out.append(f"| {self.link(w)} | {escape(w.msg)} | {flag} | {escape(self.reporters(category, w))} |") + listed += 1 + out += ["", "
", ""] + if listed >= MAX_LISTED: + out += [f"_Only the first {MAX_LISTED} warnings are listed; see the workflow run for the full logs._", ""] + break + return out + + def breakdown_section(self): + compiler = self.unique(COMPILER) + tidy = self.unique(CLANG_TIDY) + if not compiler and not tidy: + return [] + out = [] + + by_type = collections.Counter() + for category, warnings in ((COMPILER, compiler), (CLANG_TIDY, tidy)): + for w in warnings: + by_type[(category, w.flag or "(no flag)")] += 1 + out += ["
Whole project: warnings by type", "", + "| Warning | Source | Count |", "|---|---|---:|"] + out += [f"| `{flag}` | {category} | {n} |" for (category, flag), n in by_type.most_common(30)] + out += ["", "
", ""] + + by_file = collections.defaultdict(lambda: [0, 0]) + for w in compiler: + by_file[w.file][0] += 1 + for w in tidy: + by_file[w.file][1] += 1 + top = sorted(by_file.items(), key=lambda kv: (-sum(kv[1]), kv[0]))[:20] + out += ["
Whole project: files with most warnings", "", + "| File | Compiler | clang-tidy |", "|---|---:|---:|"] + out += [f"| `{escape(file)}` | {c} | {t} |" for file, (c, t) in top] + out += ["", "
", ""] + return out + + def footer(self): + parts = [] + if self.sha: + parts.append(f"Commit {self.sha[:10]}") + if self.run_url: + parts.append(f"[Workflow run and full build logs]({self.run_url})") + parts.append("Deduplicated across translation units and builds. " + "Excludes `dependencies/`, system headers and generated files.") + return ["" + " · ".join(parts) + ""] + + def render(self): + out = [MARKER] + out += self.headline() + [""] + out += self.changed_files_section() + compiler_table = self.platform_table(COMPILER, "All compilers (unique)") + if compiler_table: + out += ["#### Compiler warnings", ""] + compiler_table + tidy_table = self.platform_table(CLANG_TIDY, "All (unique)") + if tidy_table: + out += ["#### clang-tidy", ""] + tidy_table + out += self.breakdown_section() + out += self.footer() + + text = "\n".join(out) + if len(text) > MAX_REPORT_SIZE: + cut = text.rfind("\n", 0, MAX_REPORT_SIZE) + text = text[:cut] + "\n\n_The report was truncated; see the workflow run for the full logs._\n" \ + + "\n".join(self.footer()) + return text def main(): parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("--logs-dir", required=True, help="Directory with one subdirectory per build log") parser.add_argument("--changed-files", help="File with one changed path (relative) per line") + parser.add_argument("--repo", help="owner/name, for links to source lines") + parser.add_argument("--sha", help="Commit SHA, for links to source lines") + parser.add_argument("--run-url", help="URL of the workflow run") args = parser.parse_args() changed = None @@ -106,60 +300,12 @@ def main(): with open(args.changed_files, encoding="utf-8") as f: changed = {line.strip() for line in f if line.strip()} - reports = [parse_log(d) for d in pathlib.Path(args.logs_dir).iterdir() if d.is_dir()] - reports.sort(key=lambda r: r[0].lower()) + logs_dir = pathlib.Path(args.logs_dir) + logs = [parse_log(d) for d in logs_dir.iterdir() if d.is_dir()] if logs_dir.is_dir() else [] + logs.sort(key=lambda log: log.title.lower()) - # Unique warnings across all platforms, with the platforms that reported each. - platforms_by_warning = collections.defaultdict(list) - for title, warnings in reports: - for w in warnings or (): - platforms_by_warning[w].append(title) - all_warnings = sorted(platforms_by_warning) - - def in_changed(warnings): - return [w for w in warnings if w.file in changed] - - out = [MARKER, "## Warnings report", ""] - - if changed is not None: - out += ["| Platform | In changed files | Total |", "|---|---:|---:|"] - else: - out += ["| Platform | Total |", "|---|---:|"] - for title, warnings in reports: - if warnings is None: - cells = ["n/a", "build log missing"] if changed is not None else ["build log missing"] - elif changed is not None: - cells = [str(len(in_changed(warnings))), str(len(warnings))] - else: - cells = [str(len(warnings))] - out.append(f"| {escape(title)} | " + " | ".join(cells) + " |") - if changed is not None: - out.append(f"| **All platforms (unique)** | **{len(in_changed(all_warnings))}** | **{len(all_warnings)}** |") - else: - out.append(f"| **All platforms (unique)** | **{len(all_warnings)}** |") - out.append("") - - listed = in_changed(all_warnings) if changed is not None else [] - if listed: - out += [f"
Warnings in changed files ({len(listed)})", ""] - for w in listed[:MAX_LISTED]: - flag = f" `[{w.flag}]`" if w.flag else "" - out.append(f"- `{w.file}:{w.line}:{w.col}`: {escape(w.msg)}{flag}" - f" ({escape(', '.join(platforms_by_warning[w]))})") - if len(listed) > MAX_LISTED: - out.append(f"- ... and {len(listed) - MAX_LISTED} more") - out += ["", "
", ""] - - if all_warnings: - counter = collections.Counter(w.flag or "(no flag)" for w in all_warnings) - out += [f"
All warnings by type ({len(all_warnings)})", "", - "| Warning | Count |", "|---|---:|"] - out += [f"| `{flag}` | {n} |" for flag, n in counter.most_common(25)] - out += ["", "
", ""] - - out.append("Deduplicated across translation units and platforms. Warnings in `dependencies/`, " - "system headers and generated files are excluded. Updated automatically on each push.") - print("\n".join(out)) + sys.stdout.reconfigure(encoding="utf-8") + print(Report(logs, changed, args.repo, args.sha, args.run_url).render()) return 0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1eb98d3..7215885 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,11 +62,16 @@ jobs: > changed-files.txt - name: Generate report + env: + HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }} run: | mkdir -p logs changed=() if [ -f changed-files.txt ]; then changed=(--changed-files changed-files.txt); fi - python3 .github/scripts/warnings_report.py --logs-dir logs "${changed[@]}" > report.md + python3 .github/scripts/warnings_report.py --logs-dir logs "${changed[@]}" \ + --repo "$GITHUB_REPOSITORY" --sha "$HEAD_SHA" \ + --run-url "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \ + > report.md cat report.md >> "$GITHUB_STEP_SUMMARY" # The token is read-only for PRs from forks, so there the report is only in the job summary. diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index ab8bdd9..162aa9e 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -53,3 +53,4 @@ jobs: with: id: clang-tidy-${{ env.LLVM_VERSION }} title: clang-tidy ${{ env.LLVM_VERSION }} + category: clang-tidy