tools: Automatically revert kata-deploy changes

When branching the "stable-x.y" branch, we need to do some quite
specific changes to kata-deploy / kata-cleanup files, such as:
* changing the tags from "latest" to "stable-x.y".
* removing the kata-deploy / kata-cleanup stable files.

However, after the branching is done, we need to get the `main` repo to
its original state, with the kata-deploy / kata-cleanup using the
"latest" tag, and with the stable files present there, and this commit
ensures that, during the release process, a new PR is automatically
created with these changes.

Fixes: #3069

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
Fabiano Fidêncio 2021-11-21 12:11:16 +01:00
parent 36d73c96c8
commit 76540dbdd1

View File

@ -82,6 +82,18 @@ There are no changes when doing an alpha release, as the files on the
\"main\" branch always point to the \"latest\" and \"stable\" tags."
}
generate_revert_kata_deploy_commit() {
local new_version=$1
[ -n "$new_version" ] || die "no new version"
printf "release: Revert kata-deploy changes after %s release" "${new_version}"
printf "\n
As %s has been released, let's switch the kata-deploy / kata-cleanup
tags back to \"latest\", and re-add the kata-deploy-stable and the
kata-cleanup-stable files." "${new_version}"
}
generate_commit() {
local new_version=$1
local current_version=$2
@ -208,6 +220,7 @@ bump_repo() {
info "Creating the commit with the kata-deploy changes"
local commit_msg="$(generate_kata_deploy_commit $new_version)"
git commit -s -m "${commit_msg}"
local kata_deploy_commit="$(git rev-parse HEAD)"
fi
fi
@ -244,6 +257,29 @@ EOT
out=""
out=$("${hub_bin}" pull-request -b "${target_branch}" -F "${notes_file}" 2>&1) || echo "$out" | grep "A pull request already exists"
fi
if [ "${repo}" == "kata-containers" ] && [ "${target_branch}" == "main" ] && [[ "${new_version}" =~ "rc" ]]; then
reverting_kata_deploy_changes_branch="revert-kata-deploy-changes-after-${new_version}-release"
git checkout -b "${reverting_kata_deploy_changes_branch}"
git revert --no-edit ${kata_deploy_commit} >>/dev/null
commit_msg="$(generate_revert_kata_deploy_commit $new_version)"
info "Creating the commit message reverting the kata-deploy changes"
git commit --amend -s -m "${commit_msg}"
echo "${commit_msg}" >"${notes_file}"
echo "" >>"${notes_file}"
echo "Only merge this commit after ${new_version} release is successfully tagged!" >>"${notes_file}"
if [[ ${PUSH} == "true" ]]; then
info "Push \"${reverting_kata_deploy_changes_branch}\" to fork"
${hub_bin} push fork -f "${reverting_kata_deploy_changes_branch}"
info "Create \"${reverting_kata_deploy_changes_branch}\" PR"
out=""
out=$("${hub_bin}" pull-request -b "${target_branch}" -F "${notes_file}" 2>&1) || echo "$out" | grep "A pull request already exists"
fi
fi
popd >>/dev/null
}