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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. # basePath
  13. if [ -z "$basePath" ]; then basePath=$PWD/../../..; fi
  14. #----------------------------------------------
  15. echo "#1 get appVersion"
  16. # get csproj file with appVersion tag, if not exist get file with pack or publish tag
  17. csprojPath=$(find ${basePath} -name *.props -exec grep '<Version>' -l {} \; | head -n 1);
  18. if [ ! -f "$csprojPath" ]; then csprojPath=$(find ${basePath} -name *.csproj -exec grep '<appVersion>' -l {} \; | head -n 1); fi
  19. if [ ! -f "$csprojPath" ]; then csprojPath=$(find ${basePath} -name *.csproj -exec grep '<pack>\|<publish>' -l {} \; | head -n 1); fi
  20. if [ -f "$csprojPath" ]; then export appVersion=`grep '<Version>' "$csprojPath" | grep -oE '\>(.*)\<' | tr -d '<>/'`; fi
  21. echo "appVersion from csproj: $appVersion"
  22. # get v1 v2 v3
  23. v1=$(echo $appVersion | tr '.' '\n' | sed -n 1p)
  24. v2=$(echo $appVersion | tr '.' '\n' | sed -n 2p)
  25. v3=$(echo $appVersion | tr '.-' '\n' | sed -n 3p)
  26. ((v3++));
  27. #export nextAppVersion="${appVersion%%-*}$versionSuffix"
  28. export nextAppVersion="$v1.$v2.$v3$versionSuffix"
  29. echo "nextAppVersion: $nextAppVersion"
  30. #----------------------------------------------
  31. echo "#2 change app version from [$appVersion] to [$nextAppVersion]"
  32. sed -i 's/'"<Version>$appVersion<\/Version>"'/'"<Version>$nextAppVersion<\/Version>"'/g' `find ${basePath} -name *.csproj -exec grep '<pack>\|<publish>' -l {} \;`