Skip to content

Commit

Permalink
Add shell script linter to pre-commit and CI (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsuok authored Oct 10, 2022
1 parent 9d2cd20 commit 406df15
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,11 @@ jobs:
uses: pre-commit/[email protected]
with:
extra_args: end-of-file-fixer --all-files
lint-shell-script:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: lint
uses: pre-commit/[email protected]
with:
extra_args: shellcheck --all-files
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# shellcheck disable=SC1091
. "$(dirname "$0")/_/husky.sh"

pre-commit run && \
Expand Down
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: requirements-txt-fixer
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.8.0
hooks:
- id: shellcheck
2 changes: 1 addition & 1 deletion deployment/serve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# container only. The script takes any number of gunicorn arguments
# passed in as a string.

nohup nginx -g "daemon off;" & gunicorn -b 0.0.0.0:5000 -t 600 "explainaboard_web.__main__:create_app()" $1
nohup nginx -g "daemon off;" & gunicorn -b 0.0.0.0:5000 -t 600 "explainaboard_web.__main__:create_app()" "$1"
14 changes: 8 additions & 6 deletions openapi/gen_api_layer.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# Generates API layer code for backend and frontend based on openapi.yaml
# reference: https://stackoverflow.com/a/47554626

Expand All @@ -7,19 +9,19 @@ set -e
# three modes: generate frontend only, backend only and both
mode=$1
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
project_root=`dirname $script_dir`
project_root=$(dirname "$script_dir")

OPENAPI_PATH="openapi"
BACKEND_GEN_PATH="backend/src/gen"
FRONTEND_GEN_PATH="frontend/src/clients/openapi"

if ! [ `which curl` ]; then
if ! [ "$(which curl)" ]; then
echo "ERROR: curl not found. Please install curl command."
exit 1
fi

# download codegen cli if not exists
cd $script_dir
cd "$script_dir"
if [ ! -f swagger-codegen-cli-3.0.29.jar ]; then
curl -L -O https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.29/swagger-codegen-cli-3.0.29.jar
fi
Expand All @@ -29,10 +31,10 @@ fi
if [[ $mode == "backend" || $mode == "project" ]]; then
# remove src/gen if exists and generate code
# we also create a link to src/impl in src/gen which contains our own implementation
cd $project_root && rm -rf $BACKEND_GEN_PATH && \
cd "$project_root" && rm -rf $BACKEND_GEN_PATH && \
mkdir -p $BACKEND_GEN_PATH/explainaboard_web && \
cd $BACKEND_GEN_PATH/explainaboard_web/ && \
ln -sf ../../impl/ && \
ln -sf ../../impl/ . && \
cd ../../../.. && \
java -jar $OPENAPI_PATH/swagger-codegen-cli-3.0.29.jar generate \
-i $OPENAPI_PATH/openapi.yaml \
Expand All @@ -49,7 +51,7 @@ fi

# frontend
if [[ $mode == "frontend" || $mode == "project" ]]; then
cd $project_root && rm -rf $FRONTEND_GEN_PATH && \
cd "$project_root" && rm -rf $FRONTEND_GEN_PATH && \
java -jar $OPENAPI_PATH/swagger-codegen-cli-3.0.29.jar generate \
-i $OPENAPI_PATH/openapi.yaml \
-l typescript-fetch \
Expand Down

0 comments on commit 406df15

Please sign in to comment.