Skip to content

Commit 1f24d95

Browse files
committed
ci(run-tests): add usage help and refactor options (#516)
1 parent 5e92a2f commit 1f24d95

2 files changed

Lines changed: 116 additions & 95 deletions

File tree

.github/workflows/ci.yml

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,41 @@
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
18+
- name: Setup Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
2222

23-
- name: Install commitlint
23+
- name: Install system dependencies
2424
run: |
25-
npm install conventional-changelog-conventionalcommits
26-
npm install commitlint@latest
25+
sudo apt-get update -y
26+
sudo apt-get install python3-dev graphviz libgraphviz-dev pkg-config uuid-dev
2727
28-
- name: Check commit message compliance of the recently pushed commit
29-
if: github.event_name == 'push'
28+
- name: Install system dependencies
3029
run: |
31-
./run-tests.sh --check-commitlint HEAD~1 HEAD
30+
sudo apt-get update -y
31+
sudo apt install libcurl4-openssl-dev libssl-dev
32+
sudo apt-get install libgnutls28-dev
3233
33-
- name: Check commit message compliance of the pull request
34-
if: github.event_name == 'pull_request'
34+
- name: Install Python dependencies
3535
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
36+
pip install -e .[docs,kubernetes]
4337
44-
- name: Runs shell script static analysis
45-
run: |
46-
sudo apt-get install shellcheck
47-
./run-tests.sh --check-shellcheck
38+
- name: Run Sphinx documentation with doctests
39+
run: ./run-tests.sh --docs-sphinx
4840

49-
lint-black:
41+
format-black:
5042
runs-on: ubuntu-24.04
5143
steps:
5244
- name: Checkout
@@ -60,25 +52,35 @@ jobs:
6052
- name: Check Python code formatting
6153
run: |
6254
pip install black
63-
./run-tests.sh --check-black
55+
./run-tests.sh --format-black
6456
65-
lint-flake8:
57+
lint-commitlint:
6658
runs-on: ubuntu-24.04
6759
steps:
6860
- name: Checkout
6961
uses: actions/checkout@v4
70-
71-
- name: Setup Python
72-
uses: actions/setup-python@v5
7362
with:
74-
python-version: "3.12"
63+
fetch-depth: 0
7564

76-
- name: Check compliance with pep8, pyflakes and circular complexity
65+
- name: Setup Node
66+
uses: actions/setup-node@v4
67+
68+
- name: Install commitlint
7769
run: |
78-
pip install flake8
79-
./run-tests.sh --check-flake8
70+
npm install conventional-changelog-conventionalcommits
71+
npm install commitlint@latest
8072
81-
lint-pydocstyle:
73+
- name: Check commit message compliance of the recently pushed commit
74+
if: github.event_name == 'push'
75+
run: |
76+
./run-tests.sh --lint-commitlint HEAD~1 HEAD
77+
78+
- name: Check commit message compliance of the pull request
79+
if: github.event_name == 'pull_request'
80+
run: |
81+
./run-tests.sh --lint-commitlint ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.number }}
82+
83+
lint-flake8:
8284
runs-on: ubuntu-24.04
8385
steps:
8486
- name: Checkout
@@ -89,12 +91,12 @@ jobs:
8991
with:
9092
python-version: "3.12"
9193

92-
- name: Check compliance with Python docstring conventions
94+
- name: Check compliance with pep8, pyflakes and circular complexity
9395
run: |
94-
pip install pydocstyle
95-
./run-tests.sh --check-pydocstyle
96+
pip install flake8
97+
./run-tests.sh --lint-flake8
9698
97-
lint-check-manifest:
99+
lint-manifest:
98100
runs-on: ubuntu-24.04
99101
steps:
100102
- name: Checkout
@@ -108,9 +110,9 @@ jobs:
108110
- name: Check Python manifest completeness
109111
run: |
110112
pip install check-manifest
111-
./run-tests.sh --check-manifest
113+
./run-tests.sh --lint-manifest
112114
113-
docs-sphinx:
115+
lint-pydocstyle:
114116
runs-on: ubuntu-24.04
115117
steps:
116118
- name: Checkout
@@ -121,23 +123,21 @@ jobs:
121123
with:
122124
python-version: "3.12"
123125

124-
- name: Install system dependencies
126+
- name: Check compliance with Python docstring conventions
125127
run: |
126-
sudo apt-get update -y
127-
sudo apt-get install python3-dev graphviz libgraphviz-dev pkg-config uuid-dev
128+
pip install pydocstyle
129+
./run-tests.sh --lint-pydocstyle
128130
129-
- name: Install system dependencies
130-
run: |
131-
sudo apt-get update -y
132-
sudo apt install libcurl4-openssl-dev libssl-dev
133-
sudo apt-get install libgnutls28-dev
131+
lint-shellcheck:
132+
runs-on: ubuntu-24.04
133+
steps:
134+
- name: Checkout
135+
uses: actions/checkout@v4
134136

135-
- name: Install Python dependencies
137+
- name: Runs shell script static analysis
136138
run: |
137-
pip install -e .[docs,kubernetes]
138-
139-
- name: Run Sphinx documentation with doctests
140-
run: ./run-tests.sh --check-sphinx
139+
sudo apt-get install shellcheck
140+
./run-tests.sh --lint-shellcheck
141141
142142
python-tests:
143143
runs-on: ubuntu-24.04
@@ -165,7 +165,7 @@ jobs:
165165
pip install -e .[cwl,docs,kubernetes,snakemake,tests,yadage]
166166
167167
- name: Run pytest
168-
run: ./run-tests.sh --check-pytest
168+
run: ./run-tests.sh --python-tests
169169

170170
- name: Codecov Coverage
171171
if: matrix.python-version == '3.12'

run-tests.sh

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
#!/usr/bin/env bash
22
#
33
# This file is part of REANA.
4-
# Copyright (C) 2018, 2020, 2021, 2024 CERN.
4+
# Copyright (C) 2018, 2020, 2021, 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.
88

99
set -o errexit
1010
set -o nounset
1111

12-
check_commitlint () {
12+
docs_sphinx() {
13+
sphinx-build -qnNW docs docs/_build/html
14+
}
15+
16+
format_black() {
17+
black --check .
18+
}
19+
20+
lint_commitlint() {
1321
from=${2:-master}
1422
to=${3:-HEAD}
1523
pr=${4:-[0-9]+}
16-
npx commitlint --from="$from" --to="$to"
24+
if command -v commitlint > /dev/null 2>&1; then
25+
commitlint --from="$from" --to="$to"
26+
else
27+
npx commitlint --from="$from" --to="$to"
28+
fi
1729
found=0
1830
while IFS= read -r line; do
1931
commit_hash=$(echo "$line" | cut -d ' ' -f 1)
@@ -31,7 +43,7 @@ check_commitlint () {
3143
# (iii) check absence of merge commits in feature branches
3244
if [ "$commit_number_of_parents" -gt 1 ]; then
3345
if echo "$commit_title" | grep -qE "^chore\(.*\): merge "; then
34-
break # skip checking maint-to-master merge commits
46+
break # skip checking maint-to-master merge commits
3547
else
3648
echo "✖ Merge commits are not allowed in feature branches: $commit_title"
3749
found=1
@@ -43,59 +55,68 @@ check_commitlint () {
4355
fi
4456
}
4557

46-
check_shellcheck () {
47-
find . -name "*.sh" -exec shellcheck {} \+
48-
}
49-
50-
check_pydocstyle () {
51-
pydocstyle reana_commons
58+
lint_flake8() {
59+
flake8 .
5260
}
5361

54-
check_black () {
55-
black --check .
62+
lint_manifest() {
63+
check-manifest
5664
}
5765

58-
check_flake8 () {
59-
flake8 .
66+
lint_pydocstyle() {
67+
pydocstyle reana_commons
6068
}
6169

62-
check_manifest () {
63-
check-manifest
70+
lint_shellcheck() {
71+
find . -name "*.sh" -exec shellcheck {} \+
6472
}
6573

66-
check_sphinx () {
67-
sphinx-build -qnNW docs docs/_build/html
74+
python_tests() {
75+
pytest
6876
}
6977

70-
check_pytest () {
71-
pytest
78+
all() {
79+
docs_sphinx
80+
format_black
81+
lint_commitlint
82+
lint_flake8
83+
lint_manifest
84+
lint_pydocstyle
85+
lint_shellcheck
86+
python_tests
7287
}
7388

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
89+
help() {
90+
echo "Usage: $0 [options]"
91+
echo "Options:"
92+
echo " --all Perform all checks [default]"
93+
echo " --docs-sphinx Check Sphinx docs build"
94+
echo " --format-black Check formatting of Python code"
95+
echo " --help Display this help message"
96+
echo " --lint-commitlint Check linting of commit messages"
97+
echo " --lint-flake8 Check linting of Python code"
98+
echo " --lint-manifest Check linting of Python manifest"
99+
echo " --lint-pydocstyle Check linting of Python docstrings"
100+
echo " --lint-shellcheck Check linting of shell scripts"
101+
echo " --python-tests Check Python test suite"
83102
}
84103

85104
if [ $# -eq 0 ]; then
86-
check_all
105+
all
87106
exit 0
88107
fi
89108

90109
arg="$1"
91110
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;;
111+
--all) all ;;
112+
--help) help ;;
113+
--docs-sphinx) docs_sphinx ;;
114+
--format-black) format_black ;;
115+
--lint-commitlint) lint_commitlint "$@" ;;
116+
--lint-flake8) lint_flake8 ;;
117+
--lint-manifest) lint_manifest ;;
118+
--lint-pydocstyle) lint_pydocstyle ;;
119+
--lint-shellcheck) lint_shellcheck ;;
120+
--python-tests) python_tests ;;
121+
*) echo "[ERROR] Invalid argument '$arg'. Exiting." && help && exit 1 ;;
101122
esac

0 commit comments

Comments
 (0)