10.Test.bash 1.8 KB

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