black/action.yml
Sebastian Rittau 3383f531bc
GitHub Action: Allow reading version from pyproject.toml (#4294)
Closes #4285

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-04-05 08:40:40 -04:00

80 lines
2.3 KiB
YAML

name: "Black"
description: "The uncompromising Python code formatter."
author: "Łukasz Langa and contributors to Black"
inputs:
options:
description:
"Options passed to Black. Use `black --help` to see available options. Default:
'--check --diff'"
required: false
default: "--check --diff"
src:
description: "Source to run Black. Default: '.'"
required: false
default: "."
jupyter:
description:
"Set this option to true to include Jupyter Notebook files. Default: false"
required: false
default: false
black_args:
description: "[DEPRECATED] Black input arguments."
required: false
default: ""
deprecationMessage:
"Input `with.black_args` is deprecated. Use `with.options` and `with.src` instead."
version:
description: 'Python Version specifier (PEP440) - e.g. "21.5b1"'
required: false
default: ""
use_pyproject:
description: Read Black version specifier from pyproject.toml if `true`.
required: false
default: "false"
summary:
description: "Whether to add the output to the workflow summary"
required: false
default: true
branding:
color: "black"
icon: "check-circle"
runs:
using: composite
steps:
- name: black
run: |
# Even when black fails, do not close the shell
set +e
if [ "$RUNNER_OS" == "Windows" ]; then
runner="python"
else
runner="python3"
fi
out=$(${runner} $GITHUB_ACTION_PATH/action/main.py)
exit_code=$?
# Display the raw output in the step
echo "${out}"
if [ "${{ inputs.summary }}" == "true" ]; then
# Display the Markdown output in the job summary
echo "\`\`\`python" >> $GITHUB_STEP_SUMMARY
echo "${out}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
fi
# Exit with the exit-code returned by Black
exit ${exit_code}
env:
# TODO: Remove once https://github.com/actions/runner/issues/665 is fixed.
INPUT_OPTIONS: ${{ inputs.options }}
INPUT_SRC: ${{ inputs.src }}
INPUT_JUPYTER: ${{ inputs.jupyter }}
INPUT_BLACK_ARGS: ${{ inputs.black_args }}
INPUT_VERSION: ${{ inputs.version }}
INPUT_USE_PYPROJECT: ${{ inputs.use_pyproject }}
pythonioencoding: utf-8
shell: bash