Skip to content

Commit 992506f

Browse files
author
Michael Buchar
committed
ci(shfmt): add shfmt code formatting checks (#654)
Also adds basic `.editorconfig` configuration for various languages since this is the primary way how to configure `shfmt` shell script source code formatting with respect to indentation. Closes #652
1 parent 12a9742 commit 992506f

5 files changed

Lines changed: 70 additions & 36 deletions

File tree

.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 fomatting
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:

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The list of contributors in alphabetical order:
1818
- [Lukas Heinrich](https://orcid.org/0000-0002-4048-7584)
1919
- [Marco Donadoni](https://orcid.org/0000-0003-2922-5505)
2020
- [Marco Vidal](https://orcid.org/0000-0002-9363-4971)
21+
- [Michael Buchar](https://orcid.org/0009-0009-4804-8525)
2122
- [Michael R. Crusoe](https://orcid.org/0000-0002-2961-9670)
2223
- [Parth Shandilya](https://github.com/ParthS007)
2324
- [Rokas Maciulaitis](https://orcid.org/0000-0003-1064-6967)

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ include Dockerfile
1515
include LICENSE
1616
include pytest.ini
1717
include docs/openapi.json
18+
include .editorconfig
1819
exclude .readthedocs.yaml
1920
prune docs/_build
2021
recursive-include docs *.py

run-tests.sh

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,42 @@ 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-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

146149
if [ $# -eq 0 ]; then
@@ -150,16 +153,17 @@ fi
150153

151154
arg="$1"
152155
case $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 ;;
165169
esac

0 commit comments

Comments
 (0)