bump_version 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/usr/bin/env bash
  2. # bump_version - increase the shared version and generate changelogs
  3. set -o errexit
  4. set -o pipefail
  5. usage() {
  6. echo -e "bump_version - increase the shared version and generate changelogs"
  7. echo -e ""
  8. echo -e "Usage:"
  9. echo -e " $ bump_version [-b/--web-branch <web_branch>] <new_version>"
  10. echo -e ""
  11. echo -e "The web_branch defaults to the same branch name as the current main branch."
  12. echo -e "This helps facilitate releases where both branches would be called release-X.Y.Z"
  13. echo -e "and would already be created before running this script."
  14. }
  15. if [[ -z $1 ]]; then
  16. usage
  17. exit 1
  18. fi
  19. shared_version_file="./SharedVersion.cs"
  20. # Parse branch option
  21. if [[ $1 == '-b' || $1 == '--web-branch' ]]; then
  22. web_branch="$2"
  23. shift 2
  24. else
  25. web_branch="$( git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' )"
  26. fi
  27. # Initialize submodules
  28. git submodule update --init --recursive
  29. # configure branch
  30. pushd MediaBrowser.WebDashboard/jellyfin-web
  31. if ! git diff-index --quiet HEAD --; then
  32. popd
  33. echo
  34. echo "ERROR: Your 'jellyfin-web' submodule working directory is not clean!"
  35. echo "This script will overwrite your unstaged and unpushed changes."
  36. echo "Please do development on 'jellyfin-web' outside of the submodule."
  37. exit 1
  38. fi
  39. git fetch --all
  40. # If this is an official branch name, fetch it from origin
  41. official_branches_regex="^master$|^dev$|^release-.*$|^hotfix-.*$"
  42. if [[ ${web_branch} =~ ${official_branches_regex} ]]; then
  43. git checkout origin/${web_branch} || {
  44. echo "ERROR: 'jellyfin-web' branch 'origin/${web_branch}' is invalid."
  45. exit 1
  46. }
  47. # Otherwise, just check out the local branch (for testing, etc.)
  48. else
  49. git checkout ${web_branch} || {
  50. echo "ERROR: 'jellyfin-web' branch '${web_branch}' is invalid."
  51. exit 1
  52. }
  53. fi
  54. popd
  55. new_version="$1"
  56. # Parse the version from the AssemblyVersion
  57. old_version="$(
  58. grep "AssemblyVersion" ${shared_version_file} \
  59. | sed -E 's/\[assembly: ?AssemblyVersion\("([0-9\.]+)"\)\]/\1/'
  60. )"
  61. # Set the shared version to the specified new_version
  62. old_version_sed="$( sed 's/\./\\./g' <<<"${old_version}" )" # Escape the '.' chars
  63. sed -i "s/${old_version_sed}/${new_version}/g" ${shared_version_file}
  64. declare -a pr_merges_since_last_master
  65. declare changelog_string_github
  66. declare changelog_string_deb
  67. declare changelog_string_yum
  68. # Build up a changelog from merge commits
  69. for repo in ./ MediaBrowser.WebDashboard/jellyfin-web/; do
  70. last_master_merge_commit=""
  71. pr_merges_since_last_master=()
  72. git_show_details=""
  73. pull_request_id=""
  74. pull_request_description=""
  75. changelog_strings_repo_github=""
  76. changelog_strings_repo_deb=""
  77. changelog_strings_repo_yum=""
  78. case $repo in
  79. *jellyfin-web*)
  80. repo_name="jellyfin-web"
  81. ;;
  82. *)
  83. repo_name="jellyfin"
  84. ;;
  85. esac
  86. pushd ${repo}
  87. # Find the last release commit, so we know what's happened since
  88. last_master_branch="release-${old_version}"
  89. last_master_merge_commit="$(
  90. git log --merges --pretty=oneline \
  91. | grep -F "${last_master_branch}" \
  92. | awk '{ print $1 }' \
  93. || true # Don't die here with errexit
  94. )"
  95. if [[ -z ${last_master_merge_commit} ]]; then
  96. # This repo has no last proper commit, so just skip it
  97. popd
  98. continue
  99. fi
  100. # Get all the PR merge commits since the last master merge commit in `jellyfin`
  101. pr_merges_since_last_master+=( $(
  102. git log --merges --pretty=oneline ${last_master_merge_commit}..HEAD \
  103. | grep -F "Merge pull request" \
  104. | awk '{ print $1 }'
  105. ) )
  106. for commit_hash in ${pr_merges_since_last_master[@]}; do
  107. git_show_details="$( git show ${commit_hash} )"
  108. pull_request_id="$(
  109. awk '
  110. /Merge pull request/{ print $4 }
  111. { next }
  112. ' <<<"${git_show_details}"
  113. )"
  114. pull_request_description="$(
  115. awk '
  116. /^[a-zA-Z]/{ next }
  117. /^ Merge/{ next }
  118. /^$/{ next }
  119. { print $0 }
  120. ' <<<"${git_show_details}"
  121. )"
  122. pull_request_description="$( sed ':a;N;$!ba;s/\n//g; s/ \+//g' <<<"${pull_request_description}" )"
  123. changelog_strings_repo_github="${changelog_strings_repo_github}\n* ${pull_request_id}: ${pull_request_description}"
  124. changelog_strings_repo_deb="${changelog_strings_repo_deb}\n * $( sed 's/#/PR/' <<<"${pull_request_id}" ) ${pull_request_description}"
  125. changelog_strings_repo_yum="${changelog_strings_repo_yum}\n- $( sed 's/#/PR/' <<<"${pull_request_id}" ) ${pull_request_description}"
  126. done
  127. changelog_string_github="${changelog_string_github}\n#### ${repo_name}:\n$( echo -e "${changelog_strings_repo_github}" | sort -nk2 )\n"
  128. changelog_string_deb="${changelog_string_deb}\n * ${repo_name}:$( echo -e "${changelog_strings_repo_deb}" | sort -nk2 )"
  129. changelog_string_yum="${changelog_string_yum}\n- ${repo_name}:$( echo -e "${changelog_strings_repo_yum}" | sort -nk2 )"
  130. popd
  131. done
  132. # Write out a temporary Debian changelog with our new stuff appended and some templated formatting
  133. debian_changelog_file="deployment/debian-package-x64/pkg-src/changelog"
  134. debian_changelog_temp="$( mktemp )"
  135. # Create new temp file with our changelog
  136. echo -e "### DEBIAN PACKAGE CHANGELOG: Verify this file looks correct or edit accordingly, then delete this line, write, and exit.
  137. jellyfin (${new_version}-1) unstable; urgency=medium
  138. ${changelog_string_deb}
  139. -- Jellyfin Packaging Team <packaging@jellyfin.org> $( date --rfc-2822 )
  140. " >> ${debian_changelog_temp}
  141. cat ${debian_changelog_file} >> ${debian_changelog_temp}
  142. # Edit the file to verify
  143. $EDITOR ${debian_changelog_temp}
  144. # Move into place
  145. mv ${debian_changelog_temp} ${debian_changelog_file}
  146. # Clean up
  147. rm -f ${debian_changelog_temp}
  148. # Write out a temporary Yum changelog with our new stuff prepended and some templated formatting
  149. fedora_spec_file="deployment/fedora-package-x64/pkg-src/jellyfin.spec"
  150. fedora_changelog_temp="$( mktemp )"
  151. fedora_spec_temp_dir="$( mktemp -d )"
  152. fedora_spec_temp="${fedora_spec_temp_dir}/jellyfin.spec.tmp"
  153. # Make a copy of our spec file for hacking
  154. cp ${fedora_spec_file} ${fedora_spec_temp_dir}/
  155. pushd ${fedora_spec_temp_dir}
  156. # Split out the stuff before and after changelog
  157. csplit jellyfin.spec "/^%changelog/" # produces xx00 xx01
  158. # Update the version in xx00
  159. sed -i "s/${old_version_sed}/${new_version}/g" xx00
  160. # Remove the header from xx01
  161. sed -i '/^%changelog/d' xx01
  162. # Create new temp file with our changelog
  163. echo -e "### YUM SPEC CHANGELOG: Verify this file looks correct or edit accordingly, then delete this line, write, and exit.
  164. %changelog
  165. * $( LANG=C date '+%a %b %d %Y' ) Jellyfin Packaging Team <packaging@jellyfin.org>${changelog_string_yum}" >> ${fedora_changelog_temp}
  166. cat xx01 >> ${fedora_changelog_temp}
  167. # Edit the file to verify
  168. $EDITOR ${fedora_changelog_temp}
  169. # Reassembble
  170. cat xx00 ${fedora_changelog_temp} > ${fedora_spec_temp}
  171. popd
  172. # Move into place
  173. mv ${fedora_spec_temp} ${fedora_spec_file}
  174. # Clean up
  175. rm -rf ${fedora_changelog_temp} ${fedora_spec_temp_dir}
  176. # Stage the changed files for commit
  177. git add ${shared_version_file} ${debian_changelog_file} ${fedora_spec_file}
  178. git status
  179. # Write out the GitHub-formatted changelog for the merge request/release pages
  180. echo ""
  181. echo "=== The GitHub-formatted changelog follows ==="
  182. echo -e "${changelog_string_github}"