| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 | #!/usr/bin/env bash# bump_version - increase the shared version and generate changelogsset -o errexitset -o pipefailusage() {    echo -e "bump_version - increase the shared version and generate changelogs"    echo -e ""    echo -e "Usage:"    echo -e " $ bump_version [-b/--web-branch <web_branch>] <new_version>"    echo -e ""    echo -e "The web_branch defaults to the same branch name as the current main branch."    echo -e "This helps facilitate releases where both branches would be called release-X.Y.Z"    echo -e "and would already be created before running this script."}if [[ -z $1 ]]; then    usage    exit 1fishared_version_file="./SharedVersion.cs"# Parse branch optionif [[ $1 == '-b' || $1 == '--web-branch' ]]; then	web_branch="$2"	shift 2else    web_branch="$( git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' )"fi# Initialize submodulesgit submodule update --init --recursive# configure branchpushd MediaBrowser.WebDashboard/jellyfin-webif ! git diff-index --quiet HEAD --; then    popd    echo    echo "ERROR: Your 'jellyfin-web' submodule working directory is not clean!"    echo "This script will overwrite your unstaged and unpushed changes."    echo "Please do development on 'jellyfin-web' outside of the submodule."    exit 1figit fetch --all# If this is an official branch name, fetch it from originofficial_branches_regex="^master$|^dev$|^release-.*$|^hotfix-.*$"if [[ ${web_branch} =~ ${official_branches_regex} ]]; then    git checkout origin/${web_branch} || {        echo "ERROR: 'jellyfin-web' branch 'origin/${web_branch}' is invalid."        exit 1    }# Otherwise, just check out the local branch (for testing, etc.)else    git checkout ${web_branch} || {        echo "ERROR: 'jellyfin-web' branch '${web_branch}' is invalid."        exit 1    }fipopdnew_version="$1"# Parse the version from the AssemblyVersionold_version="$(    grep "AssemblyVersion" ${shared_version_file} \        | sed -E 's/\[assembly: ?AssemblyVersion\("([0-9\.]+)"\)\]/\1/')"# Set the shared version to the specified new_versionold_version_sed="$( sed 's/\./\\./g' <<<"${old_version}" )" # Escape the '.' charssed -i "s/${old_version_sed}/${new_version}/g" ${shared_version_file}declare -a pr_merges_since_last_masterdeclare changelog_string_githubdeclare changelog_string_debdeclare changelog_string_yum# Build up a changelog from merge commitsfor repo in ./ MediaBrowser.WebDashboard/jellyfin-web/; do    last_master_merge_commit=""    pr_merges_since_last_master=()    git_show_details=""    pull_request_id=""    pull_request_description=""    changelog_strings_repo_github=""    changelog_strings_repo_deb=""    changelog_strings_repo_yum=""    case $repo in        *jellyfin-web*)            repo_name="jellyfin-web"        ;;        *)            repo_name="jellyfin"        ;;    esac    pushd ${repo}    # Find the last release commit, so we know what's happened since    last_master_branch="release-${old_version}"    last_master_merge_commit="$(        git log --merges --pretty=oneline \            | grep -F "${last_master_branch}" \            | awk '{ print $1 }' \            || true # Don't die here with errexit    )"    if [[ -z ${last_master_merge_commit} ]]; then        # This repo has no last proper commit, so just skip it        popd        continue    fi    # Get all the PR merge commits since the last master merge commit in `jellyfin`    pr_merges_since_last_master+=( $(        git log --merges --pretty=oneline ${last_master_merge_commit}..HEAD \            | grep -F "Merge pull request" \            | awk '{ print $1 }'    ) )    for commit_hash in ${pr_merges_since_last_master[@]}; do        git_show_details="$( git show ${commit_hash} )"        pull_request_id="$(            awk '                /Merge pull request/{ print $4 }                { next }            ' <<<"${git_show_details}"        )"        pull_request_description="$(            awk '                /^[a-zA-Z]/{ next }                /^    Merge/{ next }                /^$/{ next }                { print $0 }            ' <<<"${git_show_details}"        )"        pull_request_description="$( sed ':a;N;$!ba;s/\n//g; s/  \+//g' <<<"${pull_request_description}" )"        changelog_strings_repo_github="${changelog_strings_repo_github}\n* ${pull_request_id}: ${pull_request_description}"        changelog_strings_repo_deb="${changelog_strings_repo_deb}\n  * $( sed 's/#/PR/' <<<"${pull_request_id}" ) ${pull_request_description}"        changelog_strings_repo_yum="${changelog_strings_repo_yum}\n- $( sed 's/#/PR/' <<<"${pull_request_id}" ) ${pull_request_description}"    done    changelog_string_github="${changelog_string_github}\n#### ${repo_name}:\n$( echo -e "${changelog_strings_repo_github}" | sort -nk2 )\n"    changelog_string_deb="${changelog_string_deb}\n  * ${repo_name}:$( echo -e "${changelog_strings_repo_deb}" | sort -nk2 )"    changelog_string_yum="${changelog_string_yum}\n- ${repo_name}:$( echo -e "${changelog_strings_repo_yum}" | sort -nk2 )"    popddone# Write out a temporary Debian changelog with our new stuff appended and some templated formattingdebian_changelog_file="deployment/debian-package-x64/pkg-src/changelog"debian_changelog_temp="$( mktemp )"# Create new temp file with our changelogecho -e "### DEBIAN PACKAGE CHANGELOG: Verify this file looks correct or edit accordingly, then delete this line, write, and exit.jellyfin (${new_version}-1) unstable; urgency=medium${changelog_string_deb} -- Jellyfin Packaging Team <packaging@jellyfin.org>  $( date --rfc-2822 )" >> ${debian_changelog_temp}cat ${debian_changelog_file} >> ${debian_changelog_temp}# Edit the file to verify$EDITOR ${debian_changelog_temp}# Move into placemv ${debian_changelog_temp} ${debian_changelog_file}# Clean uprm -f ${debian_changelog_temp}# Write out a temporary Yum changelog with our new stuff prepended and some templated formattingfedora_spec_file="deployment/fedora-package-x64/pkg-src/jellyfin.spec"fedora_changelog_temp="$( mktemp )"fedora_spec_temp_dir="$( mktemp -d )"fedora_spec_temp="${fedora_spec_temp_dir}/jellyfin.spec.tmp"# Make a copy of our spec file for hackingcp ${fedora_spec_file} ${fedora_spec_temp_dir}/pushd ${fedora_spec_temp_dir}# Split out the stuff before and after changelogcsplit jellyfin.spec  "/^%changelog/" # produces xx00 xx01# Update the version in xx00sed -i "s/${old_version_sed}/${new_version}/g" xx00# Remove the header from xx01sed -i '/^%changelog/d' xx01# Create new temp file with our changelogecho -e "### YUM SPEC CHANGELOG: Verify this file looks correct or edit accordingly, then delete this line, write, and exit.%changelog* $( LANG=C date '+%a %b %d %Y' ) Jellyfin Packaging Team <packaging@jellyfin.org>${changelog_string_yum}" >> ${fedora_changelog_temp}cat xx01 >> ${fedora_changelog_temp}# Edit the file to verify$EDITOR ${fedora_changelog_temp}# Reassembblecat xx00 ${fedora_changelog_temp} > ${fedora_spec_temp}popd# Move into placemv ${fedora_spec_temp} ${fedora_spec_file}# Clean uprm -rf ${fedora_changelog_temp} ${fedora_spec_temp_dir}# Stage the changed files for commitgit add ${shared_version_file} ${debian_changelog_file} ${fedora_spec_file}git status# Write out the GitHub-formatted changelog for the merge request/release pagesecho ""echo "=== The GitHub-formatted changelog follows ==="echo -e "${changelog_string_github}"
 |