From 0d441a7e835c4bedeab79cff52063f343c1acbb9 Mon Sep 17 00:00:00 2001 From: David Wallace Date: Thu, 1 Feb 2024 14:32:24 +0100 Subject: [PATCH] ci: update and refactor rdmo-app script --- .github/rdmo-app-ci-script.sh | 44 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/.github/rdmo-app-ci-script.sh b/.github/rdmo-app-ci-script.sh index 8512fa2..be2cdc1 100755 --- a/.github/rdmo-app-ci-script.sh +++ b/.github/rdmo-app-ci-script.sh @@ -4,23 +4,23 @@ git clone https://$GITHUB_TOKEN@github.com/rdmorganiser/rdmo.git # need rdmo only for testing/config/settings git clone https://$GITHUB_TOKEN@github.com/rdmorganiser/rdmo-app.git -cd rdmo-app +cd rdmo-app || exit 1 python3 -m venv env source env/bin/activate pip install --upgrade pip setuptools pip install rdmo"[allauth]" # install and set-up plugin -cd .. +cd - || exit 1 pip install . cp rdmo_radar/sample.local.py rdmo-app/config/settings/local.py -PLUGIN=$(basename $(pwd)) +PLUGIN="$(basename "$(pwd)")" PLUGIN_NAME="${PLUGIN/rdmo-plugins-/}" # set up rdmo-app settings # write to rdmo-app/config/settings/__init__.py cp rdmo/testing/config/settings/* rdmo-app/config/settings -cd rdmo-app +cd rdmo-app || exit 1 # set up instance # python manage.py download_vendor_files # download front-end vendor files python manage.py migrate # initializes the database @@ -31,22 +31,20 @@ python manage.py loaddata -v 2 ../rdmo/testing/fixtures/* python manage.py check -# test PROJECT_EXPORTS setting -PROJECT_EXPORTS=$(python manage.py print_settings -f PROJECT_EXPORTS --format=value) -echo "Testing for presence of setting in django settings" -if [[ $PROJECT_EXPORTS == *"$PLUGIN_NAME"* ]]; then - echo "Plugin $PLUGIN_NAME is in PROJECT_EXPORTS.\n\t${PROJECT_EXPORTS}" -else - echo "Plugin $PLUGIN_NAME is not in PROJECT_EXPORTS.\n\t${PROJECT_EXPORTS}" - exit 1 -fi - -# test PROJECT_IMPORTS setting -PROJECT_IMPORTS=$(python manage.py print_settings -f PROJECT_IMPORTS --format=value) -echo "Testing for presence of setting in django settings" -if [[ $PROJECT_IMPORTS == *"$PLUGIN_NAME"* ]]; then - echo "Plugin $PLUGIN_NAME is in PROJECT_IMPORTS.\n\t${PROJECT_IMPORTS}" -else - echo "Plugin $PLUGIN_NAME is not in PROJECT_IMPORTS.\n\t${PROJECT_IMPORTS}" - exit 1 -fi +# function for testing presence of plugin name in a certain django setting +test_if_settings_contains_plugin () { + SETTING_NAME=$1 + SETTING_VALUE="$(python manage.py print_settings -f $SETTING_NAME --format=value)" + echo "Testing for presence of ${SETTING_NAME} setting in django settings" + if [[ ${SETTING_VALUE} == *"$PLUGIN_NAME"* ]]; then + echo -e "OK, Plugin $PLUGIN_NAME is in ${SETTING_NAME}.\n\t${SETTING_VALUE}" + else + echo -e "ERROR, Plugin $PLUGIN_NAME is not in ${SETTING_NAME}.\n\t${SETTING_VALUE}" + exit 1 + fi +} + +test_if_settings_contains_plugin "PROJECT_EXPORTS" + +test_if_settings_contains_plugin "PROJECT_IMPORTS" +