Skip to content

Commit e962077

Browse files
Michael BucharMichael Buchar
authored andcommitted
ci(shfmt): add shfmt code formatting checks (#654)
1 parent 12a9742 commit e962077

5 files changed

Lines changed: 100 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
@@ -24,3 +24,4 @@ The list of contributors in alphabetical order:
2424
- [Sinclert Perez](https://www.linkedin.com/in/sinclert)
2525
- [Tibor Simko](https://orcid.org/0000-0001-7202-5803)
2626
- [Vladyslav Moisieienkov](https://orcid.org/0000-0001-9717-0775)
27+
- [Michael Buchar](https://orcid.org/0009-0009-4804-8525)

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: 70 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,77 @@ 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_helm() {
115+
helm lint helm/reana
116+
}
117+
118+
check_yamllint() {
119+
yamllint .
120+
}
121+
122+
check_markdownlint() {
123+
markdownlint-cli2 "**/*.md"
124+
}
125+
126+
check_prettier() {
127+
prettier -c .
128+
}
129+
130+
check_shfmt() {
131+
shfmt -d .
132+
}
133+
134+
check_jsonlint() {
135+
find . -name "*.json" -exec jsonlint -q {} \+
136+
}
137+
138+
check_pytest() {
117139
clean_old_db_container
118140
start_db_container
119141
trap clean_old_db_container SIGINT SIGTERM SIGSEGV ERR
120142
pytest
121143
stop_db_container
122144
}
123145

124-
check_dockerfile () {
125-
docker run -i --rm docker.io/hadolint/hadolint:v2.12.0 < Dockerfile
146+
check_dockerfile() {
147+
docker run -i --rm docker.io/hadolint/hadolint:v2.12.0 <Dockerfile
126148
}
127149

128-
check_docker_build () {
150+
check_docker_build() {
129151
docker build -t docker.io/reanahub/reana-workflow-controller .
130152
}
131153

132-
check_all () {
154+
check_all() {
133155
check_commitlint
134156
check_shellcheck
135157
check_pydocstyle
@@ -141,6 +163,12 @@ check_all () {
141163
check_pytest
142164
check_dockerfile
143165
check_docker_build
166+
check_helm
167+
check_yamllint
168+
check_markdownlint
169+
check_prettier
170+
check_shfmt
171+
check_jsonlint
144172
}
145173

146174
if [ $# -eq 0 ]; then
@@ -150,16 +178,22 @@ fi
150178

151179
arg="$1"
152180
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;;
181+
--check-commitlint) check_commitlint "$@" ;;
182+
--check-shellcheck) check_shellcheck ;;
183+
--check-pydocstyle) check_pydocstyle ;;
184+
--check-black) check_black ;;
185+
--check-flake8) check_flake8 ;;
186+
--check-openapi-spec) check_openapi_spec ;;
187+
--check-manifest) check_manifest ;;
188+
--check-sphinx) check_sphinx ;;
189+
--check-pytest) check_pytest ;;
190+
--check-dockerfile) check_dockerfile ;;
191+
--check-docker-build) check_docker_build ;;
192+
--check-helm) check_helm ;;
193+
--check-yamllint) check_yamllint ;;
194+
--check-markdownlint) check_markdownlint ;;
195+
--check-prettier) check_prettier ;;
196+
--check-shfmt) check_shfmt ;;
197+
--check_jsonlint) check_jsonlint ;;
198+
*) echo "[ERROR] Invalid argument '$arg'. Exiting." && exit 1 ;;
165199
esac

0 commit comments

Comments
 (0)