Skip to content

Commit

Permalink
[github action] display black result in job summary (#3688)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
tieum committed May 15, 2023
1 parent 64887aa commit c97b9c5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 15 additions & 5 deletions action/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

0 comments on commit c97b9c5

Please sign in to comment.