10.Test.bash 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. set -e
  2. #---------------------------------------------------------------------
  3. # args
  4. args_="
  5. export basePath=/root/temp/svn
  6. # "
  7. #----------------------------------------------
  8. # basePath
  9. if [ -z "$basePath" ]; then export basePath=$PWD/../../..; fi
  10. export devOpsPath="$PWD/.."
  11. #----------------------------------------------
  12. echo "#10.Test.bash -> #1 init test environment"
  13. bashFile="$devOpsPath/environment/build-bash__10.Test__#1.InitEnv.sh"
  14. if [ -f "$bashFile" ]; then
  15. echo "#10.Test.bash -> #1 init test environment - Run bash"
  16. sh "$bashFile"
  17. fi
  18. #----------------------------------------------
  19. echo "#10.Test.bash -> #2 find test projects and run test"
  20. docker run -i --rm \
  21. --net=host \
  22. --env LANG=C.UTF-8 \
  23. -v $NUGET_PATH:/root/.nuget \
  24. -v "$basePath":/root/code \
  25. -v "$basePath":"$basePath" \
  26. serset/dotnet:sdk-6.0 \
  27. bash -c "
  28. set -e
  29. cd /root/code
  30. #2.1 skip if no test projects
  31. if grep '<test>' -r --include *.csproj; then
  32. echo '#10.Test.bash -> got projects need to test'
  33. else
  34. echo '#10.Test.bash -> skip for no project needs to test'
  35. exit 0
  36. fi
  37. #2.2 run test
  38. echo '#10.Test.bash -> #2.2 run test...'
  39. for file in \$(grep -a '<test>' . -rl --include *.csproj)
  40. do
  41. echo '#10.Test.bash -> #2.2.1 run test:'
  42. echo run test for project \"\$file\"
  43. # run test
  44. cd /root/code
  45. cd \$(dirname \"\$file\")
  46. dotnet test
  47. done
  48. "
  49. #----------------------------------------------
  50. echo "#10.Test.bash -> #3 clean test environment"
  51. bashFile="$devOpsPath/environment/build-bash__10.Test__#3.CleanEnv.sh"
  52. if [ -f "$bashFile" ]; then
  53. echo "#10.Test.bash -> #1 Clean test environment - Run bash"
  54. sh "$bashFile"
  55. fi
  56. #----------------------------------------------
  57. echo '#10.Test.bash -> success!'