From ba3648d98471a6d0ad951d7f75ac512108173bc7 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Fri, 8 Jan 2021 20:47:03 +0100 Subject: [PATCH] Release gh action (#1909) * Gets gh-action ready for marketplace release * Updates documentation and removes redundant gh-action input argument * Fixes gh-action bug This commit fixes a bug which caused not all input arguments were forwarder to the black formatter. * Update README.md Co-authored-by: Cooper Lees Co-authored-by: Cooper Lees --- README.md | 8 ++++++++ action.yml | 5 +++++ action/entrypoint.sh | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a557a6f..269bf5a 100644 --- a/README.md +++ b/README.md @@ -411,8 +411,16 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 - uses: psf/black@stable + with: + black_args: ". --check" ``` +### Inputs + +#### `black_args` + +**optional**: Black input arguments. Defaults to `. --check --diff`. + ## Ignoring unmodified files _Black_ remembers files it has already formatted, unless the `--diff` flag is used or diff --git a/action.yml b/action.yml index 60bf369..59b16a9 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,11 @@ name: "Black" description: "The uncompromising Python code formatter." author: "Łukasz Langa and contributors to Black" +inputs: + black_args: + description: "Black input arguments." + required: false + default: "" branding: color: "black" icon: "check-circle" diff --git a/action/entrypoint.sh b/action/entrypoint.sh index dc86fa1..92501f7 100755 --- a/action/entrypoint.sh +++ b/action/entrypoint.sh @@ -1,10 +1,17 @@ #!/bin/sh set -e -if [ $# -eq 0 ]; then - # Default (if no args provided). - sh -c "black . --check --diff" +# 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 - # Custom args. - sh -c "black $*" + # Default (if no args provided). + black_args+=("--check" "--diff") fi + +sh -c "black . ${black_args[*]}" -- 2.39.2