build.sh 3.12 KB
Newer Older
BO ZHANG's avatar
BO ZHANG committed
1
2
#!/bin/bash
echo "===================== prepare for installation ====================="
BO ZHANG's avatar
BO ZHANG committed
3
# show where I am
BO ZHANG's avatar
BO ZHANG committed
4
echo " > whoami"
BO ZHANG's avatar
BO ZHANG committed
5
whoami
BO ZHANG's avatar
BO ZHANG committed
6
echo " > uname -a"
BO ZHANG's avatar
BO ZHANG committed
7
uname -a
BO ZHANG's avatar
BO ZHANG committed
8
echo " > pwd"
BO ZHANG's avatar
BO ZHANG committed
9
pwd
BO ZHANG's avatar
BO ZHANG committed
10
echo " > ls -a"
BO ZHANG's avatar
BO ZHANG committed
11
12
ls -a

BO ZHANG's avatar
BO ZHANG committed
13
# define environment variables
BO ZHANG's avatar
BO ZHANG committed
14
15
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
16
export AUX_DIR="/nfsdata/users/csstpipeline/L1Pipeline/unittests/"
BO ZHANG's avatar
BO ZHANG committed
17

BO ZHANG's avatar
BO ZHANG committed
18
# show Python environment
BO ZHANG's avatar
BO ZHANG committed
19
echo " > which python"
BO ZHANG's avatar
BO ZHANG committed
20
which python
BO ZHANG's avatar
BO ZHANG committed
21
echo " > which pip"
BO ZHANG's avatar
BO ZHANG committed
22
which pip
BO ZHANG's avatar
BO ZHANG committed
23
echo " > python --version"
BO ZHANG's avatar
BO ZHANG committed
24
25
python --version

26
27
28
echo "===================== uninstall package ====================="
pip uninstall -y "$JOB_NAME"

BO ZHANG's avatar
BO ZHANG committed
29
echo "===================== install requirements ====================="
BO ZHANG's avatar
BO ZHANG committed
30
31
if [ -f "requirements.txt" ]; then
  pip install -r requirements.txt
BO ZHANG's avatar
BO ZHANG committed
32
33
34
  status_install_requirements=$?
else
  status_install_requirements=0
BO ZHANG's avatar
BO ZHANG committed
35
fi
BO ZHANG's avatar
BO ZHANG committed
36
37

echo "===================== install package ====================="
BO ZHANG's avatar
BO ZHANG committed
38
39
40
#if [ -f "install_local.sh" ]; then
#  sh install_local.sh
#else
BO ZHANG's avatar
BO ZHANG committed
41
  # default install script
BO ZHANG's avatar
BO ZHANG committed
42
43
44
45
46
#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
47
status_install=$?
BO ZHANG's avatar
BO ZHANG committed
48
#fi
BO ZHANG's avatar
BO ZHANG committed
49
50

echo "===================== show package info ====================="
BO ZHANG's avatar
BO ZHANG committed
51
echo " > pip show $JOB_NAME"
BO ZHANG's avatar
BO ZHANG committed
52
pip show $JOB_NAME
BO ZHANG's avatar
BO ZHANG committed
53

BO ZHANG's avatar
BO ZHANG committed
54
if [ "$JOB_NAME" != "csst_proto" ]; then
BO ZHANG's avatar
tweaks    
BO ZHANG committed
55
  echo "===================== download code style tests ====================="
56
57
  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
58
coverage run -m pytest --import-mode=importlib
BO ZHANG's avatar
BO ZHANG committed
59
status_unittest=$?
BO ZHANG's avatar
BO ZHANG committed
60
61
62
63

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

echo "===================== importability ====================="
67
68
69
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
tweaks    
BO ZHANG committed
70
  status_import=$?
BO ZHANG's avatar
BO ZHANG committed
71
  if [ "$status_import" != 0 ]; then
72
73
74
75
    echo "Import failed!"
  else
    echo "Import done!"
  fi
BO ZHANG's avatar
tweaks    
BO ZHANG committed
76
else
BO ZHANG's avatar
tweaks    
BO ZHANG committed
77
  status_import=0
BO ZHANG's avatar
BO ZHANG committed
78
fi
BO ZHANG's avatar
BO ZHANG committed
79

BO ZHANG's avatar
BO ZHANG committed
80
# the exit value is determined from unit tests
BO ZHANG's avatar
BO ZHANG committed
81
82
83
84
if [ "$status_install_requirements" != 0 ] \
  || [ "$status_install" != 0 ] \
  || [ "$status_import" != 0 ] \
  || [ "$status_unittest" != 0 ]; then
BO ZHANG's avatar
tweaks    
BO ZHANG committed
85
  echo "===================== TEST SUMMARY ====================="
BO ZHANG's avatar
BO ZHANG committed
86
  echo "Test failed!"
BO ZHANG's avatar
BO ZHANG committed
87
88
89
90
  echo "Install requirements: $status_install_requirements"
  echo "Install package: $status_install"
  echo "Importability status: $status_import"
  echo "Unit test status: $status_unittest"
BO ZHANG's avatar
BO ZHANG committed
91
92
  echo "===================== POST BUILD BELOW ====================="
  exit 1
BO ZHANG's avatar
BO ZHANG committed
93
else
BO ZHANG's avatar
tweaks    
BO ZHANG committed
94
  echo "===================== TEST SUMMARY ====================="
BO ZHANG's avatar
tweaks    
BO ZHANG committed
95
  echo "Test passed!"
BO ZHANG's avatar
BO ZHANG committed
96
97
98
99
  echo "Install requirements: $status_install_requirements"
  echo "Install package: $status_install"
  echo "Importability status: $status_import"
  echo "Unit test status: $status_unittest"
BO ZHANG's avatar
BO ZHANG committed
100
  echo "===================== POST BUILD BELOW ====================="
BO ZHANG's avatar
BO ZHANG committed
101
102
103
  exit 0
fi

BO ZHANG's avatar
BO ZHANG committed
104
105
106
# In Jenkins:
#!/bin/bash
#sh -c "$(curl -fsSL https://csst-tb.bao.ac.cn/code/csst-l1/csst_proto/-/raw/main/pipelines/build.sh)"