Skip to content
build.sh 3.12 KiB
Newer Older
BO ZHANG's avatar
BO ZHANG committed
#!/bin/bash
echo "===================== prepare for installation ====================="
BO ZHANG's avatar
BO ZHANG committed
# show where I am
BO ZHANG's avatar
BO ZHANG committed
echo " > whoami"
BO ZHANG's avatar
BO ZHANG committed
whoami
BO ZHANG's avatar
BO ZHANG committed
echo " > uname -a"
BO ZHANG's avatar
BO ZHANG committed
uname -a
BO ZHANG's avatar
BO ZHANG committed
echo " > pwd"
BO ZHANG's avatar
BO ZHANG committed
pwd
BO ZHANG's avatar
BO ZHANG committed
echo " > ls -a"
BO ZHANG's avatar
BO ZHANG committed
ls -a

BO ZHANG's avatar
BO ZHANG committed
# define environment variables
BO ZHANG's avatar
BO ZHANG committed
export CSST_SIMS_C3="/nfsdata/share/csst_simulation_data/Cycle-3-SimuData/"
export CSST_SIMS_C5_2="/nfsdata/share/csst_simulation_data/Cycle-5-SimuData/"
BO ZHANG's avatar
BO ZHANG committed
export AUX_DIR="/nfsdata/users/csstpipeline/L1Pipeline/unittests/"
BO ZHANG's avatar
BO ZHANG committed
# show Python environment
BO ZHANG's avatar
BO ZHANG committed
echo " > which python"
BO ZHANG's avatar
BO ZHANG committed
which python
BO ZHANG's avatar
BO ZHANG committed
echo " > which pip"
BO ZHANG's avatar
BO ZHANG committed
which pip
BO ZHANG's avatar
BO ZHANG committed
echo " > python --version"
BO ZHANG's avatar
BO ZHANG committed
python --version

echo "===================== uninstall package ====================="
pip uninstall -y "$JOB_NAME"

BO ZHANG's avatar
BO ZHANG committed
echo "===================== install requirements ====================="
BO ZHANG's avatar
BO ZHANG committed
if [ -f "requirements.txt" ]; then
  pip install -r requirements.txt
BO ZHANG's avatar
BO ZHANG committed
  status_install_requirements=$?
else
  status_install_requirements=0
BO ZHANG's avatar
BO ZHANG committed
fi
BO ZHANG's avatar
BO ZHANG committed

echo "===================== install package ====================="
BO ZHANG's avatar
BO ZHANG committed
#if [ -f "install_local.sh" ]; then
#  sh install_local.sh
#else
BO ZHANG's avatar
BO ZHANG committed
  # default install script
BO ZHANG's avatar
BO ZHANG committed
#python setup.py install
rm -rf dist
python setup.py build_ext --inplace
python setup.py sdist
pip install dist/*.tar.gz --force-reinstall --no-deps
BO ZHANG's avatar
BO ZHANG committed
status_install=$?
BO ZHANG's avatar
BO ZHANG committed
#fi
BO ZHANG's avatar
BO ZHANG committed

echo "===================== show package info ====================="
BO ZHANG's avatar
BO ZHANG committed
echo " > pip show $JOB_NAME"
BO ZHANG's avatar
BO ZHANG committed
pip show $JOB_NAME
BO ZHANG's avatar
BO ZHANG committed
if [ "$JOB_NAME" != "csst_proto" ]; then
BO ZHANG's avatar
BO ZHANG committed
  echo "===================== download code style tests ====================="
  curl -O https://csst-tb.bao.ac.cn/code/csst-l1/csst_proto/-/raw/main/pipelines/test_codestyle.py
fi
BO ZHANG's avatar
BO ZHANG committed
coverage run -m pytest --import-mode=importlib
BO ZHANG's avatar
BO ZHANG committed
status_unittest=$?
BO ZHANG's avatar
BO ZHANG committed

echo "===================== make coverage ====================="
coverage report
coverage html
BO ZHANG's avatar
BO ZHANG committed
zip -q -r htmlcov.zip htmlcov
BO ZHANG's avatar
BO ZHANG committed

echo "===================== importability ====================="
if [ "$JOB_NAME" != "csst_common" ]; then
  echo " > try 'from $JOB_NAME.top_level_interface import *'"
  python -c "from $JOB_NAME.top_level_interface import *"
BO ZHANG's avatar
BO ZHANG committed
  status_import=$?
BO ZHANG's avatar
BO ZHANG committed
  if [ "$status_import" != 0 ]; then
    echo "Import failed!"
  else
    echo "Import done!"
  fi
BO ZHANG's avatar
BO ZHANG committed
else
BO ZHANG's avatar
BO ZHANG committed
  status_import=0
BO ZHANG's avatar
BO ZHANG committed
fi
BO ZHANG's avatar
BO ZHANG committed
# the exit value is determined from unit tests
BO ZHANG's avatar
BO ZHANG committed
if [ "$status_install_requirements" != 0 ] \
  || [ "$status_install" != 0 ] \
  || [ "$status_import" != 0 ] \
  || [ "$status_unittest" != 0 ]; then
BO ZHANG's avatar
BO ZHANG committed
  echo "===================== TEST SUMMARY ====================="
  echo "Test failed!"
BO ZHANG's avatar
BO ZHANG committed
  echo "Install requirements: $status_install_requirements"
  echo "Install package: $status_install"
  echo "Importability status: $status_import"
  echo "Unit test status: $status_unittest"
  echo "===================== POST BUILD BELOW ====================="
  exit 1
BO ZHANG's avatar
BO ZHANG committed
else
BO ZHANG's avatar
BO ZHANG committed
  echo "===================== TEST SUMMARY ====================="
BO ZHANG's avatar
BO ZHANG committed
  echo "Test passed!"
BO ZHANG's avatar
BO ZHANG committed
  echo "Install requirements: $status_install_requirements"
  echo "Install package: $status_install"
  echo "Importability status: $status_import"
  echo "Unit test status: $status_unittest"
  echo "===================== POST BUILD BELOW ====================="
BO ZHANG's avatar
BO ZHANG committed
# In Jenkins:
#!/bin/bash
#sh -c "$(curl -fsSL https://csst-tb.bao.ac.cn/code/csst-l1/csst_proto/-/raw/main/pipelines/build.sh)"