release.sh 3.0 KB

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