Unverified Commit 53168363 authored by Shota Ray Imaki's avatar Shota Ray Imaki Committed by GitHub
Browse files

Simplify GitHub Action entrypoint (#2119)

This commit simplifies entrypoint.sh for GitHub Actions by removing
duplication of args and black_args (cf. #1909).

The reason why #1909 uses the input id black_args is to avoid an overlap
with args, but this naming seems redundant. So let me suggest option
and src, which are consistent with CLI. Backward compatibility is
guaranteed; Users can still use black_args as well.

Commit history pre-merge:
* Simplify GitHub Action entrypoint (#1909)
* Fix prettier
* Emit a warning message when `black_args` is used

  This deprecation should be visible in GitHub Action's UI now.

  Co-authored-by: default avatarShota Ray Imaki <shota.imaki.0801@gmail.com>
  Co-authored-by: default avatarRichard Si <63936253+ichard26@users.noreply.github.com>
parent 07c88129
Loading
Loading
Loading
Loading
+8 −6
Changes for README.md: 8 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -425,15 +425,17 @@ jobs:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
      - uses: psf/black@stable
        with:
          args: ". --check"
```

### Inputs

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

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

## Ignoring unmodified files

+11 −1
Changes for action.yml: 11 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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:
+6 −15
Changes for action/entrypoint.sh: 6 added lines, 15 removed lines.
Original line number Diff line number Diff line
#!/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
  echo '::warning::Input `with.black_args` is deprecated. Use `with.options` and `with.src` instead.'
  black $INPUT_BLACK_ARGS
  exit $?

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