From 471496188992a8789073ebc651e1345debb05fee Mon Sep 17 00:00:00 2001 From: Kleber Sacilotto de Souza Date: Thu, 6 Dec 2018 13:42:51 +0000 Subject: [PATCH] UBUNTU: [Packaging] update helper scripts BugLink: http://bugs.launchpad.net/bugs/1786013 Signed-off-by: Kleber Sacilotto de Souza --- debian/scripts/helpers/close | 140 ++++++++++++++++++++++++++++++++++ debian/scripts/helpers/rebase | 129 +++++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100755 debian/scripts/helpers/close create mode 100755 debian/scripts/helpers/rebase diff --git a/debian/scripts/helpers/close b/debian/scripts/helpers/close new file mode 100755 index 000000000000..3306d39f5c59 --- /dev/null +++ b/debian/scripts/helpers/close @@ -0,0 +1,140 @@ +#!/bin/bash -e +# +# This script is intended as a helper when closing a release. +# +source debian/debian.env + +# Parse args +usage="$0 [-c] [-d]"$'\n\n' +usage+="-c include config changes in the closing commit."$'\n' +usage+="-d Dry run (do not change files or commit)." +while getopts "cd" opt; do + case $opt in + c) commit_configs=1 ;; + d) dry_run=1 ;; + *) echo usage: "${usage}"; exit ;; + esac +done + +hl() { echo -e "\e[1m$*\e[0m"; } + +run() { + # Quote args for echo or eval + local quoted=() + for token; do + quoted+=( "$(printf '%q' "$token")" ) + done + # Run + if [ "$dry_run" ]; then + hl "DRY RUN: ${quoted[*]}" + else + hl "${quoted[*]}" + eval "${quoted[*]}" + echo + fi +} + +# Check if the "debian./" directory exists. +if [ ! -d "$DEBIAN" ]; then + echo "You must run this script from the top directory of this repository." + exit 1 +fi +branch="${DEBIAN#*.}" + +# Check if changelog is open +series=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SDistribution) +if [ "$series" != 'UNRELEASED' ]; then + echo "The last entry of the changelog is already released." + exit 1 +fi + +# Update configs +run fakeroot debian/rules clean updateconfigs +changes=$(git diff HEAD -- "./$DEBIAN/config/") +if ! [ "$commit_configs" ] && [ "$changes" ]; then + echo "Config has changed! please, review it and commit." + exit 1 +fi + +# Derivatives have at least one base kernel. +if [ "$branch" != 'master' ]; then + skip_master_entries= + + # For backports, insert the changes from the base derivative. + # Straight derivatives and backports such as hwe and hwe-edge, should + # skip that step and fetch the entries directly from the master kernel. + version=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SVersion) + if [[ $version == *~* ]]; then + base_version=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SVersion -c1 -o1) + base_changelog="${DEBIAN%-*}/changelog" + if [ -f "$base_changelog" ] && [ "$DEBIAN" != "${DEBIAN%-*}" ]; then + run ./debian/scripts/misc/insert-ubuntu-changes "$DEBIAN/changelog" "${base_version%%~*}" "${version%%~*}" "$base_changelog" + skip_master_entries=1 + fi + fi + + if ! [ "$skip_master_entries" ]; then + offset=0 + # Loop through each entry of the current changelog, searching for an + # entry that refers to the master version used as base (ie a line + # containing "[ Ubuntu: 4.15.0-39.42 ]"): + while true; do + changes=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SChanges -c1 -o"$offset") + if ! [ "$changes" ]; then + echo "Failed to retrieve base master version from changelog file: $DEBIAN/changelog" + exit 1 + fi + base_master_version=$(echo "$changes" | sed -n -r -e '/^\s.*\[ Ubuntu: ([0-9.-]*) \]$/{s//\1/p;q}') + [ "$base_master_version" ] && break + offset=$(( offset + 1 )) + done + master_version=$(dpkg-parsechangelog -ldebian.master/changelog -SVersion) + if ! [ "$master_version" ]; then + echo "Failed to retrieve current master version from changelog: $DEBIAN/changelog" + exit 1 + fi + run ./debian/scripts/misc/insert-ubuntu-changes "$DEBIAN/changelog" "$base_master_version" "$master_version" + fi +fi + +# Insert local changes +run fakeroot debian/rules insertchanges + +# This should be the last step. If there were no changes to the +# changelog, there is nothing to release, so nothing to commit. +changes=$(git diff HEAD) +if ! [ "$changes" ] && ! [ "$dry_run" ]; then + hl "No changes to commit." + exit 1 +fi + +# Find the current series from previous changelog entries: +series='' +offset=0 +while true; do + series=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SDistribution -c1 -o"$offset") + if [ "$series" ] && [ "$series" != 'UNRELEASED' ]; then + break + fi + offset=$(( offset + 1 )) +done +if ! [ "$series" ]; then + echo "Failed to retrieve the package series from changelog: $DEBIAN/changelog" + exit 1 +fi +# Close the changelog +run dch --nomultimaint -c "$DEBIAN/changelog" -r -D "$series" '' + +# Commit changes +package=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SSource) +prefix="Ubuntu$(echo "$package" | sed -r -e 's/linux(-?)/\1/')-" +version=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SVersion) +run git commit -sam "UBUNTU: $prefix$version" + +# This should only show the tag. If it starts tagging, we might revisit +# where it is called, or not fail if it points to the same thing, and +# warns/errors out if the tag exists, but do not point to the same +# thing. +alt_version="${version//\~/_}" +head=$(git rev-parse HEAD) +echo "git tag -sm '$prefix$version' '$prefix$alt_version' $head" diff --git a/debian/scripts/helpers/rebase b/debian/scripts/helpers/rebase new file mode 100755 index 000000000000..e3f59e0b92e1 --- /dev/null +++ b/debian/scripts/helpers/rebase @@ -0,0 +1,129 @@ +#!/bin/bash -e +# +# This script is intended as a helper when rebasing from its master branch. +# + +LOCAL_BRANCH= +RELEASE_REPO= +SOURCE_RELEASE_BRANCH= + +function out() +{ + local rc="${?}" + trap - EXIT INT TERM HUP + [ "${rc}" -eq 0 ] || echo "Error: Script failed" + exit "${rc}" +} + +trap out EXIT INT TERM HUP + +if [ -f debian/debian.env ]; then + source debian/debian.env +fi + +if [ ! -d "${DEBIAN}" ]; then + echo You must run this script from the top directory of this repository. + exit 1 +fi + +CONF="${DEBIAN}"/etc/update.conf +if [ -f "${CONF}" ]; then + source "${CONF}" +fi + +usage="$0 [-r RELEASE_REPO] [ -b REMOTE_BRANCH ] [-l LOCAL_BRANCH] [-d]"$'\n\n' +usage+="-r RELEASE_REPO Git repository to fetch the reference branch from."$'\n' +usage+="-b REMOTE_BRANCH Remote branch to fetch from."$'\n' +usage+="-l LOCAL_BRANCH Use LOCAL_BRANCH as the reference branch."$'\n' +usage+="-d Dry run (do not rebase)." + +# +# command line options: +# [-r RELEASE_REPO] - override default git repository. +# [-b REMOTE_BRANCH] - override default remote branch. +# [-l LOCAL_BRANCH] - do not fetch from remote repo, use a local branch. + +while getopts "r:b:l:d" opt; do + case $opt in + r ) RELEASE_REPO="$OPTARG" ;; + b ) SOURCE_RELEASE_BRANCH="$OPTARG" ;; + l ) LOCAL_BRANCH="$OPTARG" ;; + d ) DRY_RUN=1 ;; + \? ) echo "usage: ${usage}"; exit ;; + esac +done +shift $((OPTIND - 1)) + +if [ -z "${LOCAL_BRANCH}" ]; then + if [ -z "${RELEASE_REPO}" ] || [ -z "${SOURCE_RELEASE_BRANCH}" ]; then + echo Missing update.conf or missing parameters for remote repo and branch. + exit 1 + fi + # + # Fetch the upstream branch. + # + git fetch "${RELEASE_REPO}" + git fetch "${RELEASE_REPO}" "${SOURCE_RELEASE_BRANCH}" + LOCAL_BRANCH=FETCH_HEAD +fi + +if [ "$DEBIAN" = "debian.master" ]; then + echo "This is a master kernel, no rebase should be needed, please report if otherwise" + exit 0 +fi + +if [ "$DEBIAN_MASTER" = "" ]; then + echo "DEBIAN_MASTER should be defined either in ${DEBIAN}/etc/update.conf or the environment" + exit 1 +fi + +# +# Find the most recent tag on given upstream branch, then +# rebase against it. This avoids the case where there have been some +# commits since the last official tag. +# +MASTER_COMMIT=$(git log --pretty=one "${LOCAL_BRANCH}" "${DEBIAN_MASTER}" | \ + awk ' + /Ubuntu-/ { + if (match($0, /UBUNTU: Ubuntu-/)) { + print $1 + exit + } + } + ' +) +# +# Find the current merge point where current branch was based. +# +BASE_COMMIT=$(git log --pretty=one "${DEBIAN_MASTER}" | \ + awk ' + /Ubuntu-/ { + if (match($0, /UBUNTU: Ubuntu-/)) { + print $1 + exit + } + } + ' +) +if [ "${MASTER_COMMIT}" = "${BASE_COMMIT}" ]; then + echo Already up to date. + exit 0 +fi + +if [ -z "${MASTER_COMMIT}" ] || [ -z "${BASE_COMMIT}" ]; then + echo "Could not find either master or base commit." + echo "master commit: ${MASTER_COMMIT}" + echo "base commit: ${BASE_COMMIT}" + exit 1 +fi + +MASTER_VERSION=$(git show --format=%s -s "$MASTER_COMMIT" | sed 's/^UBUNTU: //') +BASE_VERSION=$(git show --format=%s -s "$BASE_COMMIT" | sed 's/^UBUNTU: //') +echo "Rebase still needed between $BASE_VERSION and $MASTER_VERSION." + +if [ "${DRY_RUN}" ]; then + echo "DRY RUN: git rebase --onto ${MASTER_COMMIT} ${BASE_COMMIT}" + exit 0 +fi + +git rebase --onto "${MASTER_COMMIT}" "${BASE_COMMIT}" -- 2.39.2