11#! /usr/bin/env bash
22#
33# This file is part of REANA.
4- # Copyright (C) 2018, 2020, 2021, 2022, 2023, 2024 CERN.
4+ # Copyright (C) 2018, 2020, 2021, 2022, 2023, 2024, 2025 CERN.
55#
66# REANA is free software; you can redistribute it and/or modify it
77# under the terms of the MIT License; see LICENSE file for more details.
@@ -12,48 +12,58 @@ 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-db bash -c " pg_isready" & > /dev/null;
27+ _db_check () {
28+ docker exec --user postgres postgres__reana-db 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-db) "
3533 if [ -n " $OLD " ]; then
3634 echo ' ==> [INFO] Cleaning old DB container...'
3735 docker stop postgres__reana-db
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-db -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-db
5048}
5149
52- check_commitlint () {
50+ docs_sphinx () {
51+ sphinx-build -qnNW docs docs/_build/html
52+ }
53+
54+ format_black () {
55+ black --check .
56+ }
57+
58+ lint_commitlint () {
5359 from=${2:- master}
5460 to=${3:- HEAD}
5561 pr=${4:- [0-9]+}
56- npx commitlint --from=" $from " --to=" $to "
62+ if command -v commitlint > /dev/null 2>&1 ; then
63+ commitlint --from=" $from " --to=" $to "
64+ else
65+ npx commitlint --from=" $from " --to=" $to "
66+ fi
5767 found=0
5868 while IFS= read -r line; do
5969 commit_hash=$( echo " $line " | cut -d ' ' -f 1)
@@ -71,7 +81,7 @@ check_commitlint () {
7181 # (iii) check absence of merge commits in feature branches
7282 if [ " $commit_number_of_parents " -gt 1 ]; then
7383 if echo " $commit_title " | grep -qE " ^chore\(.*\): merge " ; then
74- break # skip checking maint-to-master merge commits
84+ break # skip checking maint-to-master merge commits
7585 else
7686 echo " ✖ Merge commits are not allowed in feature branches: $commit_title "
7787 found=1
@@ -83,62 +93,72 @@ check_commitlint () {
8393 fi
8494}
8595
86- check_shellcheck () {
87- find . -name " *.sh" -exec shellcheck {} \+
88- }
89-
90- check_pydocstyle () {
91- pydocstyle reana_db
92- }
93-
94- check_black () {
95- black --check .
96- }
97-
98- check_flake8 () {
96+ lint_flake8 () {
9997 flake8 .
10098}
10199
102- check_manifest () {
100+ lint_manifest () {
103101 check-manifest
104102}
105103
106- check_sphinx () {
107- sphinx-build -qnNW docs docs/_build/html
104+ lint_pydocstyle () {
105+ pydocstyle reana_db
108106}
109107
110- check_pytest () {
108+ lint_shellcheck () {
109+ find . -name " *.sh" -exec shellcheck {} \+
110+ }
111+
112+ python_tests () {
111113 clean_old_db_container
112114 start_db_container
113115 trap clean_old_db_container SIGINT SIGTERM SIGSEGV ERR
114116 pytest
115117 stop_db_container
116118}
117119
118- check_all () {
119- check_shellcheck
120- check_pydocstyle
121- check_black
122- check_flake8
123- check_manifest
124- check_sphinx
125- check_pytest
120+ all () {
121+ docs_sphinx
122+ format_black
123+ lint_commitlint
124+ lint_flake8
125+ lint_manifest
126+ lint_pydocstyle
127+ lint_shellcheck
128+ python_tests
129+ }
130+
131+ help () {
132+ echo " Usage: $0 [options]"
133+ echo " Options:"
134+ echo " --all Perform all checks [default]"
135+ echo " --docs-sphinx Check Sphinx docs build"
136+ echo " --format-black Check formatting of Python code"
137+ echo " --help Display this help message"
138+ echo " --lint-commitlint Check linting of commit messages"
139+ echo " --lint-flake8 Check linting of Python code"
140+ echo " --lint-manifest Check linting of Python manifest"
141+ echo " --lint-pydocstyle Check linting of Python docstrings"
142+ echo " --lint-shellcheck Check linting of shell scripts"
143+ echo " --python-tests Check Python test suite"
126144}
127145
128146if [ $# -eq 0 ]; then
129- check_all
147+ all
130148 exit 0
131149fi
132150
133151arg=" $1 "
134152case $arg in
135- --check-commitlint) check_commitlint " $@ " ;;
136- --check-shellcheck) check_shellcheck;;
137- --check-pydocstyle) check_pydocstyle;;
138- --check-black) check_black;;
139- --check-flake8) check_flake8;;
140- --check-manifest) check_manifest;;
141- --check-sphinx) check_sphinx;;
142- --check-pytest) check_pytest;;
143- * ) echo " [ERROR] Invalid argument '$arg '. Exiting." && exit 1;;
153+ --all) all ;;
154+ --help) help ;;
155+ --docs-sphinx) docs_sphinx ;;
156+ --format-black) format_black ;;
157+ --lint-commitlint) lint_commitlint " $@ " ;;
158+ --lint-flake8) lint_flake8 ;;
159+ --lint-manifest) lint_manifest ;;
160+ --lint-pydocstyle) lint_pydocstyle ;;
161+ --lint-shellcheck) lint_shellcheck ;;
162+ --python-tests) python_tests ;;
163+ * ) echo " [ERROR] Invalid argument '$arg '. Exiting." && help && exit 1 ;;
144164esac
0 commit comments