release.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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/s]"
  60. read -r decision
  61. if [ "$decision" = 'N' ]
  62. then
  63. retry="0"
  64. exit 1
  65. fi
  66. if [ "$decision" = 's' ]
  67. then
  68. retry="0"
  69. break
  70. fi
  71. latestCI=$(curl https://ci.apiote.xyz/toys/czwek-commitly/latest 2>/dev/null)
  72. latestCIstatus=$(echo "$latestCI" | grep '<h2' | sed 's/<h2[^>]*>//' | sed 's|</h2>||' | grep -oE '[A-Z]+')
  73. 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)
  74. done
  75. currentVersionName=$(grep -Eo 'versionName = "[0-9\.]+"' app/build.gradle.kts | cut -d '=' -f2 | tr -d ' "')
  76. major=$(echo "$currentVersionName" | cut -d '.' -f1)
  77. minor=$(echo "$currentVersionName" | cut -d '.' -f2)
  78. patch=$(echo "$currentVersionName" | cut -d '.' -f3)
  79. currentVersionCode=$(grep 'versionCode' app/build.gradle.kts | cut -d '=' -f2 | tr -d ' ')
  80. case $releaseType in
  81. major) newVersionName="$((major + 1)).0.0" ;;
  82. minor) newVersionName="${major}.$((minor + 1)).0" ;;
  83. patch) newVersionName="${major}.${minor}.$((patch + 1))" ;;
  84. *) echo "wrong release type given"; exit 1 ;;
  85. esac
  86. newVersionCode=$((currentVersionCode + 1))
  87. sed -i "s/versionName = \"$currentVersionName\"/versionName = \"$newVersionName\"/" app/build.gradle.kts
  88. sed -i "s/versionCode = $currentVersionCode/versionCode = $newVersionCode/" app/build.gradle.kts
  89. git shortlog "v${currentVersionName}..HEAD" >> "metadata/en-US/changelogs/$newVersionCode.txt"
  90. echo "time to update changelogs"
  91. elif [ $phase -eq 1 ]
  92. then
  93. newVersionName=$(grep -Eo 'versionName = "[0-9\.]+"' app/build.gradle.kts | cut -d '=' -f2 | tr -d ' "')
  94. newVersionCode=$(grep 'versionCode' app/build.gradle.kts | cut -d '=' -f2 | tr -d ' ')
  95. if ! find metadata -type d -name changelogs -print0 | xargs -0 -I{} [ -f "{}/$newVersionCode.txt" ]
  96. then
  97. echo "not all languages have changelog"
  98. echo "OK? [y/N]"
  99. read -r yn
  100. if [ "$yn" != 'y' ] && [ "$yn" != 'Y' ]; then
  101. exit 1
  102. fi
  103. fi
  104. git add app/build.gradle.kts
  105. git add metadata/
  106. git commit -S -m "release version $newVersionName ($newVersionCode)" || true
  107. echo 'pushing …'
  108. git push
  109. git switch master
  110. git merge -S --no-ff -m "merge develop into master for version $newVersionName" develop
  111. echo 'push to master? [y/N]'
  112. read -r yn
  113. if [ "$yn" != 'y' ] && [ "$yn" != 'Y' ]; then
  114. exit 1
  115. fi
  116. echo 'pushing …'
  117. git push
  118. echo 'tag and push tag? [y/N]'
  119. read -r yn
  120. if [ "$yn" != 'y' ] && [ "$yn" != 'Y' ]; then
  121. exit 1
  122. fi
  123. git tag -s -m "v${newVersionName}" "v${newVersionName}"
  124. git push origin --tags
  125. git switch develop
  126. git merge master
  127. elif [ $phase -eq 2 ]
  128. then
  129. newVersionName=$(grep -Eo 'versionName = "[0-9\.]+"' app/build.gradle.kts | cut -d '=' -f2 | tr -d ' "')
  130. git tag -s -m "v${newVersionName}" "v${newVersionName}"
  131. git push origin --tags
  132. git switch develop
  133. git merge master
  134. fi