release.sh 3.5 KB

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