bump_version 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. | sed -E 's/.0$//'
  61. )"
  62. # Set the shared version to the specified new_version
  63. old_version_sed="$( sed 's/\./\\./g' <<<"${old_version}" )" # Escape the '.' chars
  64. sed -i "s/${old_version_sed}/${new_version}/g" ${shared_version_file}
  65. declare -a pr_merges_since_last_master
  66. declare changelog_string_github
  67. declare changelog_string_deb
  68. declare changelog_string_yum
  69. # Build up a changelog from merge commits
  70. for repo in ./ MediaBrowser.WebDashboard/jellyfin-web/; do
  71. last_master_merge_commit=""
  72. pr_merges_since_last_master=()
  73. git_show_details=""
  74. pull_request_id=""
  75. pull_request_description=""
  76. changelog_strings_repo_github=""
  77. changelog_strings_repo_deb=""
  78. changelog_strings_repo_yum=""
  79. case $repo in
  80. *jellyfin-web*)
  81. repo_name="jellyfin-web"
  82. ;;
  83. *)
  84. repo_name="jellyfin"
  85. ;;
  86. esac
  87. pushd ${repo}
  88. # Find the last release commit, so we know what's happened since
  89. last_master_branch="release-${old_version}"
  90. last_master_merge_commit="$(
  91. git log --merges --pretty=oneline \
  92. | grep -F "${last_master_branch}" \
  93. | awk '{ print $1 }' \
  94. || true # Don't die here with errexit
  95. )"
  96. if [[ -z ${last_master_merge_commit} ]]; then
  97. # This repo has no last proper commit, so just skip it
  98. popd
  99. continue
  100. fi
  101. # Get all the PR merge commits since the last master merge commit in `jellyfin`
  102. pr_merges_since_last_master+=( $(
  103. git log --merges --pretty=oneline ${last_master_merge_commit}..HEAD \
  104. | grep -F "Merge pull request" \
  105. | awk '{ print $1 }'
  106. ) )
  107. for commit_hash in ${pr_merges_since_last_master[@]}; do
  108. git_show_details="$( git show ${commit_hash} )"
  109. pull_request_id="$(
  110. awk '
  111. /Merge pull request/{ print $4 }
  112. { next }
  113. ' <<<"${git_show_details}"
  114. )"
  115. pull_request_description="$(
  116. awk '
  117. /^[a-zA-Z]/{ next }
  118. /^ Merge/{ next }
  119. /^$/{ next }
  120. { print $0 }
  121. ' <<<"${git_show_details}"
  122. )"
  123. pull_request_description="$( sed ':a;N;$!ba;s/\n//g; s/ \+//g' <<<"${pull_request_description}" )"
  124. changelog_strings_repo_github="${changelog_strings_repo_github}\n* ${pull_request_id}: ${pull_request_description}"
  125. changelog_strings_repo_deb="${changelog_strings_repo_deb}\n * $( sed 's/#/PR/' <<<"${pull_request_id}" ) ${pull_request_description}"
  126. changelog_strings_repo_yum="${changelog_strings_repo_yum}\n- $( sed 's/#/PR/' <<<"${pull_request_id}" ) ${pull_request_description}"
  127. done
  128. changelog_string_github="${changelog_string_github}\n#### ${repo_name}:\n$( echo -e "${changelog_strings_repo_github}" | sort -nk2 )\n"
  129. changelog_string_deb="${changelog_string_deb}\n * ${repo_name}:$( echo -e "${changelog_strings_repo_deb}" | sort -nk2 )"
  130. changelog_string_yum="${changelog_string_yum}\n- ${repo_name}:$( echo -e "${changelog_strings_repo_yum}" | sort -nk2 )"
  131. popd
  132. done
  133. # Write out a temporary Debian changelog with our new stuff appended and some templated formatting
  134. debian_changelog_file="deployment/debian-package-x64/pkg-src/changelog"
  135. debian_changelog_temp="$( mktemp )"
  136. # Create new temp file with our changelog
  137. echo -e "### DEBIAN PACKAGE CHANGELOG: Verify this file looks correct or edit accordingly, then delete this line, write, and exit.
  138. jellyfin (${new_version}-1) unstable; urgency=medium
  139. ${changelog_string_deb}
  140. -- Jellyfin Packaging Team <packaging@jellyfin.org> $( date --rfc-2822 )
  141. " >> ${debian_changelog_temp}
  142. cat ${debian_changelog_file} >> ${debian_changelog_temp}
  143. # Edit the file to verify
  144. $EDITOR ${debian_changelog_temp}
  145. # Move into place
  146. mv ${debian_changelog_temp} ${debian_changelog_file}
  147. # Clean up
  148. rm -f ${debian_changelog_temp}
  149. # Write out a temporary Yum changelog with our new stuff prepended and some templated formatting
  150. fedora_spec_file="deployment/fedora-package-x64/pkg-src/jellyfin.spec"
  151. fedora_changelog_temp="$( mktemp )"
  152. fedora_spec_temp_dir="$( mktemp -d )"
  153. fedora_spec_temp="${fedora_spec_temp_dir}/jellyfin.spec.tmp"
  154. # Make a copy of our spec file for hacking
  155. cp ${fedora_spec_file} ${fedora_spec_temp_dir}/
  156. pushd ${fedora_spec_temp_dir}
  157. # Split out the stuff before and after changelog
  158. csplit jellyfin.spec "/^%changelog/" # produces xx00 xx01
  159. # Update the version in xx00
  160. sed -i "s/${old_version_sed}/${new_version}/g" xx00
  161. # Remove the header from xx01
  162. sed -i '/^%changelog/d' xx01
  163. # Create new temp file with our changelog
  164. echo -e "### YUM SPEC CHANGELOG: Verify this file looks correct or edit accordingly, then delete this line, write, and exit.
  165. %changelog
  166. * $( LANG=C date '+%a %b %d %Y' ) Jellyfin Packaging Team <packaging@jellyfin.org>${changelog_string_yum}" >> ${fedora_changelog_temp}
  167. cat xx01 >> ${fedora_changelog_temp}
  168. # Edit the file to verify
  169. $EDITOR ${fedora_changelog_temp}
  170. # Reassembble
  171. cat xx00 ${fedora_changelog_temp} > ${fedora_spec_temp}
  172. popd
  173. # Move into place
  174. mv ${fedora_spec_temp} ${fedora_spec_file}
  175. # Clean up
  176. rm -rf ${fedora_changelog_temp} ${fedora_spec_temp_dir}
  177. # Stage the changed files for commit
  178. git add ${shared_version_file} ${debian_changelog_file} ${fedora_spec_file}
  179. git status
  180. # Write out the GitHub-formatted changelog for the merge request/release pages
  181. echo ""
  182. echo "=== The GitHub-formatted changelog follows ==="
  183. echo -e "${changelog_string_github}"