Skip to content

Commit

Permalink
ci(shfmt): add shfmt code formatting checks (reanahub#838)
Browse files Browse the repository at this point in the history
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 reanahub#836
  • Loading branch information
tiborsimko committed Nov 13, 2024
1 parent 8e878f2 commit df67510
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 38 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace=true

[*.{css,html,js,json,scss,yaml,yml}]
indent_size=2

[*.go]
indent_style = tab
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,14 @@ jobs:
run: |
npm install prettier --global
./run-tests.sh --check-prettier
lint-shfmt:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check shell script code fomatting
run: |
sudo apt-get install shfmt
./run-tests.sh --check-shfmt
60 changes: 33 additions & 27 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
set -o errexit
set -o nounset

check_commitlint () {
check_commitlint() {
from=${2:-master}
to=${3:-HEAD}
pr=${4:-[0-9]+}
Expand All @@ -31,7 +31,7 @@ check_commitlint () {
# (iii) check absence of merge commits in feature branches
if [ "$commit_number_of_parents" -gt 1 ]; then
if echo "$commit_title" | grep -qP "^chore\(.*\): merge "; then
break # skip checking maint-to-master merge commits
break # skip checking maint-to-master merge commits
else
echo "✖ Merge commits are not allowed in feature branches: $commit_title"
found=1
Expand All @@ -43,51 +43,55 @@ check_commitlint () {
fi
}

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

check_black () {
check_black() {
black --check .
}

check_flake8 () {
check_flake8() {
flake8 .
}

check_pydocstyle () {
check_pydocstyle() {
pydocstyle reana
}

check_manifest () {
check_manifest() {
check-manifest
}

check_sphinx () {
check_sphinx() {
sphinx-build -qnNW docs docs/_build/html
}

check_pytest () {
check_pytest() {
pytest
}

check_helm () {
check_helm() {
helm lint helm/reana
}

check_yamllint () {
check_yamllint() {
yamllint .
}

check_markdownlint () {
check_markdownlint() {
markdownlint-cli2 "**/*.md"
}

check_prettier () {
check_prettier() {
prettier -c .
}

check_all () {
check_shfmt() {
shfmt -d .
}

check_all() {
check_commitlint
check_shellcheck
check_black
Expand All @@ -100,6 +104,7 @@ check_all () {
check_yamllint
check_markdownlint
check_prettier
check_shfmt
}

if [ $# -eq 0 ]; then
Expand All @@ -109,17 +114,18 @@ fi

arg="$1"
case $arg in
--check-commitlint) check_commitlint "$@";;
--check-shellcheck) check_shellcheck;;
--check-black) check_black;;
--check-flake8) check_flake8;;
--check-pydocstyle) check_pydocstyle;;
--check-manifest) check_manifest;;
--check-sphinx) check_sphinx;;
--check-pytest) check_pytest;;
--check-helm) check_helm;;
--check-yamllint) check_yamllint;;
--check-markdownlint) check_markdownlint;;
--check-prettier) check_prettier;;
*) echo "[ERROR] Invalid argument '$arg'. Exiting." && exit 1;;
--check-commitlint) check_commitlint "$@" ;;
--check-shellcheck) check_shellcheck ;;
--check-black) check_black ;;
--check-flake8) check_flake8 ;;
--check-pydocstyle) check_pydocstyle ;;
--check-manifest) check_manifest ;;
--check-sphinx) check_sphinx ;;
--check-pytest) check_pytest ;;
--check-helm) check_helm ;;
--check-yamllint) check_yamllint ;;
--check-markdownlint) check_markdownlint ;;
--check-prettier) check_prettier ;;
--check-shfmt) check_shfmt ;;
*) echo "[ERROR] Invalid argument '$arg'. Exiting." && exit 1 ;;
esac
10 changes: 4 additions & 6 deletions scripts/create-admin-user.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#
# This file is part of REANA.
# Copyright (C) 2020 CERN.
# Copyright (C) 2020, 2024 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -19,8 +19,7 @@ admin_email=$3
admin_password=$4

# Wait for database to be ready
while [ "0" -ne "$(kubectl -n "${kubernetes_namespace}" exec "deployment/${instance_name}-db" -- pg_isready -U reana -h 127.0.0.1 -p 5432 &> /dev/null && echo $? || echo 1)" ]
do
while [ "0" -ne "$(kubectl -n "${kubernetes_namespace}" exec "deployment/${instance_name}-db" -- pg_isready -U reana -h 127.0.0.1 -p 5432 &>/dev/null && echo $? || echo 1)" ]; do
echo "Waiting for deployment/${instance_name}-db to be ready..."
sleep 5
done
Expand All @@ -30,16 +29,15 @@ kubectl -n "${kubernetes_namespace}" exec "deployment/${instance_name}-server" -

# Create admin user
if ! admin_access_token=$(kubectl -n "${kubernetes_namespace}" exec "deployment/${instance_name}-server" -c rest-api -- \
flask reana-admin create-admin-user --email "${admin_email}" --password "${admin_password}")
then
flask reana-admin create-admin-user --email "${admin_email}" --password "${admin_password}"); then
# Output failures
echo "${admin_access_token}"
exit 1
fi

# Add token to secrets
kubectl -n "${kubernetes_namespace}" create secret generic "${instance_name}"-admin-access-token \
--from-literal=ADMIN_ACCESS_TOKEN="${admin_access_token}"
--from-literal=ADMIN_ACCESS_TOKEN="${admin_access_token}"

# Success!
echo "Success! You may now set the following environment variables:"
Expand Down
9 changes: 4 additions & 5 deletions scripts/prefetch-images.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#
# This file is part of REANA.
# Copyright (C) 2020, 2021, 2022, 2023 CERN.
# Copyright (C) 2020, 2021, 2022, 2023, 2024 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -19,8 +19,7 @@ for image in \
docker.io/reanahub/reana-workflow-engine-cwl:0.9.3 \
docker.io/reanahub/reana-workflow-engine-serial:0.9.3 \
docker.io/reanahub/reana-workflow-engine-snakemake:0.9.3 \
docker.io/reanahub/reana-workflow-engine-yadage:0.9.4 \
; do
docker pull $image
kind load docker-image $image
docker.io/reanahub/reana-workflow-engine-yadage:0.9.4; do
docker pull $image
kind load docker-image $image
done

0 comments on commit df67510

Please sign in to comment.