From f6a446112a01ef1137513552b054ff27d360462a Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 7 Nov 2025 14:39:12 -0500 Subject: [PATCH 1/2] feat: add output-file input for clean Black logging --- CHANGES.md | 2 ++ action.yml | 7 +++++++ action/main.py | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 921fc3efdd8..b2945f5a702 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -73,6 +73,8 @@ - Enable 3.14 base CI (#4804) - Enhance GitHub Action `psf/black` to support the `required-version` major-version-only "stability" format when using pyproject.toml (#4770) +- Add `output-file` input to GitHub Action `psf/black` to write formatter output to a file + for artifact capture and log cleanliness (#4824) - Improve error message for vim plugin users. It now handles independently vim version - Vim: Warn on unsupported Vim and Python versions independently (#4772) - Vim: Print the import paths when importing black fails (#4675) diff --git a/action.yml b/action.yml index d49dc4ac3a0..3f8ec0972b6 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,12 @@ inputs: description: "Whether to add the output to the workflow summary" required: false default: true + output-file: + description: > + Optional path to write Black output to a file in addition to stdout. + Useful for keeping GitHub Actions logs clean when using --diff or --check. + required: false + default: "" branding: color: "black" icon: "check-circle" @@ -75,5 +81,6 @@ runs: INPUT_BLACK_ARGS: ${{ inputs.black_args }} INPUT_VERSION: ${{ inputs.version }} INPUT_USE_PYPROJECT: ${{ inputs.use_pyproject }} + OUTPUT_FILE: ${{ inputs.output-file }} pythonioencoding: utf-8 shell: bash diff --git a/action/main.py b/action/main.py index 2cabc9772ba..b67428285f6 100644 --- a/action/main.py +++ b/action/main.py @@ -16,6 +16,7 @@ BLACK_ARGS = os.getenv("INPUT_BLACK_ARGS", default="") VERSION = os.getenv("INPUT_VERSION", default="") USE_PYPROJECT = os.getenv("INPUT_USE_PYPROJECT") == "true" +OUTPUT_FILE = os.getenv("OUTPUT_FILE", default="") BLACK_VERSION_RE = re.compile(r"^black([^A-Z0-9._-]+.*)$", re.IGNORECASE) EXTRAS_RE = re.compile(r"\[.*\]") @@ -182,5 +183,16 @@ def find_black_version_in_array(array: object) -> Union[str, None]: encoding="utf-8", ) shutil.rmtree(ENV_PATH, ignore_errors=True) + +# Write output to file if specified +if OUTPUT_FILE: + try: + with open(OUTPUT_FILE, "w", encoding="utf-8") as f: + f.write(proc.stdout) + print(f"Black output written to {OUTPUT_FILE}") + except Exception as e: + print(f"::error::Failed to write output to {OUTPUT_FILE}: {e}", file=sys.stderr) + sys.exit(1) + print(proc.stdout) sys.exit(proc.returncode) From fabc5b16b295fcdfaaa42764eff2526ca2cfb57c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 8 Nov 2025 14:29:30 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGES.md | 4 ++-- action.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b2945f5a702..b30f88074fc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -73,8 +73,8 @@ - Enable 3.14 base CI (#4804) - Enhance GitHub Action `psf/black` to support the `required-version` major-version-only "stability" format when using pyproject.toml (#4770) -- Add `output-file` input to GitHub Action `psf/black` to write formatter output to a file - for artifact capture and log cleanliness (#4824) +- Add `output-file` input to GitHub Action `psf/black` to write formatter output to a + file for artifact capture and log cleanliness (#4824) - Improve error message for vim plugin users. It now handles independently vim version - Vim: Warn on unsupported Vim and Python versions independently (#4772) - Vim: Print the import paths when importing black fails (#4675) diff --git a/action.yml b/action.yml index 3f8ec0972b6..9d0d7939cd6 100644 --- a/action.yml +++ b/action.yml @@ -37,8 +37,8 @@ inputs: default: true output-file: description: > - Optional path to write Black output to a file in addition to stdout. - Useful for keeping GitHub Actions logs clean when using --diff or --check. + Optional path to write Black output to a file in addition to stdout. Useful for + keeping GitHub Actions logs clean when using --diff or --check. required: false default: "" branding: