-
Notifications
You must be signed in to change notification settings - Fork 46
/
run-tests.sh
executable file
·138 lines (121 loc) · 3.8 KB
/
run-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
#
# This file is part of REANA.
# Copyright (C) 2017, 2018, 2019, 2020, 2022, 2024 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
set -o errexit
set -o nounset
check_commitlint () {
from=${2:-master}
to=${3:-HEAD}
pr=${4:-[0-9]+}
npx commitlint --from="$from" --to="$to"
found=0
while IFS= read -r line; do
commit_hash=$(echo "$line" | cut -d ' ' -f 1)
commit_title=$(echo "$line" | cut -d ' ' -f 2-)
commit_number_of_parents=$(git rev-list --parents "$commit_hash" -n1 | awk '{print NF-1}')
# (i) skip checking release commits generated by Release Please
if [ "$commit_number_of_parents" -le 1 ] && echo "$commit_title" | grep -qP "^chore\(.*\): release"; then
continue
fi
# (ii) check presence of PR number
if ! echo "$commit_title" | grep -qP "\(\#$pr\)$"; then
echo "✖ Headline does not end by '(#$pr)' PR number: $commit_title"
found=1
fi
# (iii) check absence of merge commits in feature branches
if [ "$commit_number_of_parents" -gt 1 ]; then
if echo "$commit_title" | grep -qP "^chore\(.*\): merge "; then
break # skip checking maint-to-master merge commits
else
echo "✖ Merge commits are not allowed in feature branches: $commit_title"
found=1
fi
fi
done < <(git log "$from..$to" --format="%H %s")
if [ $found -gt 0 ]; then
exit 1
fi
}
check_shellcheck () {
find . -name "*.sh" -exec shellcheck {} \+
}
check_black () {
black --check .
}
check_flake8 () {
flake8 .
}
check_pydocstyle () {
pydocstyle reana_client
}
check_manifest () {
check-manifest
}
check_cli_cmds () {
reana-client --help > cmd_list.txt
diff -q -w docs/cmd_list.txt cmd_list.txt
rm cmd_list.txt
}
check_cli_api () {
cli_docs_url=https://raw.githubusercontent.com/reanahub/docs.reana.io/master/docs/reference/reana-client-cli-api/index.md
docs_differ_error_msg='Current reana-client differs with the documentation. Please update http://docs.reana.io/reference/reana-client-cli-api/.'
python scripts/generate_cli_api.py > cli_api.md
(diff -q -w cli_api.md <(curl -s $cli_docs_url) || (echo "$docs_differ_error_msg" && exit 1))
rm cli_api.md
}
check_dockerfile () {
docker run -i --rm docker.io/hadolint/hadolint:v2.12.0 < Dockerfile
}
check_docker_build () {
docker build -t docker.io/reanahub/reana-client .
}
check_docker_run () {
docker run --rm -v "$PWD"/tests:/home/reana/tests --entrypoint /bin/bash docker.io/reanahub/reana-client -c 'pytest tests'
}
check_sphinx () {
sphinx-build -qnNW docs docs/_build/html
sphinx-build -qnNW -b doctest docs docs/_build/doctest
}
check_pytest () {
pytest
}
check_all() {
check_commitlint
check_shellcheck
check_black
check_flake8
check_pydocstyle
check_manifest
check_cli_cmds
check_cli_api
check_dockerfile
check_docker_build
check_docker_run
check_sphinx
check_pytest
}
if [ $# -eq 0 ]; then
check_all
exit 0
fi
arg="$1"
case $arg in
--check-commitlint) check_commitlint "$@";;
--check-shellcheck) check_shellcheck;;
--check-black) check_black;;
--check-flake8) check_flake8;;
--check-pydocstyle) check_pydocstyle;;
--check-manifest) check_manifest;;
--check-cli-cmds) check_cli_cmds;;
--check-cli-api) check_cli_api;;
--check-dockerfile) check_dockerfile;;
--check-docker-build) check_docker_build;;
--check-docker-run) check_docker_run;;
--check-sphinx) check_sphinx;;
--check-pytest) check_pytest;;
*) echo "[ERROR] Invalid argument '$arg'. Exiting." && exit 1;;
esac