Skip to content

Commit dd2826f

Browse files
ci(shfmt): add shell script formatting checks (reanahub#301)
1 parent 381bdc7 commit dd2826f

File tree

4 files changed

+60
-24
lines changed

4 files changed

+60
-24
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_style = space
7+
insert_final_newline = true
8+
trim_trailing_whitespace=true
9+
10+
[*.{css,html,js,json,scss,yaml,yml}]
11+
indent_size = 2
12+
13+
[*.{py,sh}]
14+
indent_size = 4
15+
16+
[*.go]
17+
indent_style = tab

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ jobs:
114114
pip install check-manifest
115115
./run-tests.sh --check-manifest
116116
117+
format-shfmt:
118+
runs-on: ubuntu-24.04
119+
steps:
120+
- name: Checkout
121+
uses: actions/checkout@v4
122+
123+
- name: Check shell script code formatting
124+
run: |
125+
sudo apt-get install shfmt
126+
./run-tests.sh --check-shfmt
127+
117128
docs-sphinx:
118129
runs-on: ubuntu-24.04
119130
steps:

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ include docs/requirements.txt
1818
include pytest.ini
1919
include scripts/*.py
2020
exclude .readthedocs.yaml
21+
exclude .editorconfig
2122
prune docs/_build
2223
recursive-include badges *.json
2324
recursive-include docs *.py

run-tests.sh

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
set -o errexit
1010
set -o nounset
1111

12-
check_commitlint () {
12+
check_commitlint() {
1313
from=${2:-master}
1414
to=${3:-HEAD}
1515
pr=${4:-[0-9]+}
@@ -31,7 +31,7 @@ check_commitlint () {
3131
# (iii) check absence of merge commits in feature branches
3232
if [ "$commit_number_of_parents" -gt 1 ]; then
3333
if echo "$commit_title" | grep -qE "^chore\(.*\): merge "; then
34-
break # skip checking maint-to-master merge commits
34+
break # skip checking maint-to-master merge commits
3535
else
3636
echo "✖ Merge commits are not allowed in feature branches: $commit_title"
3737
found=1
@@ -43,43 +43,47 @@ check_commitlint () {
4343
fi
4444
}
4545

46-
check_shellcheck () {
46+
check_shellcheck() {
4747
find . -name "*.sh" -exec shellcheck {} \+
4848
}
4949

50-
check_pydocstyle () {
50+
check_pydocstyle() {
5151
pydocstyle reana_workflow_engine_cwl
5252
}
5353

54-
check_black () {
54+
check_black() {
5555
black --check .
5656
}
5757

58-
check_flake8 () {
58+
check_flake8() {
5959
flake8 .
6060
}
6161

62-
check_manifest () {
62+
check_manifest() {
6363
check-manifest
6464
}
6565

66-
check_sphinx () {
66+
check_sphinx() {
6767
sphinx-build -qnNW docs docs/_build/html
6868
}
6969

70-
check_pytest () {
70+
check_pytest() {
7171
pytest
7272
}
7373

74-
check_dockerfile () {
75-
docker run -i --rm docker.io/hadolint/hadolint:v2.12.0 < Dockerfile
74+
check_dockerfile() {
75+
docker run -i --rm docker.io/hadolint/hadolint:v2.12.0 <Dockerfile
7676
}
7777

78-
check_docker_build () {
78+
check_docker_build() {
7979
docker build -t docker.io/reanahub/reana-workflow-engine-cwl .
8080
}
8181

82-
check_all () {
82+
check_shfmt() {
83+
shfmt -d .
84+
}
85+
86+
check_all() {
8387
check_commitlint
8488
check_shellcheck
8589
check_pydocstyle
@@ -90,6 +94,7 @@ check_all () {
9094
check_pytest
9195
check_dockerfile
9296
check_docker_build
97+
check_shfmt
9398
}
9499

95100
if [ $# -eq 0 ]; then
@@ -99,15 +104,17 @@ fi
99104

100105
arg="$1"
101106
case $arg in
102-
--check-commitlint) check_commitlint "$@";;
103-
--check-shellcheck) check_shellcheck;;
104-
--check-pydocstyle) check_pydocstyle;;
105-
--check-black) check_black;;
106-
--check-flake8) check_flake8;;
107-
--check-manifest) check_manifest;;
108-
--check-sphinx) check_sphinx;;
109-
--check-pytest) check_pytest;;
110-
--check-dockerfile) check_dockerfile;;
111-
--check-docker-build) check_docker_build;;
112-
*) echo "[ERROR] Invalid argument '$arg'. Exiting." && exit 1;;
107+
--check-commitlint) check_commitlint "$@" ;;
108+
--check-shellcheck) check_shellcheck ;;
109+
--check-pydocstyle) check_pydocstyle ;;
110+
--check-black) check_black ;;
111+
--check-flake8) check_flake8 ;;
112+
--check-manifest) check_manifest ;;
113+
--check-sphinx) check_sphinx ;;
114+
--check-pytest) check_pytest ;;
115+
--check-dockerfile) check_dockerfile ;;
116+
--check-docker-build) check_docker_build ;;
117+
--check-shfmt) check_shfmt ;;
118+
--check-all) check_all ;;
119+
*) echo "[ERROR] Invalid argument '$arg'. Exiting." && exit 1 ;;
113120
esac

0 commit comments

Comments
 (0)