From a40e211f25d0bf6636857ee540173fbfd858d6ca Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 19 Dec 2025 17:31:21 +0500 Subject: [PATCH] ci - add black formatter annotations --- .../workflows/black_to_github_annotations.py | 41 +++++++++++++++++++ .github/workflows/ci-black-formatting.yaml | 9 ++++ 2 files changed, 50 insertions(+) create mode 100644 .github/workflows/black_to_github_annotations.py diff --git a/.github/workflows/black_to_github_annotations.py b/.github/workflows/black_to_github_annotations.py new file mode 100644 index 0000000000..074eedf6b7 --- /dev/null +++ b/.github/workflows/black_to_github_annotations.py @@ -0,0 +1,41 @@ +from __future__ import annotations + +import json +import os +import sys +from typing import TypedDict + +import github_action_utils as gha_utils + + +class Entry(TypedDict): + location: Location + + +class Location(TypedDict): + path: str + lines: Lines + + +class Lines(TypedDict): + begin: int + end: int + + +json_data: list[Entry] = json.load(sys.stdin) + +if os.getenv("RUNNER_DEBUG"): + print("Debug: Black formatting JSON data:") + print(json.dumps(json_data, indent=2)) + +for change in json_data: + location = change["location"] + path = location["path"] + lines = location["lines"] + gha_utils.error( + f"Black formatting issue in {path}", + title="Black Format Issue", + file=path, + line=lines["begin"], + end_line=lines["end"], + ) diff --git a/.github/workflows/ci-black-formatting.yaml b/.github/workflows/ci-black-formatting.yaml index 4002b0e02e..c5581a2a70 100644 --- a/.github/workflows/ci-black-formatting.yaml +++ b/.github/workflows/ci-black-formatting.yaml @@ -43,6 +43,15 @@ jobs: uses: psf/black@stable continue-on-error: true + # Same check as above, but just for creating github annotations. + - name: Black formatter annotations + id: black-annotations + run: | + uv tool install black-codeclimate + pip install github_action_utils + black --diff --check . | black-codeclimate | python .github/workflows/black_to_github_annotations.py + continue-on-error: true + - name: Ruff check id: ruff run: |