File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff 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 : " "
3844branding :
3945 color : " black"
4046 icon : " check-circle"
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
Original file line number Diff line number Diff line change 1515BLACK_ARGS = os .getenv ("INPUT_BLACK_ARGS" , default = "" )
1616VERSION = os .getenv ("INPUT_VERSION" , default = "" )
1717USE_PYPROJECT = os .getenv ("INPUT_USE_PYPROJECT" ) == "true"
18+ OUTPUT_FILE = os .getenv ("OUTPUT_FILE" , default = "" )
1819
1920BLACK_VERSION_RE = re .compile (r"^black([^A-Z0-9._-]+.*)$" , re .IGNORECASE )
2021EXTRAS_RE = re .compile (r"\[.*\]" )
@@ -181,5 +182,16 @@ def find_black_version_in_array(array: object) -> str | None:
181182 encoding = "utf-8" ,
182183 )
183184shutil .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+
184196print (proc .stdout )
185197sys .exit (proc .returncode )
You can’t perform that action at this time.
0 commit comments