From edfd950aad5f79d0cfabacf79674a323f1d93520 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sat, 19 Jan 2019 18:11:01 -0500 Subject: Add bump_version script --- bump_version | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100755 bump_version (limited to 'bump_version') diff --git a/bump_version b/bump_version new file mode 100755 index 0000000000..0e849c4678 --- /dev/null +++ b/bump_version @@ -0,0 +1,189 @@ +#!/usr/bin/env bash + +# bump_version - increase the shared version and generate changelogs + +set -o errexit +set -o pipefail + +usage() { + echo -e "bump_version - increase the shared version and generate changelogs" + echo -e "" + echo -e "Usage:" + echo -e " $ bump_version [-b/--web-branch ] " + 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 1 +fi + +shared_version_file="./SharedVersion.cs" + +# Parse branch option +if [[ $1 == '-b' || $1 == '--web-branch' ]]; then + web_branch="$2" + shift 2 +else + web_branch="$( git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' )" +fi + +# Initialize submodules +git submodule update --init --recursive + +# configure branch +pushd MediaBrowser.WebDashboard/jellyfin-web +git fetch --all +git checkout origin/${web_branch} || { + echo "jellyfin-web branch ${web_branch} is invalid." + exit 1 +} +popd + +new_version="$1" + +# Parse the version from the AssemblyVersion +old_version="$( + grep "AssemblyVersion" ${shared_version_file} \ + | sed -E 's/\[assembly: ?AssemblyVersion\("([0-9\.]+)"\)\]/\1/' \ + | sed -E 's/.0$//' +)" + +# Set the shared version to the specified new_version +old_version_sed="$( sed 's/\./\\./g' <<<"${old_version}" )" # Escape the '.' chars +sed -i "s/${old_version_sed}/${new_version}/g" ${shared_version_file} + +declare -a pr_merges_since_last_master +declare changelog_string_github +declare changelog_string_deb +declare changelog_string_yum + +# Build up a changelog from merge commits +for 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="master-${old_version}" # TODO: Set to `release-` for next release, so we can properly parse both repos with the new branch standard + 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 )" + + popd +done + +# Write out a temporary Debian changelog with our new stuff appended and some templated formatting +debian_changelog_file="deployment/debian-package-x64/pkg-src/changelog" +debian_changelog_temp="$( mktemp )" +# Create new temp file with our changelog +echo -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 $( date --rfc-2822 ) +" >> ${debian_changelog_temp} +cat ${debian_changelog_file} >> ${debian_changelog_temp} +# Edit the file to verify +$EDITOR ${debian_changelog_temp} +# Move into place +mv ${debian_changelog_temp} ${debian_changelog_file} +# Clean up +rm -f ${debian_changelog_temp} + +# Write out a temporary Yum changelog with our new stuff prepended and some templated formatting +fedora_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 hacking +cp ${fedora_spec_file} ${fedora_spec_temp_dir}/ +pushd ${fedora_spec_temp_dir} +# Split out the stuff before and after changelog +csplit jellyfin.spec "/^%changelog/" # produces xx00 xx01 +# Update the version in xx00 +sed -i "s/${old_version_sed}/${new_version}/g" xx00 +# Remove the header from xx01 +sed -i '/^%changelog/d' xx01 +# Create new temp file with our changelog +echo -e "### YUM SPEC CHANGELOG: Verify this file looks correct or edit accordingly, then delete this line, write, and exit. +%changelog +* $( date '+%a %b %d %Y' ) Jellyfin Packaging Team ${changelog_string_yum}" >> ${fedora_changelog_temp} +cat xx01 >> ${fedora_changelog_temp} +# Edit the file to verify +$EDITOR ${fedora_changelog_temp} +# Reassembble +cat xx00 ${fedora_changelog_temp} > ${fedora_spec_temp} +popd +# Move into place +mv ${fedora_spec_temp} ${fedora_spec_file} +# Clean up +rm -rf ${fedora_changelog_temp} ${fedora_spec_temp_dir} + +# Stage the changed files for commit +git add ${shared_version_file} ${debian_changelog_file} ${fedora_spec_file} +git status + +# Write out the GitHub-formatted changelog for the merge request/release pages +echo "" +echo "=== The GitHub-formatted changelog follows ===" +echo -e "${changelog_string_github}" -- cgit v1.2.3 From 90b9a9561900d4e59531c9e15749b76728c09f6b Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sun, 20 Jan 2019 12:23:36 -0500 Subject: Use LANG=C for date in Yum changelog --- bump_version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bump_version') diff --git a/bump_version b/bump_version index 0e849c4678..3f75a93cb6 100755 --- a/bump_version +++ b/bump_version @@ -167,7 +167,7 @@ sed -i '/^%changelog/d' xx01 # Create new temp file with our changelog echo -e "### YUM SPEC CHANGELOG: Verify this file looks correct or edit accordingly, then delete this line, write, and exit. %changelog -* $( date '+%a %b %d %Y' ) Jellyfin Packaging Team ${changelog_string_yum}" >> ${fedora_changelog_temp} +* $( LANG=C date '+%a %b %d %Y' ) Jellyfin Packaging Team ${changelog_string_yum}" >> ${fedora_changelog_temp} cat xx01 >> ${fedora_changelog_temp} # Edit the file to verify $EDITOR ${fedora_changelog_temp} -- cgit v1.2.3 From 56365e923730e9aa9a4cbf6085877d0b4f6a027d Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sun, 20 Jan 2019 13:19:50 -0500 Subject: Bail out if web branch is unclean like build does --- bump_version | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'bump_version') diff --git a/bump_version b/bump_version index 3f75a93cb6..06a690e195 100755 --- a/bump_version +++ b/bump_version @@ -36,9 +36,19 @@ git submodule update --init --recursive # configure branch pushd MediaBrowser.WebDashboard/jellyfin-web + +if ! 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 1 +fi + git fetch --all git checkout origin/${web_branch} || { - echo "jellyfin-web branch ${web_branch} is invalid." + echo "ERROR: 'jellyfin-web' branch ${web_branch} is invalid." exit 1 } popd -- cgit v1.2.3 From adf037c44c798b366b90e047bc62c40b72a883f2 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sun, 20 Jan 2019 23:41:37 -0500 Subject: Complete and remove todo from bump_version --- bump_version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bump_version') diff --git a/bump_version b/bump_version index 06a690e195..f0917ad65e 100755 --- a/bump_version +++ b/bump_version @@ -94,7 +94,7 @@ for repo in ./ MediaBrowser.WebDashboard/jellyfin-web/; do pushd ${repo} # Find the last release commit, so we know what's happened since - 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 + last_master_branch="release-${old_version}" last_master_merge_commit="$( git log --merges --pretty=oneline \ | grep -F "${last_master_branch}" \ -- cgit v1.2.3 From c72144111e15b37255d1522962273cac69ea54f9 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Mon, 21 Jan 2019 00:00:16 -0500 Subject: Correct bad signature line --- bump_version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bump_version') diff --git a/bump_version b/bump_version index f0917ad65e..0db6c18ad6 100755 --- a/bump_version +++ b/bump_version @@ -150,7 +150,7 @@ echo -e "### DEBIAN PACKAGE CHANGELOG: Verify this file looks correct or edit ac jellyfin (${new_version}-1) unstable; urgency=medium ${changelog_string_deb} --- Jellyfin Packaging Team $( date --rfc-2822 ) + -- Jellyfin Packaging Team $( date --rfc-2822 ) " >> ${debian_changelog_temp} cat ${debian_changelog_file} >> ${debian_changelog_temp} # Edit the file to verify -- cgit v1.2.3 From cf85e2327ed8fc0c3bdb54b08b5708b31bb0262d Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Mon, 21 Jan 2019 12:10:48 -0500 Subject: Support trying local branches in submodule --- build | 18 ++++++++++++++---- bump_version | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'bump_version') diff --git a/build b/build index b922cf72a9..5c081af6e5 100755 --- a/build +++ b/build @@ -171,10 +171,20 @@ if ! git diff-index --quiet HEAD --; then fi git fetch --all -git checkout origin/${web_branch} || { - echo "ERROR: 'jellyfin-web' branch ${web_branch} is invalid." - exit 1 -} +# If this is an official branch name, fetch it from origin +official_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 + } +fi popd # Execute each platform and action in order, if said action is enabled diff --git a/bump_version b/bump_version index 0db6c18ad6..c3f1a78d50 100755 --- a/bump_version +++ b/bump_version @@ -47,10 +47,20 @@ if ! git diff-index --quiet HEAD --; then fi git fetch --all -git checkout origin/${web_branch} || { - echo "ERROR: 'jellyfin-web' branch ${web_branch} is invalid." - exit 1 -} +# If this is an official branch name, fetch it from origin +official_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 + } +fi popd new_version="$1" -- cgit v1.2.3