[github action] display black result in job summary (#3688)

* send output to $GITHUB_STEP_SUMMARY

* update CHANGES.md

* update CHANGES.md with PR number

* implement PR feedback

* fix pre-commit issues (prettier/trailing whitespace)
This commit is contained in:
Matthieu Simon 2023-05-15 23:35:39 +02:00 committed by GitHub
parent 64887aab03
commit c97b9c55b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 8 deletions

View File

@ -45,6 +45,8 @@
<!-- For example, Docker, GitHub Actions, pre-commit, editors -->
- Update GitHub Action to display black output in the job summary (#3688)
### Documentation
<!-- Major changes to documentation and policies. Small docs changes

View File

@ -33,11 +33,12 @@ branding:
runs:
using: composite
steps:
- run: |
- name: black
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
python $GITHUB_ACTION_PATH/action/main.py
python $GITHUB_ACTION_PATH/action/main.py | tee -a $GITHUB_STEP_SUMMARY
else
python3 $GITHUB_ACTION_PATH/action/main.py
python3 $GITHUB_ACTION_PATH/action/main.py | tee -a $GITHUB_STEP_SUMMARY
fi
env:
# TODO: Remove once https://github.com/actions/runner/issues/665 is fixed.

View File

@ -32,7 +32,7 @@
describe_name = line[len("describe-name: ") :].rstrip()
break
if not describe_name:
print("::error::Failed to detect action version.", flush=True)
print("::error::Failed to detect action version.", file=sys.stderr, flush=True)
sys.exit(1)
# expected format is one of:
# - 23.1.0
@ -53,15 +53,25 @@
)
if pip_proc.returncode:
print(pip_proc.stdout)
print("::error::Failed to install Black.", flush=True)
print("::error::Failed to install Black.", file=sys.stderr, flush=True)
sys.exit(pip_proc.returncode)
base_cmd = [str(ENV_BIN / "black")]
if BLACK_ARGS:
# TODO: remove after a while since this is deprecated in favour of SRC + OPTIONS.
proc = run([*base_cmd, *shlex.split(BLACK_ARGS)])
proc = run(
[*base_cmd, *shlex.split(BLACK_ARGS)],
stdout=PIPE,
stderr=STDOUT,
encoding="utf-8",
)
else:
proc = run([*base_cmd, *shlex.split(OPTIONS), *shlex.split(SRC)])
proc = run(
[*base_cmd, *shlex.split(OPTIONS), *shlex.split(SRC)],
stdout=PIPE,
stderr=STDOUT,
encoding="utf-8",
)
print(proc.stdout)
sys.exit(proc.returncode)