You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
7.8 KiB

3 years ago
  1. #!/bin/bash
  2. #
  3. # WARNING: since Etherpad 1.7.0 (2018-08-17), this script is DEPRECATED, and
  4. # will be removed/modified in a future version.
  5. # It's left here just for documentation.
  6. # The branching policies for releases have been changed.
  7. #
  8. # This script is used to publish a new release/version of etherpad on github
  9. #
  10. # Work that is done by this script:
  11. # ETHER_REPO:
  12. # - Add text to CHANGELOG.md
  13. # - Replace version of etherpad in src/package.json
  14. # - Create a release branch and push it to github
  15. # - Merges this release branch into master branch
  16. # - Creating the windows build and the docs
  17. # ETHER_WEB_REPO:
  18. # - Creating a new branch with the docs and the windows build
  19. # - Replacing the version numbers in the index.html
  20. # - Push this branch and merge it to master
  21. # ETHER_REPO:
  22. # - Create a new release on github
  23. printf "WARNING: since Etherpad 1.7.0 this script is DEPRECATED, and will be removed/modified in a future version.\n\n"
  24. while true; do
  25. read -p "Do you want to continue? This is discouraged. [y/N]" yn
  26. case $yn in
  27. [Yy]* ) break;;
  28. [Nn]* ) exit;;
  29. * ) printf "Please answer yes or no.\n\n";;
  30. esac
  31. done
  32. ETHER_REPO="https://github.com/ether/etherpad-lite.git"
  33. ETHER_WEB_REPO="https://github.com/ether/ether.github.com.git"
  34. TMP_DIR="/tmp/"
  35. echo "WARNING: You can only run this script if your github api token is allowed to create and merge branches on $ETHER_REPO and $ETHER_WEB_REPO."
  36. echo "This script automatically changes the version number in package.json and adds a text to CHANGELOG.md."
  37. echo "When you use this script you should be in the branch that you want to release (develop probably) on latest version. Any changes that are currently not committed will be committed."
  38. echo "-----"
  39. # Get the latest version
  40. LATEST_GIT_TAG=$(git tag | tail -n 1)
  41. # Current environment
  42. echo "Current environment: "
  43. echo "- branch: $(git branch | grep '* ')"
  44. echo "- last commit date: $(git show --quiet --pretty=format:%ad)"
  45. echo "- current version: $LATEST_GIT_TAG"
  46. echo "- temp dir: $TMP_DIR"
  47. # Get new version number
  48. # format: x.x.x
  49. echo -n "Enter new version (x.x.x): "
  50. read VERSION
  51. # Get the message for the changelogs
  52. read -p "Enter new changelog entries (press enter): "
  53. tmp=$(mktemp)
  54. "${EDITOR:-vi}" $tmp
  55. changelogText=$(<$tmp)
  56. echo "$changelogText"
  57. rm $tmp
  58. if [ "$changelogText" != "" ]; then
  59. changelogText="# $VERSION\n$changelogText"
  60. fi
  61. # get the token for the github api
  62. echo -n "Enter your github api token: "
  63. read API_TOKEN
  64. function check_api_token {
  65. echo "Checking if github api token is valid..."
  66. CURL_RESPONSE=$(curl --silent -i https://api.github.com/user?access_token=$API_TOKEN | iconv -f utf8)
  67. HTTP_STATUS=$(echo $CURL_RESPONSE | head -1 | sed -r 's/.* ([0-9]{3}) .*/\1/')
  68. [[ $HTTP_STATUS != "200" ]] && echo "Aborting: Invalid github api token" && exit 1
  69. }
  70. function modify_files {
  71. # Add changelog text to first line of CHANGELOG.md
  72. msg=""
  73. # source: https://unix.stackexchange.com/questions/9784/how-can-i-read-line-by-line-from-a-variable-in-bash#9789
  74. while IFS= read -r line
  75. do
  76. # replace newlines with literal "\n" for using with sed
  77. msg+="$line\n"
  78. done < <(printf '%s\n' "${changelogText}")
  79. sed -i "1s/^/${msg}\n/" CHANGELOG.md
  80. [[ $? != 0 ]] && echo "Aborting: Error modifying CHANGELOG.md" && exit 1
  81. # Replace version number of etherpad in package.json
  82. sed -i -r "s/(\"version\"[ ]*: \").*(\")/\1$VERSION\2/" src/package.json
  83. [[ $? != 0 ]] && echo "Aborting: Error modifying package.json" && exit 1
  84. }
  85. function create_release_branch {
  86. echo "Creating new release branch..."
  87. git rev-parse --verify release/$VERSION 2>/dev/null
  88. if [ $? == 0 ]; then
  89. echo "Aborting: Release branch already present"
  90. exit 1
  91. fi
  92. git checkout -b release/$VERSION
  93. [[ $? != 0 ]] && echo "Aborting: Error creating release branch" && exit 1
  94. echo "Committing CHANGELOG.md and package.json"
  95. git add CHANGELOG.md
  96. git add src/package.json
  97. git commit -m "Release version $VERSION"
  98. echo "Pushing release branch to github..."
  99. git push -u $ETHER_REPO release/$VERSION
  100. [[ $? != 0 ]] && echo "Aborting: Error pushing release branch to github" && exit 1
  101. }
  102. function merge_release_branch {
  103. echo "Merging release to master branch on github..."
  104. API_JSON=$(printf '{"base": "master","head": "release/%s","commit_message": "Merge new release into master branch!"}' $VERSION)
  105. CURL_RESPONSE=$(curl --silent -i -N --data "$API_JSON" https://api.github.com/repos/ether/etherpad-lite/merges?access_token=$API_TOKEN | iconv -f utf8)
  106. echo $CURL_RESPONSE
  107. HTTP_STATUS=$(echo $CURL_RESPONSE | head -1 | sed -r 's/.* ([0-9]{3}) .*/\1/')
  108. [[ $HTTP_STATUS != "200" ]] && echo "Aborting: Error merging release branch on github" && exit 1
  109. }
  110. function create_builds {
  111. echo "Cloning etherpad-lite repo and ether.github.com repo..."
  112. cd $TMP_DIR
  113. rm -rf etherpad-lite ether.github.com
  114. git clone $ETHER_REPO --branch master
  115. git clone $ETHER_WEB_REPO
  116. echo "Creating windows build..."
  117. cd etherpad-lite
  118. bin/buildForWindows.sh
  119. [[ $? != 0 ]] && echo "Aborting: Error creating build for windows" && exit 1
  120. echo "Creating docs..."
  121. make docs
  122. [[ $? != 0 ]] && echo "Aborting: Error generating docs" && exit 1
  123. }
  124. function push_builds {
  125. cd $TMP_DIR/etherpad-lite/
  126. echo "Copying windows build and docs to website repo..."
  127. GIT_SHA=$(git rev-parse HEAD | cut -c1-10)
  128. mv etherpad-lite-win.zip $TMP_DIR/ether.github.com/downloads/etherpad-lite-win-$VERSION-$GIT_SHA.zip
  129. mv out/doc $TMP_DIR/ether.github.com/doc/v$VERSION
  130. cd $TMP_DIR/ether.github.com/
  131. sed -i "s/etherpad-lite-win.*\.zip/etherpad-lite-win-$VERSION-$GIT_SHA.zip/" index.html
  132. sed -i "s/$LATEST_GIT_TAG/$VERSION/g" index.html
  133. git checkout -b release_$VERSION
  134. [[ $? != 0 ]] && echo "Aborting: Error creating new release branch" && exit 1
  135. git add doc/
  136. git add downloads/
  137. git commit -a -m "Release version $VERSION"
  138. git push -u $ETHER_WEB_REPO release_$VERSION
  139. [[ $? != 0 ]] && echo "Aborting: Error pushing release branch to github" && exit 1
  140. }
  141. function merge_web_branch {
  142. echo "Merging release to master branch on github..."
  143. API_JSON=$(printf '{"base": "master","head": "release_%s","commit_message": "Release version %s"}' $VERSION $VERSION)
  144. CURL_RESPONSE=$(curl --silent -i -N --data "$API_JSON" https://api.github.com/repos/ether/ether.github.com/merges?access_token=$API_TOKEN | iconv -f utf8)
  145. echo $CURL_RESPONSE
  146. HTTP_STATUS=$(echo $CURL_RESPONSE | head -1 | sed -r 's/.* ([0-9]{3}) .*/\1/')
  147. [[ $HTTP_STATUS != "200" ]] && echo "Aborting: Error merging release branch" && exit 1
  148. }
  149. function publish_release {
  150. echo -n "Do you want to publish a new release on github (y/n)? "
  151. read PUBLISH_RELEASE
  152. if [ $PUBLISH_RELEASE = "y" ]; then
  153. # create a new release on github
  154. API_JSON=$(printf '{"tag_name": "%s","target_commitish": "master","name": "Release %s","body": "%s","draft": false,"prerelease": false}' $VERSION $VERSION $changelogText)
  155. CURL_RESPONSE=$(curl --silent -i -N --data "$API_JSON" https://api.github.com/repos/ether/etherpad-lite/releases?access_token=$API_TOKEN | iconv -f utf8)
  156. HTTP_STATUS=$(echo $CURL_RESPONSE | head -1 | sed -r 's/.* ([0-9]{3}) .*/\1/')
  157. [[ $HTTP_STATUS != "201" ]] && echo "Aborting: Error publishing release on github" && exit 1
  158. else
  159. echo "No release published on github!"
  160. fi
  161. }
  162. function todo_notification {
  163. echo "Release procedure was successful, but you have to do some steps manually:"
  164. echo "- Update the wiki at https://github.com/ether/etherpad-lite/wiki"
  165. echo "- Create a pull request on github to merge the master branch back to develop"
  166. echo "- Announce the new release on the mailing list, blog.etherpad.org and Twitter"
  167. }
  168. # Call functions
  169. check_api_token
  170. modify_files
  171. create_release_branch
  172. merge_release_branch
  173. create_builds
  174. push_builds
  175. merge_web_branch
  176. publish_release
  177. todo_notification