@@ -12,44 +12,42 @@ set -o nounset
1212export REANA_SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://postgres:mysecretpassword@localhost/postgres
1313
1414# Verify that db container is running before continuing
15- _check_ready () {
15+ _check_ready () {
1616 RETRIES=40
17- while ! $2
18- do
17+ while ! $2 ; do
1918 echo " ==> [INFO] Waiting for $1 , $(( RETRIES-- )) remaining attempts..."
2019 sleep 2
21- if [ $RETRIES -eq 0 ]
22- then
20+ if [ $RETRIES -eq 0 ]; then
2321 echo " ==> [ERROR] Couldn't reach $1 "
2422 exit 1
2523 fi
2624 done
2725}
2826
29- _db_check () {
30- docker exec --user postgres postgres__reana-workflow-controller bash -c " pg_isready" & > /dev/null;
27+ _db_check () {
28+ docker exec --user postgres postgres__reana-workflow-controller bash -c " pg_isready" & > /dev/null
3129}
3230
33- clean_old_db_container () {
31+ clean_old_db_container () {
3432 OLD=" $( docker ps --all --quiet --filter=name=postgres__reana-workflow-controller) "
3533 if [ -n " $OLD " ]; then
3634 echo ' ==> [INFO] Cleaning old DB container...'
3735 docker stop postgres__reana-workflow-controller
3836 fi
3937}
4038
41- start_db_container () {
39+ start_db_container () {
4240 echo ' ==> [INFO] Starting DB container...'
4341 docker run --rm --name postgres__reana-workflow-controller -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d docker.io/library/postgres:14.10
4442 _check_ready " Postgres" _db_check
4543}
4644
47- stop_db_container () {
45+ stop_db_container () {
4846 echo ' ==> [INFO] Stopping DB container...'
4947 docker stop postgres__reana-workflow-controller
5048}
5149
52- check_commitlint () {
50+ check_commitlint () {
5351 from=${2:- master}
5452 to=${3:- HEAD}
5553 pr=${4:- [0-9]+}
@@ -71,7 +69,7 @@ check_commitlint () {
7169 # (iii) check absence of merge commits in feature branches
7270 if [ " $commit_number_of_parents " -gt 1 ]; then
7371 if echo " $commit_title " | grep -qP " ^chore\(.*\): merge " ; then
74- break # skip checking maint-to-master merge commits
72+ break # skip checking maint-to-master merge commits
7573 else
7674 echo " ✖ Merge commits are not allowed in feature branches: $commit_title "
7775 found=1
@@ -83,53 +81,57 @@ check_commitlint () {
8381 fi
8482}
8583
86- check_shellcheck () {
84+ check_shellcheck () {
8785 find . -name " *.sh" -exec shellcheck {} \+
8886}
8987
90- check_pydocstyle () {
88+ check_pydocstyle () {
9189 pydocstyle reana_workflow_controller
9290}
9391
94- check_black () {
92+ check_black () {
9593 black --check .
9694}
9795
98- check_flake8 () {
96+ check_flake8 () {
9997 flake8 .
10098}
10199
102- check_openapi_spec () {
100+ check_openapi_spec () {
103101 FLASK_APP=reana_workflow_controller/app.py python ./scripts/generate_openapi_spec.py
104102 diff -q -w temp_openapi.json docs/openapi.json
105103 rm temp_openapi.json
106104}
107105
108- check_manifest () {
106+ check_manifest () {
109107 check-manifest
110108}
111109
112- check_sphinx () {
110+ check_sphinx () {
113111 sphinx-build -qnNW docs docs/_build/html
114112}
115113
116- check_pytest () {
114+ check_shfmt () {
115+ shfmt -d .
116+ }
117+
118+ check_pytest () {
117119 clean_old_db_container
118120 start_db_container
119121 trap clean_old_db_container SIGINT SIGTERM SIGSEGV ERR
120122 pytest
121123 stop_db_container
122124}
123125
124- check_dockerfile () {
125- docker run -i --rm docker.io/hadolint/hadolint:v2.12.0 < Dockerfile
126+ check_dockerfile () {
127+ docker run -i --rm docker.io/hadolint/hadolint:v2.12.0 < Dockerfile
126128}
127129
128- check_docker_build () {
130+ check_docker_build () {
129131 docker build -t docker.io/reanahub/reana-workflow-controller .
130132}
131133
132- check_all () {
134+ check_all () {
133135 check_commitlint
134136 check_shellcheck
135137 check_pydocstyle
@@ -141,6 +143,7 @@ check_all () {
141143 check_pytest
142144 check_dockerfile
143145 check_docker_build
146+ check_shfmt
144147}
145148
146149if [ $# -eq 0 ]; then
150153
151154arg=" $1 "
152155case $arg in
153- --check-commitlint) check_commitlint " $@ " ;;
154- --check-shellcheck) check_shellcheck;;
155- --check-pydocstyle) check_pydocstyle;;
156- --check-black) check_black;;
157- --check-flake8) check_flake8;;
158- --check-openapi-spec) check_openapi_spec;;
159- --check-manifest) check_manifest;;
160- --check-sphinx) check_sphinx;;
161- --check-pytest) check_pytest;;
162- --check-dockerfile) check_dockerfile;;
163- --check-docker-build) check_docker_build;;
164- * ) echo " [ERROR] Invalid argument '$arg '. Exiting." && exit 1;;
156+ --check-commitlint) check_commitlint " $@ " ;;
157+ --check-shellcheck) check_shellcheck ;;
158+ --check-pydocstyle) check_pydocstyle ;;
159+ --check-black) check_black ;;
160+ --check-flake8) check_flake8 ;;
161+ --check-openapi-spec) check_openapi_spec ;;
162+ --check-manifest) check_manifest ;;
163+ --check-sphinx) check_sphinx ;;
164+ --check-pytest) check_pytest ;;
165+ --check-dockerfile) check_dockerfile ;;
166+ --check-docker-build) check_docker_build ;;
167+ --check-shfmt) check_shfmt ;;
168+ * ) echo " [ERROR] Invalid argument '$arg '. Exiting." && exit 1 ;;
165169esac
0 commit comments