|
9 | 9 | set -o errexit |
10 | 10 | set -o nounset |
11 | 11 |
|
12 | | -check_commitlint () { |
13 | | - from=${2:-master} |
14 | | - to=${3:-HEAD} |
15 | | - pr=${4:-[0-9]+} |
16 | | - npx commitlint --from="$from" --to="$to" |
17 | | - found=0 |
18 | | - while IFS= read -r line; do |
19 | | - commit_hash=$(echo "$line" | cut -d ' ' -f 1) |
20 | | - commit_title=$(echo "$line" | cut -d ' ' -f 2-) |
21 | | - commit_number_of_parents=$(git rev-list --parents "$commit_hash" -n1 | awk '{print NF-1}') |
22 | | - # (i) skip checking release commits generated by Release Please |
23 | | - if [ "$commit_number_of_parents" -le 1 ] && echo "$commit_title" | grep -qE "^chore\(.*\): release"; then |
24 | | - continue |
25 | | - fi |
26 | | - # (ii) check presence of PR number |
27 | | - if ! echo "$commit_title" | grep -qE "\(#$pr\)$"; then |
28 | | - echo "✖ Headline does not end by '(#$pr)' PR number: $commit_title" |
29 | | - found=1 |
30 | | - fi |
31 | | - # (iii) check absence of merge commits in feature branches |
32 | | - if [ "$commit_number_of_parents" -gt 1 ]; then |
33 | | - if echo "$commit_title" | grep -qE "^chore\(.*\): merge "; then |
34 | | - break # skip checking maint-to-master merge commits |
35 | | - else |
36 | | - echo "✖ Merge commits are not allowed in feature branches: $commit_title" |
37 | | - found=1 |
38 | | - fi |
39 | | - fi |
40 | | - done < <(git log "$from..$to" --format="%H %s") |
41 | | - if [ $found -gt 0 ]; then |
42 | | - exit 1 |
43 | | - fi |
| 12 | +check_commitlint() { |
| 13 | + from=${2:-master} |
| 14 | + to=${3:-HEAD} |
| 15 | + pr=${4:-[0-9]+} |
| 16 | + npx commitlint --from="$from" --to="$to" |
| 17 | + found=0 |
| 18 | + while IFS= read -r line; do |
| 19 | + commit_hash=$(echo "$line" | cut -d ' ' -f 1) |
| 20 | + commit_title=$(echo "$line" | cut -d ' ' -f 2-) |
| 21 | + commit_number_of_parents=$(git rev-list --parents "$commit_hash" -n1 | awk '{print NF-1}') |
| 22 | + # (i) skip checking release commits generated by Release Please |
| 23 | + if [ "$commit_number_of_parents" -le 1 ] && echo "$commit_title" | grep -qE "^chore\(.*\): release"; then |
| 24 | + continue |
| 25 | + fi |
| 26 | + # (ii) check presence of PR number |
| 27 | + if ! echo "$commit_title" | grep -qE "\(#$pr\)$"; then |
| 28 | + echo "✖ Headline does not end by '(#$pr)' PR number: $commit_title" |
| 29 | + found=1 |
| 30 | + fi |
| 31 | + # (iii) check absence of merge commits in feature branches |
| 32 | + if [ "$commit_number_of_parents" -gt 1 ]; then |
| 33 | + if echo "$commit_title" | grep -qE "^chore\(.*\): merge "; then |
| 34 | + break # skip checking maint-to-master merge commits |
| 35 | + else |
| 36 | + echo "✖ Merge commits are not allowed in feature branches: $commit_title" |
| 37 | + found=1 |
| 38 | + fi |
| 39 | + fi |
| 40 | + done < <(git log "$from..$to" --format="%H %s") |
| 41 | + if [ $found -gt 0 ]; then |
| 42 | + exit 1 |
| 43 | + fi |
44 | 44 | } |
45 | 45 |
|
46 | | -check_shellcheck () { |
47 | | - find . -name "*.sh" -exec shellcheck {} \+ |
| 46 | +check_shellcheck() { |
| 47 | + find . -name "*.sh" -exec shellcheck {} \+ |
48 | 48 | } |
49 | 49 |
|
50 | | -check_pydocstyle () { |
51 | | - pydocstyle reana_commons |
| 50 | +check_pydocstyle() { |
| 51 | + pydocstyle reana_commons |
52 | 52 | } |
53 | 53 |
|
54 | | -check_black () { |
55 | | - black --check . |
| 54 | +check_black() { |
| 55 | + black --check . |
56 | 56 | } |
57 | 57 |
|
58 | | -check_flake8 () { |
59 | | - flake8 . |
| 58 | +check_flake8() { |
| 59 | + flake8 . |
60 | 60 | } |
61 | 61 |
|
62 | | -check_manifest () { |
63 | | - check-manifest |
| 62 | +check_manifest() { |
| 63 | + check-manifest |
64 | 64 | } |
65 | 65 |
|
66 | | -check_sphinx () { |
67 | | - sphinx-build -qnNW docs docs/_build/html |
| 66 | +check_sphinx() { |
| 67 | + sphinx-build -qnNW docs docs/_build/html |
68 | 68 | } |
69 | 69 |
|
70 | | -check_pytest () { |
71 | | - pytest |
| 70 | +check_pytest() { |
| 71 | + pytest |
72 | 72 | } |
73 | 73 |
|
74 | | -check_all () { |
75 | | - check_commitlint |
76 | | - check_shellcheck |
77 | | - check_pydocstyle |
78 | | - check_black |
79 | | - check_flake8 |
80 | | - check_manifest |
81 | | - check_sphinx |
82 | | - check_pytest |
| 74 | +check_all() { |
| 75 | + check_commitlint |
| 76 | + check_shellcheck |
| 77 | + check_pydocstyle |
| 78 | + check_black |
| 79 | + check_flake8 |
| 80 | + check_manifest |
| 81 | + check_sphinx |
| 82 | + check_pytest |
83 | 83 | } |
84 | 84 |
|
85 | 85 | if [ $# -eq 0 ]; then |
86 | | - check_all |
87 | | - exit 0 |
| 86 | + check_all |
| 87 | + exit 0 |
88 | 88 | fi |
89 | 89 |
|
90 | 90 | arg="$1" |
91 | 91 | case $arg in |
92 | | - --check-commitlint) check_commitlint "$@";; |
93 | | - --check-shellcheck) check_shellcheck;; |
94 | | - --check-pydocstyle) check_pydocstyle;; |
95 | | - --check-black) check_black;; |
96 | | - --check-flake8) check_flake8;; |
97 | | - --check-manifest) check_manifest;; |
98 | | - --check-sphinx) check_sphinx;; |
99 | | - --check-pytest) check_pytest;; |
100 | | - *) echo "[ERROR] Invalid argument '$arg'. Exiting." && exit 1;; |
| 92 | +--check-commitlint) check_commitlint "$@" ;; |
| 93 | +--check-shellcheck) check_shellcheck ;; |
| 94 | +--check-pydocstyle) check_pydocstyle ;; |
| 95 | +--check-black) check_black ;; |
| 96 | +--check-flake8) check_flake8 ;; |
| 97 | +--check-manifest) check_manifest ;; |
| 98 | +--check-sphinx) check_sphinx ;; |
| 99 | +--check-pytest) check_pytest ;; |
| 100 | +*) echo "[ERROR] Invalid argument '$arg'. Exiting." && exit 1 ;; |
101 | 101 | esac |
0 commit comments