Skip to content

Commit

Permalink
scripts: add info message coloration
Browse files Browse the repository at this point in the history
* adds more info and colors for `scripts/bootstrap` scripts
* adds more info and colors for `scripts/setup` scripts
* adds more info and colors for `run-tests.sh` scripts

Co-Authored-by: Olivier DOSSMANN <[email protected]>
  • Loading branch information
blankoworld authored and rerowep committed Dec 13, 2019
1 parent fca4ea8 commit 3781ff7
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 65 deletions.
63 changes: 44 additions & 19 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,46 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

RED='\033[0;31m'
GREEN='\033[0;0;32m'
NC='\033[0m' # No Color
# COLORS for messages
NC='\033[0m' # Default color
INFO_COLOR='\033[1;97;44m' # Bold + white + blue background
SUCCESS_COLOR='\033[1;97;42m' # Bold + white + green background
ERROR_COLOR='\033[1;97;41m' # Bold + white + red background

display_error_message () {
echo -e "${RED}$1${NC}" 1>&2
PROGRAM=`basename $0`

# MESSAGES
msg() {
echo -e "${1}" 1>&2
}
# Display a colored message
# More info: https://misc.flogisoft.com/bash/tip_colors_and_formatting
# $1: choosen color
# $2: title
# $3: the message
colored_msg() {
msg "${1}[${2}]: ${3}${NC}"
}

info_msg() {
colored_msg "${INFO_COLOR}" "INFO" "${1}"
}

display_success_message () {
echo -e "${GREEN}$1${NC}" 1>&2
error_msg() {
colored_msg "${ERROR_COLOR}" "ERROR" "${1}"
}

display_error_message_and_exit () {
display_error_message "$1"
exit 1
error_msg+exit() {
error_msg "${1}" && exit 1
}

success_msg() {
colored_msg "${SUCCESS_COLOR}" "SUCCESS" "${1}"
}

# Displays program name
msg "PROGRAM: ${PROGRAM}"

# compile json files (resolve $ref)
pipenv run invenio utils compile_json ./rero_ils/modules/documents/jsonschemas/documents/document-minimal-v0.0.1_src.json -o ./rero_ils/modules/documents/jsonschemas/documents/document-minimal-v0.0.1.json
pipenv run invenio utils compile_json ./rero_ils/modules/documents/jsonschemas/documents/document-v0.0.1_src.json -o ./rero_ils/modules/documents/jsonschemas/documents/document-v0.0.1.json
Expand All @@ -50,34 +73,36 @@ if [ $# -eq 0 ]
pipenv check -i 36759
pipenv run flask utils check_json tests rero_ils/modules data
pipenv run flask utils check_license check_license_config.yml
display_success_message "Test pydocstyle:"
info_msg "Test pydocstyle:"
pipenv run pydocstyle rero_ils tests docs
display_success_message "Test isort:"
info_msg "Test isort:"
pipenv run isort -rc -c -df --skip ui
echo -e ${GREEN}Test useless imports:${NC}
pipenv run autoflake -c -r \
--remove-all-unused-imports \
--exclude ui \
--ignore-init-module-imports . \
&> /dev/null || \
display_error_message_and_exit "\nUse this command to check imports: \n\tautoflake --remove-all-unused-imports -r --exclude ui --ignore-init-module-imports .\n"
error_msg+exit "\nUse this command to check imports: \n\tautoflake --remove-all-unused-imports -r --exclude ui --ignore-init-module-imports .\n"

# syntax check for typescript
display_success_message "Syntax check for typescript:"
info_msg "Syntax check for typescript:"
CWD=`pwd`

display_success_message "Check-manifest:"
info_msg "Check-manifest:"
pipenv run check-manifest --ignore ".travis-*,docs/_build*"
display_success_message "Sphinx-build:"
info_msg "Sphinx-build:"
pipenv run sphinx-build -qnNW docs docs/_build/html
display_success_message "Tests:"
info_msg "Tests:"
pipenv run test
fi
if [ "$1" = "external" ]
then
export PYTEST_ADDOPTS="--cov-append -m "external""

display_success_message "External tests:"
info_msg "External tests:"
pipenv run test
exit 0
fi

success_msg "Perfect ${PROGRAM}! See you soon…"
exit 0
60 changes: 48 additions & 12 deletions scripts/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,47 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

NC='\033[0m' # Default color
COLORED='\033[1;97;44m' # Bold + white + blue background
NC='\033[0m' # Default color
INFO_COLOR='\033[1;97;44m' # Bold + white + blue background
SUCCESS_COLOR='\033[1;97;42m' # Bold + white + green background
ERROR_COLOR='\033[1;97;41m' # Bold + white + red background

PROGRAM=`basename $0`

set -e

# MESSAGES
msg() {
echo -e "${COLORED}${EMPHASIS}[INFO]${NC}${COLORED}: ${1}${NC}" 1>&2
echo -e "${1}" 1>&2
}
# Display a colored message
# More info: https://misc.flogisoft.com/bash/tip_colors_and_formatting
# $1: choosen color
# $2: title
# $3: the message
colored_msg() {
msg "${1}[${2}]: ${3}${NC}"
}

info_msg() {
colored_msg "${INFO_COLOR}" "INFO" "${1}"
}

error_msg() {
colored_msg "${ERROR_COLOR}" "ERROR" "${1}"
}

error_msg+exit() {
error_msg "${1}" && exit 1
}

success_msg() {
colored_msg "${SUCCESS_COLOR}" "SUCCESS" "${1}"
}

# Displays program name
msg "PROGRAM: ${PROGRAM}"

# The real bootstrap script starts 20 lines below ;-)
flags=()
deploy=false
Expand Down Expand Up @@ -64,37 +96,41 @@ fi
# pipenv --rm; pipenv install --sequential

# install the application and all the dependencies
msg "Install with command: ${cmd} ${flags[@]}"
info_msg "Install with command: ${cmd} ${flags[@]}"
${cmd} ${flags[@]}

# to avoid IPython dependency problem on Mac OS X
if [ "$(uname -s)" == "Darwin" ]; then
msg "Install 'appnope' for Mac OS X"
info_msg "Install 'appnope' for Mac OS X"
pipenv run pip install appnope
fi

# install assets utils
virtualenv_path=`pipenv --venv`
msg "Install npm assets utils in: ${virtualenv_path}"
info_msg "Install npm assets utils in: ${virtualenv_path}"
pipenv run npm i npm@latest -g --prefix "${virtualenv_path}" && pipenv run npm install --prefix "${virtualenv_path}" --silent -g [email protected] [email protected] [email protected] [email protected] @angular/[email protected] yarn

# collect static files and compile html/css assets

# ------------------------------------------------
# install the npm dependencies
msg "Install npm dependencies"
info_msg "Install npm dependencies"
pipenv run invenio npm
msg "Search static folder location"
info_msg "Search static folder location"
static_folder=$(pipenv run invenio shell --no-term-title -c "print('static_folder:%s' % app.static_folder)"|grep static_folder| cut -d: -f2-)
msg "Install static folder npm dependencies in: ${static_folder}"
info_msg "Install static folder npm dependencies in: ${static_folder}"
pipenv run npm install --prefix "${static_folder}"

# build the web assets
msg "Build web assets: collect"
info_msg "Build web assets: collect"
pipenv run invenio collect -v
msg "Build web assets: check (build command)"
info_msg "Build web assets: check (build command)"
pipenv run invenio assets build

# compile json files (resolve $ref)
info_msg "Compile JSON files to resolve \$ref"
echo
pipenv run invenio utils compile_json ./rero_ils/modules/documents/jsonschemas/documents/document-minimal-v0.0.1_src.json -o ./rero_ils/modules/documents/jsonschemas/documents/document-minimal-v0.0.1.json
pipenv run invenio utils compile_json ./rero_ils/modules/documents/jsonschemas/documents/document-v0.0.1_src.json -o ./rero_ils/modules/documents/jsonschemas/documents/document-v0.0.1.json

success_msg "${PROGRAM} finished!"
exit 0
Loading

0 comments on commit 3781ff7

Please sign in to comment.