Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c3d2ac

Browse files
jmchiltonpre-commit-ci[bot]cobaltt7
authored
feat: add output-file input for clean Black logging (psf#4824)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: cobalt <[email protected]>
1 parent 45b4087 commit 0c3d2ac

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
- Enable 3.14 base CI (#4804)
100100
- Enhance GitHub Action `psf/black` to support the `required-version` major-version-only
101101
"stability" format when using pyproject.toml (#4770)
102+
- Add `output-file` input to GitHub Action `psf/black` to write formatter output to a
103+
file for artifact capture and log cleanliness (#4824)
102104
- Improve error message for vim plugin users. It now handles independently vim version
103105
- Vim: Warn on unsupported Vim and Python versions independently (#4772)
104106
- Vim: Print the import paths when importing black fails (#4675)

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ inputs:
3535
description: "Whether to add the output to the workflow summary"
3636
required: false
3737
default: true
38+
output-file:
39+
description: >
40+
Optional path to write Black output to a file in addition to stdout. Useful for
41+
keeping GitHub Actions logs clean when using --diff or --check.
42+
required: false
43+
default: ""
3844
branding:
3945
color: "black"
4046
icon: "check-circle"
@@ -75,5 +81,6 @@ runs:
7581
INPUT_BLACK_ARGS: ${{ inputs.black_args }}
7682
INPUT_VERSION: ${{ inputs.version }}
7783
INPUT_USE_PYPROJECT: ${{ inputs.use_pyproject }}
84+
OUTPUT_FILE: ${{ inputs.output-file }}
7885
pythonioencoding: utf-8
7986
shell: bash

action/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
BLACK_ARGS = os.getenv("INPUT_BLACK_ARGS", default="")
1616
VERSION = os.getenv("INPUT_VERSION", default="")
1717
USE_PYPROJECT = os.getenv("INPUT_USE_PYPROJECT") == "true"
18+
OUTPUT_FILE = os.getenv("OUTPUT_FILE", default="")
1819

1920
BLACK_VERSION_RE = re.compile(r"^black([^A-Z0-9._-]+.*)$", re.IGNORECASE)
2021
EXTRAS_RE = re.compile(r"\[.*\]")
@@ -181,5 +182,16 @@ def find_black_version_in_array(array: object) -> str | None:
181182
encoding="utf-8",
182183
)
183184
shutil.rmtree(ENV_PATH, ignore_errors=True)
185+
186+
# Write output to file if specified
187+
if OUTPUT_FILE:
188+
try:
189+
with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
190+
f.write(proc.stdout)
191+
print(f"Black output written to {OUTPUT_FILE}")
192+
except Exception as e:
193+
print(f"::error::Failed to write output to {OUTPUT_FILE}: {e}", file=sys.stderr)
194+
sys.exit(1)
195+
184196
print(proc.stdout)
185197
sys.exit(proc.returncode)

0 commit comments

Comments
 (0)