21.change-to-next-version.bash 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. set -e
  2. # export versionSuffix='.1234.preview'
  3. # bash 21.change-to-next-version.bash
  4. #---------------------------------------------------------------------
  5. # args
  6. args_="
  7. export versionSuffix=' '
  8. # "
  9. # remove spaces
  10. versionSuffix=${versionSuffix// /}
  11. #----------------------------------------------
  12. # curPath
  13. curPath=$PWD
  14. cd $curPath/../../..
  15. export basePath=$PWD
  16. cd $curPath
  17. #----------------------------------------------
  18. echo "#1 get appVersion"
  19. # get csproj file with appVersion tag, if not exist get file with pack or publish tag
  20. csprojPath=$(find ${basePath} -name *.csproj -exec grep '<appVersion>' -l {} \; | head -n 1);
  21. if [ ! -f "$csprojPath" ]; then csprojPath=$(find ${basePath} -name *.csproj -exec grep '<pack>\|<publish>' -l {} \; | head -n 1); fi
  22. if [ -f "$csprojPath" ]; then export appVersion=`grep '<Version>' "$csprojPath" | grep -oE '\>(.*)\<' | tr -d '<>/'`; fi
  23. echo "appVersion from csproj: $appVersion"
  24. # get v1 v2 v3
  25. v1=$(echo $appVersion | tr '.' '\n' | sed -n 1p)
  26. v2=$(echo $appVersion | tr '.' '\n' | sed -n 2p)
  27. v3=$(echo $appVersion | tr '.-' '\n' | sed -n 3p)
  28. ((v3++));
  29. #export nextAppVersion="${appVersion%%-*}$versionSuffix"
  30. export nextAppVersion="$v1.$v2.$v3$versionSuffix"
  31. echo "nextAppVersion: $nextAppVersion"
  32. #----------------------------------------------
  33. echo "#2 change app version from [$appVersion] to [$nextAppVersion]"
  34. sed -i 's/'"$appVersion"'/'"$nextAppVersion"'/g' `find ${basePath} -name *.csproj -exec grep '<pack>\|<publish>' -l {} \;`
  35. #----------------------------------------------
  36. #9
  37. cd $curPath