diff --git a/Makefile b/Makefile index 1202ad180..db4c2591d 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ pcc: --no-print-directory pcc_internal .PHONY: pcc -pcc_internal: check_python_format check_finalize_nb python_linting mypy_ci pydocstyle +pcc_internal: check_python_format check_finalize_nb python_linting mypy_ci pydocstyle shell_lint .PHONY: pcc_internal pytest: @@ -203,3 +203,9 @@ upgrade_py_deps: test_codeblocks: poetry run python ./script/make_utils/test_md_python_code.py --md_dir docs/ .PHONY: test_codeblocks + +# From https://stackoverflow.com/a/63523300 for the find command +shell_lint: + find \( -path "./.venv" -o -path "./.docker_venv" \) -prune -o -type f -name "*.sh" -print | \ + xargs shellcheck +.PHONY: shell_lint diff --git a/docker/Dockerfile.concretefhe-env b/docker/Dockerfile.concretefhe-env index 78a1015d9..f2a126fe6 100644 --- a/docker/Dockerfile.concretefhe-env +++ b/docker/Dockerfile.concretefhe-env @@ -9,7 +9,8 @@ RUN apt-get update && apt-get upgrade --no-install-recommends -y && \ python-is-python3 \ git \ graphviz* \ - pandoc && \ + pandoc \ + shellcheck && \ rm -rf /var/lib/apt/lists/* && \ pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir poetry diff --git a/docker/build_release_image.sh b/docker/build_release_image.sh index 1b0a23683..8ad9c8677 100755 --- a/docker/build_release_image.sh +++ b/docker/build_release_image.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -CURR_DIR=$(dirname $0) +CURR_DIR=$(dirname "$0") DOCKER_BUILDKIT=1 docker build --pull --no-cache -f "$CURR_DIR/Dockerfile.release" \ -t concretefhe-release "$CURR_DIR/.." diff --git a/script/actions_utils/container_timestamp_check.sh b/script/actions_utils/container_timestamp_check.sh index e6cda5bcd..7337102b0 100755 --- a/script/actions_utils/container_timestamp_check.sh +++ b/script/actions_utils/container_timestamp_check.sh @@ -38,7 +38,7 @@ do *) echo "Unknown param : $1" - exit -1 + exit 1 ;; esac shift @@ -64,8 +64,8 @@ jq -rc '.[] | select(.metadata.container.tags[] | contains("latest")).updated_at echo "Base timestamp: ${BASE_IMG_TIMESTAMP}" echo "Env timestamp: ${ENV_IMG_TIMESTAMP}" -BASE_IMG_DATE=$(date -d ${BASE_IMG_TIMESTAMP} +%s) -ENV_IMG_DATE=$(date -d ${ENV_IMG_TIMESTAMP} +%s) +BASE_IMG_DATE=$(date -d "${BASE_IMG_TIMESTAMP}" +%s) +ENV_IMG_DATE=$(date -d "${ENV_IMG_TIMESTAMP}" +%s) echo "Base epoch: ${BASE_IMG_DATE}" echo "Env epoch: ${ENV_IMG_DATE}" @@ -76,7 +76,7 @@ if [[ "${BASE_IMG_DATE}" -ge "${ENV_IMG_DATE}" ]]; then -X POST \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token ${TOKEN}" \ - https://api.github.com/repos/${ORG_REPO}/dispatches \ + https://api.github.com/repos/"${ORG_REPO}"/dispatches \ -d "{\"event_type\":\"${EVENT_TYPE}\"}" else echo "Image up to date, nothing to do." diff --git a/script/actions_utils/coverage.sh b/script/actions_utils/coverage.sh index 216e31d87..90f400e2f 100755 --- a/script/actions_utils/coverage.sh +++ b/script/actions_utils/coverage.sh @@ -3,13 +3,13 @@ set -o pipefail set +e -CURR_DIR=`dirname $0` +CURR_DIR=$(dirname "$0") # Run diff-coverage if [[ "$1" == "" ]]; then - BB="origin/main" + export BB="origin/main" else - BB="origin/$1" + export BB="origin/$1" fi make coverage | tee diff-coverage.txt diff --git a/script/make_utils/ncpus.sh b/script/make_utils/ncpus.sh index 2c8cfb618..61590effd 100755 --- a/script/make_utils/ncpus.sh +++ b/script/make_utils/ncpus.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [[ `uname` == "Darwin" ]]; then +if [[ $(uname) == "Darwin" ]]; then sysctl -n hw.logicalcpu else nproc diff --git a/script/make_utils/upgrade_deps.sh b/script/make_utils/upgrade_deps.sh index e5b40e8bc..778cc9310 100755 --- a/script/make_utils/upgrade_deps.sh +++ b/script/make_utils/upgrade_deps.sh @@ -10,7 +10,9 @@ dev_file=$(mktemp --suffix=.txt) poetry show -o -t --no-dev | grep -v -e "--" | cut -d " " -f 1 | sed 's/$/\@latest/g' > "${no_dev_file}" poetry show -o -t | grep -v -e "--" | cut -d " " -f 1 | sed 's/$/\@latest/g' > "${all_file}" join -v1 -v2 "${all_file}" "${no_dev_file}" > "${dev_file}" +# shellcheck disable=SC2002 cat "${no_dev_file}" | xargs poetry add +# shellcheck disable=SC2002 cat "${dev_file}" | xargs poetry add --dev rm "${no_dev_file}" diff --git a/script/progress_tracker_utils/benchmark_and_publish_findings_in_docker.sh b/script/progress_tracker_utils/benchmark_and_publish_findings_in_docker.sh index 115d7f858..31e245a5e 100755 --- a/script/progress_tracker_utils/benchmark_and_publish_findings_in_docker.sh +++ b/script/progress_tracker_utils/benchmark_and_publish_findings_in_docker.sh @@ -3,9 +3,12 @@ # Run benchmarks while logging the intermediate results # Publish findings in the progress tracker -source /src/.docker_venv/bin/activate -if [[ "$?" != "0" ]]; then +set -e + +# shellcheck disable=SC1091 +if source /src/.docker_venv/bin/activate; then python3 -m venv /src/.docker_venv + # shellcheck disable=SC1091 source /src/.docker_venv/bin/activate cd /src/ && make setup_env fi @@ -27,6 +30,7 @@ if [ -f .env ] then # Set the last two environment variables in `.env` for the curl command below # (https://gist.github.com/mihow/9c7f559807069a03e302605691f85572) + # shellcheck disable=SC2002,SC2046 export $(cat .env | tail -n 2 | sed 's/#.*//g' | xargs -d '\n') fi diff --git a/script/source_format/format_python.sh b/script/source_format/format_python.sh index 3ef6c090c..294515ef3 100755 --- a/script/source_format/format_python.sh +++ b/script/source_format/format_python.sh @@ -30,16 +30,16 @@ do *) echo "Unknown param : $1" - exit -1 + exit 1 ;; esac shift done for SRC_DIR in "${DIRS[@]}"; do - isort --profile black ${CHECK} ${SRC_DIR} + isort --profile black "${CHECK}" "${SRC_DIR}" ((FAILURES+=$?)) - black -l 100 ${CHECK} ${SRC_DIR} + black -l 100 "${CHECK}" "${SRC_DIR}" ((FAILURES+=$?)) done