From 555ca2e277471b075f9c6d85309b4401750d287d Mon Sep 17 00:00:00 2001 From: Wes Lambert Date: Mon, 9 May 2022 20:06:39 +0000 Subject: [PATCH] Update analyzer build/testing script to download necessary Python packages --- salt/sensoroni/files/analyzers/build.sh | 40 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/salt/sensoroni/files/analyzers/build.sh b/salt/sensoroni/files/analyzers/build.sh index 17e53c6a7..05f1ba8a2 100755 --- a/salt/sensoroni/files/analyzers/build.sh +++ b/salt/sensoroni/files/analyzers/build.sh @@ -1,15 +1,35 @@ #!/bin/bash -HOME_DIR=$(dirname "$0") -TARGET_DIR=${1:-.} +COMMAND=$1 -PATH=$PATH:/usr/local/bin +function ci() { + HOME_DIR=$(dirname "$0") + TARGET_DIR=${1:-.} -if ! which pytest &> /dev/null || ! which flake8 &> /dev/null ; then - echo "Missing dependencies. Consider running the following command:" - echo " python -m pip install flake8 pytest pytest-cov" - exit 1 + PATH=$PATH:/usr/local/bin + + if ! which pytest &> /dev/null || ! which flake8 &> /dev/null ; then + echo "Missing dependencies. Consider running the following command:" + echo " python -m pip install flake8 pytest pytest-cov" + exit 1 + fi + + flake8 "$TARGET_DIR" "--config=${HOME_DIR}/pytest.ini" + pytest "$TARGET_DIR" "--cov-config=${HOME_DIR}/pytest.ini" "--cov=$TARGET_DIR" --doctest-modules --cov-report=term --cov-fail-under=100 +} + +function download() { + ANALYZERS=$1 + if [[ $ANALYZERS = "all" ]]; then + ANALYZERS="*/" + fi + for ANALYZER in $ANALYZERS; do + docker exec -it so-sensoroni pip download -r /opt/sensoroni/analyzers/$ANALYZER/requirements.txt -d /opt/sensoroni/analyzers/$ANALYZER/source-packages + done +} + +if [[ "$COMMAND" == "download" ]]; then + download "$2" +else + ci fi - -flake8 "$TARGET_DIR" "--config=${HOME_DIR}/pytest.ini" -pytest "$TARGET_DIR" "--cov-config=${HOME_DIR}/pytest.ini" "--cov=$TARGET_DIR" --doctest-modules --cov-report=term --cov-fail-under=100