bump_version 6.8 KB

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