Skip to content

Commit f133a93

Browse files
committed
🔀 Merge branch 'fixes_error_catch_behavoir'
2 parents 4843f1f + 4ef684f commit f133a93

File tree

3 files changed

+73
-11
lines changed

3 files changed

+73
-11
lines changed

CHANGELOG.md

+33-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,37 @@ All notable changes to this project will be documented in this file. Dates are d
44

55
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
66

7+
#### [v1.3.2](https://github.com/reviewdog/action-black/compare/v1.3.1...v1.3.2)
8+
9+
> 28 December 2020
10+
11+
- :bug: Fixes bug in the is_formatted output argument [`7b40b4c`](https://github.com/reviewdog/action-black/commit/7b40b4c53700aebfe7a4a3e4d6027aa8b2a116a0)
12+
- :bug: Fixes output ret bug when format is set to false [`a7203f6`](https://github.com/reviewdog/action-black/commit/a7203f604a3b1974b817e15177a792d717b6e982)
13+
14+
#### [v1.3.1](https://github.com/reviewdog/action-black/compare/v1.3...v1.3.1)
15+
16+
> 28 December 2020
17+
18+
- :bug: Fixes bug in the is_formatted output argument [`#22`](https://github.com/reviewdog/action-black/pull/22)
19+
20+
#### [v1.3](https://github.com/reviewdog/action-black/compare/v1.3.0...v1.3)
21+
22+
> 28 December 2020
23+
24+
#### [v1.3.0](https://github.com/reviewdog/action-black/compare/v1.2.2...v1.3.0)
25+
26+
> 28 December 2020
27+
28+
- :sparkles: Adds is_formatted output argument [`#21`](https://github.com/reviewdog/action-black/pull/21)
29+
- :green_heart: Fixes release gh-action [`16f69ed`](https://github.com/reviewdog/action-black/commit/16f69ed9c674938748f426c4f0a0a052dee5c250)
30+
31+
#### [v1.2.2](https://github.com/reviewdog/action-black/compare/v1.2.1...v1.2.2)
32+
33+
> 28 December 2020
34+
35+
- :memo: Adds changelog [`8b9c42d`](https://github.com/reviewdog/action-black/commit/8b9c42dee4fdcfdbb5a398ac1c39dba1c75e9424)
36+
- :memo: Updates README.md [`8d123cb`](https://github.com/reviewdog/action-black/commit/8d123cbcbc57aa500c283cf8f3ad46d10bf793cd)
37+
738
#### [v1.2.1](https://github.com/reviewdog/action-black/compare/v1.2...v1.2.1)
839

940
> 28 December 2020
@@ -12,7 +43,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
1243

1344
> 28 December 2020
1445
15-
- :twisted_rightwards_arrows: Merge pull request #20 from reviewdog/exit_code_bug_fix [`de701b3`](https://github.com/reviewdog/action-black/commit/de701b3f1708f1868d55c9285a06571c2bde7171)
46+
- :memo: Adds changelog [`8b9c42d`](https://github.com/reviewdog/action-black/commit/8b9c42dee4fdcfdbb5a398ac1c39dba1c75e9424)
1647
- :art: :bug: Fixes a small bug while catching the exit code [`ac37b4f`](https://github.com/reviewdog/action-black/commit/ac37b4f4b861666e736df9943171a85e853e0ccb)
1748
- :art: :fire: Removes redundant test [`f042d95`](https://github.com/reviewdog/action-black/commit/f042d9566d475dd75a1af0400a63affe4cdae2da)
1849

@@ -50,9 +81,9 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
5081

5182
> 28 December 2020
5283
53-
- :twisted_rightwards_arrows: Merge pull request #20 from reviewdog/exit_code_bug_fix [`de701b3`](https://github.com/reviewdog/action-black/commit/de701b3f1708f1868d55c9285a06571c2bde7171)
5484
- :sparkles: Adds ability to also format the code [`2d3fcd1`](https://github.com/reviewdog/action-black/commit/2d3fcd14c4eccf82ef584084d0a6d4f02869dd05)
5585
- :bug: Fixes docker input arguments bug [`7a8c881`](https://github.com/reviewdog/action-black/commit/7a8c881dae3ee394d7b2df183bf24136a039a5b5)
86+
- :art: Improves code structure to fix shellcheck warning [`8b57f2f`](https://github.com/reviewdog/action-black/commit/8b57f2f1881c8b026e3c7d2bd685a6b21006033b)
5687

5788
#### [v1.0](https://github.com/reviewdog/action-black/compare/v1.0.0...v1.0)
5889

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ inputs:
6464
required: false
6565
default: ""
6666
```
67+
6768
### Docker input args
6869
6970
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).

entrypoint.sh

+39-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ else
1515
fi
1616

1717
# Run black with reviewdog
18-
black_error="false"
18+
black_exit_val="0"
1919
reviewdog_error="false"
2020
if [[ "${INPUT_ANNOTATE}" = 'true' ]]; then
2121
if [[ "${INPUT_REPORTER}" = 'github-pr-review' ]]; then
@@ -31,8 +31,15 @@ if [[ "${INPUT_ANNOTATE}" = 'true' ]]; then
3131
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
3232
${INPUT_REVIEWDOG_FLAGS} || reviewdog_error="true"
3333
black_exit_val="${PIPESTATUS[0]}"
34-
if [[ "${black_exit_val}" -ne "0" ]]; then
34+
35+
# Check whether black found formatting errors
36+
if [[ "${black_exit_val}" -eq "0" ]]; then
37+
black_error="false"
38+
elif [[ "${black_exit_val}" -eq "1" ]]; then
3539
black_error="true"
40+
else
41+
echo "Something went wrong while trying to run the black command (error code: ${black_exit_val})."
42+
exit 1
3643
fi
3744
else
3845
echo "[action-black] Checking python code with the black formatter and reviewdog..."
@@ -45,31 +52,54 @@ if [[ "${INPUT_ANNOTATE}" = 'true' ]]; then
4552
-level="${INPUT_LEVEL}" \
4653
${INPUT_REVIEWDOG_FLAGS} || reviewdog_error="true"
4754
black_exit_val="${PIPESTATUS[0]}"
48-
if [[ "${black_exit_val}" -ne "0" ]]; then
55+
56+
# Check whether black found formatting errors
57+
if [[ "${black_exit_val}" -eq "0" ]]; then
58+
black_error="false"
59+
elif [[ "${black_exit_val}" -eq "1" ]]; then
4960
black_error="true"
61+
else
62+
echo "[action-black] ERROR: Something went wrong while trying to run the black formatter (error code: ${black_exit_val})."
63+
exit 1
5064
fi
5165
fi
5266
else
5367
echo "[action-black] Checking python code using the black formatter..."
54-
black --check "${INPUT_WORKDIR}/${black_args}" 2>&1 || black_error="true"
68+
black --check "${INPUT_WORKDIR}/${black_args}" 2>&1 || black_exit_val="$?"
69+
70+
# Check whether black found formatting errors
71+
if [[ "${black_exit_val}" -eq "0" ]]; then
72+
black_error="false"
73+
elif [[ "${black_exit_val}" -eq "1" ]]; then
74+
black_error="true"
75+
else
76+
echo "[action-black] ERROR: Something went wrong while trying to run the black formatter (error code: ${black_exit_val})."
77+
exit 1
78+
fi
5579
fi
5680

5781
# Also format code if this is requested
5882
# NOTE: Useful for writing back changes or creating a pull request.
83+
black_format_exit_val="0"
5984
if [[ "${INPUT_FORMAT}" = 'true' && "${black_error}" = 'true' ]]; then
6085
echo "[action-black] Formatting python code using the black formatter..."
61-
black "${INPUT_WORKDIR}/${black_args}" || black_format_error="true"
86+
black "${INPUT_WORKDIR}/${black_args}" || black_format_exit_val="$?"
6287

63-
# Check if code was formatted
64-
if [[ "${black_format_error}" != "true" ]]; then
88+
# Check whether black found formatting errors
89+
if [[ "${black_format_exit_val}" -eq "0" ]]; then
6590
echo "::set-output name=is_formatted::true"
66-
else
67-
black_error="${black_format_error}"
91+
elif [[ "${black_format_exit_val}" -eq "1" ]]; then
92+
black_error="true"
6893
echo "::set-output name=is_formatted::false"
94+
else
95+
echo "[action-black] ERROR: Something went wrong while trying to run the black formatter (error code: ${black_exit_val})."
96+
exit 1
6997
fi
7098
elif [[ "${INPUT_FORMAT}" = 'true' && "${black_error}" != 'true' ]]; then
7199
echo "[action-black] Formatting not needed."
72100
echo "::set-output name=is_formatted::false"
101+
else
102+
echo "::set-output name=is_formatted::false"
73103
fi
74104

75105
# Throw error if an error occurred and fail_on_error is true

0 commit comments

Comments
 (0)