Skip to content

Commit 6d4223d

Browse files
committed
ci(run-tests): add usage help and refactor options (#254)
1 parent 6f1e3c1 commit 6d4223d

2 files changed

Lines changed: 125 additions & 105 deletions

File tree

.github/workflows/ci.yml

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,37 @@
44
# REANA is free software; you can redistribute it and/or modify it
55
# under the terms of the MIT License; see LICENSE file for more details.
66

7-
name: CI
7+
name: ci
88

99
on: [push, pull_request]
1010

1111
jobs:
12-
lint-commitlint:
12+
docs-sphinx:
1313
runs-on: ubuntu-24.04
1414
steps:
1515
- name: Checkout
1616
uses: actions/checkout@v4
17-
with:
18-
fetch-depth: 0
1917

20-
- name: Setup Node
21-
uses: actions/setup-node@v4
22-
23-
- name: Install commitlint
24-
run: |
25-
npm install conventional-changelog-conventionalcommits
26-
npm install commitlint@latest
18+
- name: Setup Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
2722

28-
- name: Check commit message compliance of the recently pushed commit
29-
if: github.event_name == 'push'
23+
- name: Install system dependencies
3024
run: |
31-
./run-tests.sh --check-commitlint HEAD~1 HEAD
25+
sudo apt-get update -y
26+
sudo apt install libcurl4-openssl-dev libssl-dev
27+
sudo apt-get install libgnutls28-dev
3228
33-
- name: Check commit message compliance of the pull request
34-
if: github.event_name == 'pull_request'
29+
- name: Install Python dependencies
3530
run: |
36-
./run-tests.sh --check-commitlint ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.number }}
37-
38-
lint-shellcheck:
39-
runs-on: ubuntu-24.04
40-
steps:
41-
- name: Checkout
42-
uses: actions/checkout@v4
31+
pip install --upgrade pip 'setuptools<81' py
32+
pip install -e .[all]
4333
44-
- name: Runs shell script static analysis
45-
run: |
46-
sudo apt-get install shellcheck
47-
./run-tests.sh --check-shellcheck
34+
- name: Run Sphinx documentation with doctests
35+
run: ./run-tests.sh --docs-sphinx
4836

49-
lint-black:
37+
format-black:
5038
runs-on: ubuntu-24.04
5139
steps:
5240
- name: Checkout
@@ -61,26 +49,35 @@ jobs:
6149
run: |
6250
pip install --upgrade pip
6351
pip install black
64-
./run-tests.sh --check-black
52+
./run-tests.sh --format-black
6553
66-
lint-flake8:
54+
lint-commitlint:
6755
runs-on: ubuntu-24.04
6856
steps:
6957
- name: Checkout
7058
uses: actions/checkout@v4
71-
72-
- name: Setup Python
73-
uses: actions/setup-python@v5
7459
with:
75-
python-version: "3.12"
60+
fetch-depth: 0
7661

77-
- name: Check compliance with pep8, pyflakes and circular complexity
62+
- name: Setup Node
63+
uses: actions/setup-node@v4
64+
65+
- name: Install commitlint
7866
run: |
79-
pip install --upgrade pip
80-
pip install flake8
81-
./run-tests.sh --check-flake8
67+
npm install conventional-changelog-conventionalcommits
68+
npm install commitlint@latest
8269
83-
lint-pydocstyle:
70+
- name: Check commit message compliance of the recently pushed commit
71+
if: github.event_name == 'push'
72+
run: |
73+
./run-tests.sh --lint-commitlint HEAD~1 HEAD
74+
75+
- name: Check commit message compliance of the pull request
76+
if: github.event_name == 'pull_request'
77+
run: |
78+
./run-tests.sh --lint-commitlint ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.number }}
79+
80+
lint-flake8:
8481
runs-on: ubuntu-24.04
8582
steps:
8683
- name: Checkout
@@ -91,13 +88,13 @@ jobs:
9188
with:
9289
python-version: "3.12"
9390

94-
- name: Check compliance with Python docstring conventions
91+
- name: Check compliance with pep8, pyflakes and circular complexity
9592
run: |
9693
pip install --upgrade pip
97-
pip install pydocstyle
98-
./run-tests.sh --check-pydocstyle
94+
pip install flake8
95+
./run-tests.sh --lint-flake8
9996
100-
lint-check-manifest:
97+
lint-manifest:
10198
runs-on: ubuntu-24.04
10299
steps:
103100
- name: Checkout
@@ -112,9 +109,9 @@ jobs:
112109
run: |
113110
pip install --upgrade pip
114111
pip install check-manifest
115-
./run-tests.sh --check-manifest
112+
./run-tests.sh --lint-manifest
116113
117-
docs-sphinx:
114+
lint-pydocstyle:
118115
runs-on: ubuntu-24.04
119116
steps:
120117
- name: Checkout
@@ -125,19 +122,22 @@ jobs:
125122
with:
126123
python-version: "3.12"
127124

128-
- name: Install system dependencies
125+
- name: Check compliance with Python docstring conventions
129126
run: |
130-
sudo apt-get update -y
131-
sudo apt install libcurl4-openssl-dev libssl-dev
132-
sudo apt-get install libgnutls28-dev
127+
pip install --upgrade pip
128+
pip install pydocstyle
129+
./run-tests.sh --lint-pydocstyle
133130
134-
- name: Install Python dependencies
135-
run: |
136-
pip install --upgrade pip 'setuptools<81' py
137-
pip install -e .[all]
131+
lint-shellcheck:
132+
runs-on: ubuntu-24.04
133+
steps:
134+
- name: Checkout
135+
uses: actions/checkout@v4
138136

139-
- name: Run Sphinx documentation with doctests
140-
run: ./run-tests.sh --check-sphinx
137+
- name: Runs shell script static analysis
138+
run: |
139+
sudo apt-get install shellcheck
140+
./run-tests.sh --lint-shellcheck
141141
142142
python-tests:
143143
runs-on: ubuntu-24.04
@@ -161,7 +161,7 @@ jobs:
161161
pip install -e .[all]
162162
163163
- name: Run pytest
164-
run: ./run-tests.sh --check-pytest
164+
run: ./run-tests.sh --python-tests
165165

166166
- name: Codecov Coverage
167167
if: matrix.python-version == 3.12

run-tests.sh

Lines changed: 69 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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
1212
export 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

128146
if [ $# -eq 0 ]; then
129-
check_all
147+
all
130148
exit 0
131149
fi
132150

133151
arg="$1"
134152
case $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 ;;
144164
esac

0 commit comments

Comments
 (0)