bump_version 7.1 KB

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