Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify GitHub Action entrypoint (#1909) #2119

Merged
merged 3 commits into from May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,17 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: psf/black@stable
with:
args: ". --check"
```

### Inputs
You may use `options` (Default is `'--check --diff'`) and `src` (Default is `'.'`) as
follows:

#### `black_args`

**optional**: Black input arguments. Defaults to `. --check --diff`.
```yaml
- uses: psf/black@stable
with:
options: "--check --verbose"
src: "./src"
```

## Ignoring unmodified files

Expand Down
12 changes: 11 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ 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'"
required: false
default: "--check --diff"
src:
description: "Source to run black. Default: '.'"
required: false
default: "."
black_args:
description: "Black input arguments."
description: "[DEPRECATED] Black input arguments."
required: false
default: ""
branding:
Expand Down
21 changes: 6 additions & 15 deletions action/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
#!/bin/bash
set -e
#!/bin/bash -e

# If no arguments are given use current working directory
black_args=(".")
if [ "$#" -eq 0 ] && [ "${INPUT_BLACK_ARGS}" != "" ]; then
black_args+=(${INPUT_BLACK_ARGS})
elif [ "$#" -ne 0 ] && [ "${INPUT_BLACK_ARGS}" != "" ]; then
black_args+=($* ${INPUT_BLACK_ARGS})
elif [ "$#" -ne 0 ] && [ "${INPUT_BLACK_ARGS}" == "" ]; then
black_args+=($*)
else
# Default (if no args provided).
black_args+=("--check" "--diff")
fi
if [ -n $INPUT_BLACK_ARGS ]; then
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"" is necessary to check if $INPUT_BLACK_ARGS is empty.

Suggested change
if [ -n $INPUT_BLACK_ARGS ]; then
if [ -n "$INPUT_BLACK_ARGS" ]; then

echo '::warning::Input `with.black_args` is deprecated. Use `with.options` and `with.src` instead.'
black $INPUT_BLACK_ARGS
exit $?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fi is missing here...

Suggested change
exit $?
exit $?
fi


sh -c "black . ${black_args[*]}"
black $INPUT_OPTIONS $INPUT_SRC