github.com/Finschia/finschia-sdk@v0.48.1/scripts/module-tests.sh (about) 1 #!/usr/bin/env bash 2 3 # this script is used by Github CI to tranverse all modules an run module tests. 4 # the script expects a diff to be generated in order to skip some modules. 5 6 # Executes go module tests and merges the coverage profile. 7 # If GIT_DIFF variable is set then it's used to test if a module has any file changes - if 8 # it doesn't have any file changes then we will ignore the module tests. 9 execute_mod_tests() { 10 go_mod=$1; 11 mod_dir=$(dirname "$go_mod"); 12 mod_dir=${mod_dir:2}; # remove "./" prefix 13 root_dir=$(pwd); 14 15 # TODO: in the future we will need to disable it once we go into multi module setup, because 16 # we will have cross module dependencies. 17 if [ -n "$GIT_DIFF" ] && ! grep $mod_dir <<< $GIT_DIFF; then 18 echo ">>> ignoring module $mod_dir - no changes in the module"; 19 return; 20 fi; 21 22 echo ">>> running $go_mod tests" 23 cd $mod_dir; 24 go test -mod=readonly -timeout 30m -coverprofile=${root_dir}/${coverage_file}.tmp -covermode=atomic -tags='norace ledger test_ledger_mock' ./... 25 local ret=$? 26 echo "test return: " $ret; 27 cd -; 28 # strip mode statement 29 tail -n +1 ${coverage_file}.tmp >> ${coverage_file} 30 rm ${coverage_file}.tmp; 31 return $ret; 32 } 33 34 # GIT_DIFF=`git status --porcelain` 35 36 echo "GIT_DIFF: " $GIT_DIFF 37 38 coverage_file=coverage-go-submod-profile.out 39 return_val=0; 40 41 for f in $(find -name go.mod -not -path "./go.mod"); do 42 execute_mod_tests $f; 43 if [[ $? -ne 0 ]] ; then 44 return_val=2; 45 fi; 46 done 47 48 exit $return_val;