release.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/sh
  2. releaseType=""
  3. phase=0
  4. case "$1" in
  5. major|minor|patch) releaseType=$1 ;;
  6. -c) phase=1 ;;
  7. *)
  8. echo "no release type given or -c given"
  9. exit 1
  10. ;;
  11. esac
  12. if [ $phase -eq 0 ]
  13. then
  14. if [ "$(git status -s | wc -l)" -ne 0 ]
  15. then
  16. echo "uncommited changes"
  17. git status -s
  18. echo "continue? [y/N]"
  19. read -r decision
  20. if [ "$decision" != 'y' ]
  21. then
  22. echo 'aborting'
  23. exit 0
  24. fi
  25. fi
  26. if [ "$(git log '@{u}..' | wc -l)" -ne 0 ]
  27. then
  28. echo "unpushed changes"
  29. git status -s
  30. echo "continue? [y/N/p]"
  31. read -r decision
  32. if [ "$decision" != 'y' ]
  33. then
  34. echo 'aborting'
  35. exit 0
  36. elif [ "$decision" = 'p' ]
  37. then
  38. git push
  39. sleep 5
  40. fi
  41. fi
  42. retry="1"
  43. latestCI=$(curl https://ci.apiote.xyz/toys/czwek-commitly/latest 2>/dev/null)
  44. latestCIstatus=$(echo "$latestCI" | grep '<h2' | sed 's/<h2[^>]*>//' | sed 's|</h2>||' | grep -oE '[A-Z]+')
  45. latestCIstarted=$(echo "$latestCI" | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+\+[0-9]{2}:[0-9]{2}' | head -n1)
  46. while [ "$latestCIstatus" != 'OK' ] && [ "$retry" = "1" ]
  47. do
  48. echo "latest CI started at $latestCIstarted result is $latestCIstatus, not OK"
  49. echo "retry? [y/N]"
  50. read -r decision
  51. if [ "$decision" != 'y' ]
  52. then
  53. retry="0"
  54. exit 1
  55. fi
  56. done
  57. currentVersionName=$(grep 'versionName' app/build.gradle | tr -s ' ' | cut -d ' ' -f3 | tr -d '"')
  58. major=$(echo "$currentVersionName" | cut -d '.' -f1)
  59. minor=$(echo "$currentVersionName" | cut -d '.' -f2)
  60. patch=$(echo "$currentVersionName" | cut -d '.' -f3)
  61. currentVersionCode=$(grep 'versionCode' app/build.gradle | tr -s ' ' | cut -d ' ' -f3)
  62. case $releaseType in
  63. major) newVersionName="$((major + 1)).0.0" ;;
  64. minor) newVersionName="${major}.$((minor + 1)).0" ;;
  65. patch) newVersionName="${major}.${minor}.$((patch + 1))" ;;
  66. *) echo "wrong release type given"; exit 1 ;;
  67. esac
  68. newVersionCode=$((currentVersionCode + 1))
  69. sed -i "s/versionName \"$currentVersionName\"/versionName \"$newVersionName\"/" app/build.gradle
  70. sed -i "s/versionCode $currentVersionCode/versionCode $newVersionCode/" app/build.gradle
  71. git shortlog "v${currentVersionName}..HEAD" >> "metadata/en-US/changelogs/$newVersionCode.txt"
  72. echo "time to update changelogs"
  73. elif [ $phase -eq 1 ]
  74. then
  75. newVersionName=$(grep 'versionName' app/build.gradle | tr -s ' ' | cut -d ' ' -f3 | tr -d '"')
  76. newVersionCode=$(grep 'versionCode' app/build.gradle | tr -s ' ' | cut -d ' ' -f3)
  77. if ! find metadata -type d -name changelogs -print0 | xargs -0 -I{} [ -f "{}/$newVersionCode.txt" ]
  78. then
  79. echo "not all languages have changelog"
  80. exit 1
  81. fi
  82. git add app/build.gradle
  83. git add metadata/
  84. git commit -S -m "release version $newVersionName ($newVersionCode)"
  85. git push
  86. git switch master
  87. git merge -S --no-ff -m "merge develop into master for version $newVersionName" develop
  88. git tag -s -m "v${newVersionName}" "v${newVersionName}"
  89. git push origin --tags
  90. git switch develop
  91. git merge master
  92. fi