diff --git a/CHANGELOG.md b/CHANGELOG.md index a840518..e05e5d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,37 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [v1.3.2](https://github.com/reviewdog/action-black/compare/v1.3.1...v1.3.2) + +> 28 December 2020 + +- :bug: Fixes bug in the is_formatted output argument [`7b40b4c`](https://github.com/reviewdog/action-black/commit/7b40b4c53700aebfe7a4a3e4d6027aa8b2a116a0) +- :bug: Fixes output ret bug when format is set to false [`a7203f6`](https://github.com/reviewdog/action-black/commit/a7203f604a3b1974b817e15177a792d717b6e982) + +#### [v1.3.1](https://github.com/reviewdog/action-black/compare/v1.3...v1.3.1) + +> 28 December 2020 + +- :bug: Fixes bug in the is_formatted output argument [`#22`](https://github.com/reviewdog/action-black/pull/22) + +#### [v1.3](https://github.com/reviewdog/action-black/compare/v1.3.0...v1.3) + +> 28 December 2020 + +#### [v1.3.0](https://github.com/reviewdog/action-black/compare/v1.2.2...v1.3.0) + +> 28 December 2020 + +- :sparkles: Adds is_formatted output argument [`#21`](https://github.com/reviewdog/action-black/pull/21) +- :green_heart: Fixes release gh-action [`16f69ed`](https://github.com/reviewdog/action-black/commit/16f69ed9c674938748f426c4f0a0a052dee5c250) + +#### [v1.2.2](https://github.com/reviewdog/action-black/compare/v1.2.1...v1.2.2) + +> 28 December 2020 + +- :memo: Adds changelog [`8b9c42d`](https://github.com/reviewdog/action-black/commit/8b9c42dee4fdcfdbb5a398ac1c39dba1c75e9424) +- :memo: Updates README.md [`8d123cb`](https://github.com/reviewdog/action-black/commit/8d123cbcbc57aa500c283cf8f3ad46d10bf793cd) + #### [v1.2.1](https://github.com/reviewdog/action-black/compare/v1.2...v1.2.1) > 28 December 2020 @@ -12,7 +43,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). > 28 December 2020 -- :twisted_rightwards_arrows: Merge pull request #20 from reviewdog/exit_code_bug_fix [`de701b3`](https://github.com/reviewdog/action-black/commit/de701b3f1708f1868d55c9285a06571c2bde7171) +- :memo: Adds changelog [`8b9c42d`](https://github.com/reviewdog/action-black/commit/8b9c42dee4fdcfdbb5a398ac1c39dba1c75e9424) - :art: :bug: Fixes a small bug while catching the exit code [`ac37b4f`](https://github.com/reviewdog/action-black/commit/ac37b4f4b861666e736df9943171a85e853e0ccb) - :art: :fire: Removes redundant test [`f042d95`](https://github.com/reviewdog/action-black/commit/f042d9566d475dd75a1af0400a63affe4cdae2da) @@ -50,9 +81,9 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). > 28 December 2020 -- :twisted_rightwards_arrows: Merge pull request #20 from reviewdog/exit_code_bug_fix [`de701b3`](https://github.com/reviewdog/action-black/commit/de701b3f1708f1868d55c9285a06571c2bde7171) - :sparkles: Adds ability to also format the code [`2d3fcd1`](https://github.com/reviewdog/action-black/commit/2d3fcd14c4eccf82ef584084d0a6d4f02869dd05) - :bug: Fixes docker input arguments bug [`7a8c881`](https://github.com/reviewdog/action-black/commit/7a8c881dae3ee394d7b2df183bf24136a039a5b5) +- :art: Improves code structure to fix shellcheck warning [`8b57f2f`](https://github.com/reviewdog/action-black/commit/8b57f2f1881c8b026e3c7d2bd685a6b21006033b) #### [v1.0](https://github.com/reviewdog/action-black/compare/v1.0.0...v1.0) diff --git a/README.md b/README.md index 5d49525..ca26805 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ inputs: required: false default: "" ``` + ### Docker input args Besides the aforementioned input arguments you can also supply additional input arguments for the black formatter using the args keyword [run.args](https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/metadata-syntax-for-github-actions#runsargs). diff --git a/entrypoint.sh b/entrypoint.sh index 6a5a461..ca0d3b3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -15,7 +15,7 @@ else fi # Run black with reviewdog -black_error="false" +black_exit_val="0" reviewdog_error="false" if [[ "${INPUT_ANNOTATE}" = 'true' ]]; then if [[ "${INPUT_REPORTER}" = 'github-pr-review' ]]; then @@ -31,8 +31,15 @@ if [[ "${INPUT_ANNOTATE}" = 'true' ]]; then -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ ${INPUT_REVIEWDOG_FLAGS} || reviewdog_error="true" black_exit_val="${PIPESTATUS[0]}" - if [[ "${black_exit_val}" -ne "0" ]]; then + + # Check whether black found formatting errors + if [[ "${black_exit_val}" -eq "0" ]]; then + black_error="false" + elif [[ "${black_exit_val}" -eq "1" ]]; then black_error="true" + else + echo "Something went wrong while trying to run the black command (error code: ${black_exit_val})." + exit 1 fi else echo "[action-black] Checking python code with the black formatter and reviewdog..." @@ -45,31 +52,54 @@ if [[ "${INPUT_ANNOTATE}" = 'true' ]]; then -level="${INPUT_LEVEL}" \ ${INPUT_REVIEWDOG_FLAGS} || reviewdog_error="true" black_exit_val="${PIPESTATUS[0]}" - if [[ "${black_exit_val}" -ne "0" ]]; then + + # Check whether black found formatting errors + if [[ "${black_exit_val}" -eq "0" ]]; then + black_error="false" + elif [[ "${black_exit_val}" -eq "1" ]]; then black_error="true" + else + echo "[action-black] ERROR: Something went wrong while trying to run the black formatter (error code: ${black_exit_val})." + exit 1 fi fi else echo "[action-black] Checking python code using the black formatter..." - black --check "${INPUT_WORKDIR}/${black_args}" 2>&1 || black_error="true" + black --check "${INPUT_WORKDIR}/${black_args}" 2>&1 || black_exit_val="$?" + + # Check whether black found formatting errors + if [[ "${black_exit_val}" -eq "0" ]]; then + black_error="false" + elif [[ "${black_exit_val}" -eq "1" ]]; then + black_error="true" + else + echo "[action-black] ERROR: Something went wrong while trying to run the black formatter (error code: ${black_exit_val})." + exit 1 + fi fi # Also format code if this is requested # NOTE: Useful for writing back changes or creating a pull request. +black_format_exit_val="0" if [[ "${INPUT_FORMAT}" = 'true' && "${black_error}" = 'true' ]]; then echo "[action-black] Formatting python code using the black formatter..." - black "${INPUT_WORKDIR}/${black_args}" || black_format_error="true" + black "${INPUT_WORKDIR}/${black_args}" || black_format_exit_val="$?" - # Check if code was formatted - if [[ "${black_format_error}" != "true" ]]; then + # Check whether black found formatting errors + if [[ "${black_format_exit_val}" -eq "0" ]]; then echo "::set-output name=is_formatted::true" - else - black_error="${black_format_error}" + elif [[ "${black_format_exit_val}" -eq "1" ]]; then + black_error="true" echo "::set-output name=is_formatted::false" + else + echo "[action-black] ERROR: Something went wrong while trying to run the black formatter (error code: ${black_exit_val})." + exit 1 fi elif [[ "${INPUT_FORMAT}" = 'true' && "${black_error}" != 'true' ]]; then echo "[action-black] Formatting not needed." echo "::set-output name=is_formatted::false" +else + echo "::set-output name=is_formatted::false" fi # Throw error if an error occurred and fail_on_error is true