tools: add shell_lint target to lint .sh files

- update docker image to install shellcheck
- fix lint errors in files
This commit is contained in:
Arthur Meyre
2021-09-21 10:00:34 +02:00
parent e11570e973
commit 1a340e111e
9 changed files with 29 additions and 16 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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/.."

View File

@@ -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."

View File

@@ -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

View File

@@ -1,6 +1,6 @@
#!/bin/bash
if [[ `uname` == "Darwin" ]]; then
if [[ $(uname) == "Darwin" ]]; then
sysctl -n hw.logicalcpu
else
nproc

View File

@@ -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}"

View File

@@ -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

View File

@@ -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