release.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 -Eo 'versionName = "[0-9\.]+"' app/build.gradle.kts | cut -d '=' -f2 | 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.kts | cut -d '=' -f2 | tr -d ' ')
  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.kts
  80. sed -i "s/versionCode = $currentVersionCode/versionCode = $newVersionCode/" app/build.gradle.kts
  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 -Eo 'versionName = "[0-9\.]+"' app/build.gradle.kts | cut -d '=' -f2 | tr -d ' "')
  86. newVersionCode=$(grep 'versionCode' app/build.gradle.kts | cut -d '=' -f2 | tr -d ' ')
  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. echo "OK? [y/N]"
  91. read -r yn
  92. if [ "$yn" != 'y' ] && [ "$yn" != 'Y' ]; then
  93. exit 1
  94. fi
  95. fi
  96. git add app/build.gradle.kts
  97. git add metadata/
  98. git commit -S -m "release version $newVersionName ($newVersionCode)" || true
  99. echo 'pushing …'
  100. git push
  101. git switch master
  102. git merge -S --no-ff -m "merge develop into master for version $newVersionName" develop
  103. echo 'push to master? [y/N]'
  104. read -r yn
  105. if [ "$yn" != 'y' ] && [ "$yn" != 'Y' ]; then
  106. exit 1
  107. fi
  108. echo 'pushing …'
  109. git push
  110. echo 'tag and push tag? [y/N]'
  111. read -r yn
  112. if [ "$yn" != 'y' ] && [ "$yn" != 'Y' ]; then
  113. exit 1
  114. fi
  115. git tag -s -m "v${newVersionName}" "v${newVersionName}"
  116. git push origin --tags
  117. git switch develop
  118. git merge master
  119. elif [ $phase -eq 2 ]
  120. then
  121. newVersionName=$(grep -Eo 'versionName = "[0-9\.]+"' app/build.gradle.kts | cut -d '=' -f2 | tr -d ' "')
  122. git tag -s -m "v${newVersionName}" "v${newVersionName}"
  123. git push origin --tags
  124. git switch develop
  125. git merge master
  126. fi