Merge pull request #3089 from fidencio/wip/kata-deploy-remove-files-and-revert-removal-as-part-of-the-release-scripts

tools: Automatically revert kata-deploy changes
This commit is contained in:
Fabiano Fidêncio
2021-11-25 15:23:52 +01:00
committed by GitHub

View File

@@ -34,12 +34,8 @@ handle_error() {
trap 'handle_error $LINENO' ERR trap 'handle_error $LINENO' ERR
get_changes() { get_changes() {
local current_version=$1 local current_version="$1"
[ -n "${current_version}" ] || die "current version not provided" [ -n "${current_version}" ] || die "current version not provided"
if [ "${current_version}" == "new" ];then
echo "Starting to version this repository"
return
fi
# If for some reason there is not a tag this could fail # If for some reason there is not a tag this could fail
# better fail and write the error in the PR # better fail and write the error in the PR
@@ -62,9 +58,41 @@ get_changes() {
git log --oneline "${current_version}..HEAD" --no-merges git log --oneline "${current_version}..HEAD" --no-merges
} }
generate_kata_deploy_commit() {
local new_version="$1"
[ -n "$new_version" ] || die "no new version"
printf "release: Adapt kata-deploy for %s" "${new_version}"
printf "\n
kata-deploy files must be adapted to a new release. The cases where it
happens are when the release goes from -> to:
* main -> stable:
* kata-deploy / kata-cleanup: change from \"latest\" to \"rc0\"
* kata-deploy-stable / kata-cleanup-stable: are removed
* stable -> stable:
* kata-deploy / kata-cleanup: bump the release to the new one.
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() { generate_commit() {
local new_version=$1 local new_version="$1"
local current_version=$2 local current_version="$2"
[ -n "$new_version" ] || die "no new version" [ -n "$new_version" ] || die "no new version"
[ -n "$current_version" ] || die "no current version" [ -n "$current_version" ] || die "no current version"
@@ -90,25 +118,26 @@ bump_repo() {
pushd "${repo}" >>/dev/null pushd "${repo}" >>/dev/null
local kata_deploy_dir="tools/packaging/kata-deploy"
local kata_deploy_base="${kata_deploy_dir}/kata-deploy/base"
local kata_cleanup_base="${kata_deploy_dir}/kata-cleanup/base"
local kata_deploy_yaml="${kata_deploy_base}/kata-deploy.yaml"
local kata_cleanup_yaml="${kata_cleanup_base}/kata-cleanup.yaml"
local kata_deploy_stable_yaml="${kata_deploy_base}/kata-deploy-stable.yaml"
local kata_cleanup_stable_yaml="${kata_cleanup_base}/kata-cleanup-stable.yaml"
branch="${new_version}-branch-bump" branch="${new_version}-branch-bump"
git fetch origin "${target_branch}" git fetch origin "${target_branch}"
git checkout "origin/${target_branch}" -b "${branch}" git checkout "origin/${target_branch}" -b "${branch}"
# All repos we build should have a VERSION file local current_version="$(egrep -v '^(#|$)' ./VERSION)"
if [ ! -f "VERSION" ]; then
current_version="new"
echo "${new_version}" >VERSION
else
current_version="$(grep -v '#' ./VERSION)"
info "Updating VERSION file" info "Updating VERSION file"
echo "${new_version}" >VERSION echo "${new_version}" >VERSION
if git diff --exit-code; then if git diff --exit-code; then
info "${repo} already in version ${new_version}" info "${repo} already in version ${new_version}"
cat VERSION
return 0 return 0
fi fi
fi
if [ "${repo}" == "kata-containers" ]; then if [ "${repo}" == "kata-containers" ]; then
# Here there are 3 scenarios of what we can do, based on # Here there are 3 scenarios of what we can do, based on
@@ -119,23 +148,23 @@ bump_repo() {
# #
# +----------------+----------------+ # +----------------+----------------+
# | from | to | # | from | to |
# -----------------+----------------+----------------+ # -------------------+----------------+----------------+
# kata-deploy | "latest" | "latest" | # kata-deploy | "latest" | "latest" |
# -----------------+----------------+----------------+ # -------------------+----------------+----------------+
# kata-deploy-base | "stable | "stable" | # kata-deploy-stable | "stable | "stable" |
# -----------------+----------------+----------------+ # -------------------+----------------+----------------+
# #
# #
# 2) [main] ------> [stable] Update kata-deploy and # 2) [main] ------> [stable] Update kata-deploy and
# "alpha2" "rc0" get rid of kata-deploy-base # "alpha2" "rc0" get rid of kata-deploy-stable
# #
# +----------------+----------------+ # +----------------+----------------+
# | from | to | # | from | to |
# -----------------+----------------+----------------+ # -------------------+----------------+----------------+
# kata-deploy | "latest" | "rc0" | # kata-deploy | "latest" | "rc0" |
# -----------------+----------------+----------------+ # -------------------+----------------+----------------+
# kata-deploy-base | "stable" | REMOVED | # kata-deploy-stable | "stable" | REMOVED |
# -----------------+----------------+----------------+ # -------------------+----------------+----------------+
# #
# #
# 3) [stable] ------> [stable] Update kata-deploy # 3) [stable] ------> [stable] Update kata-deploy
@@ -143,35 +172,44 @@ bump_repo() {
# #
# +----------------+----------------+ # +----------------+----------------+
# | from | to | # | from | to |
# -----------------+----------------+----------------+ # -------------------+----------------+----------------+
# kata-deploy | "x.y.z" | "x.y.(z+1)" | # kata-deploy | "x.y.z" | "x.y.(z+1)" |
# -----------------+----------------+----------------+ # -------------------+----------------+----------------+
# kata-deploy-base | NON-EXISTENT | NON-EXISTENT | # kata-deploy-stable | NON-EXISTENT | NON-EXISTENT |
# -----------------+----------------+----------------+ # -------------------+----------------+----------------+
local registry="quay.io/kata-containers/kata-deploy"
info "Updating kata-deploy / kata-cleanup image tags" info "Updating kata-deploy / kata-cleanup image tags"
if [ "${target_branch}" == "main" ] && [[ "${new_version}" =~ "rc" ]]; then local version_to_replace="${current_version}"
# case 2) local replacement="${new_version}"
## change the "latest" tag to the "#{new_version}" one if [ "${target_branch}" == "main" ]; then
sed -i "s#quay.io/kata-containers/kata-deploy:latest#quay.io/kata-containers/kata-deploy:${new_version}#g" tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml if [[ "${new_version}" =~ "rc" ]]; then
sed -i "s#quay.io/kata-containers/kata-deploy:latest#quay.io/kata-containers/kata-deploy:${new_version}#g" tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml ## this is the case 2) where we remove te kata-deploy / kata-cleanup stable files
git rm "${kata_deploy_stable_yaml}"
git rm "${kata_cleanup_stable_yaml}"
else
## this is the case 1) where we just do nothing
replacement="latest"
fi
version_to_replace="latest"
fi
if [ "${version_to_replace}" != "${replacement}" ]; then
## this covers case 2) and 3), as on both of them we have changes on kata-deploy / kata-cleanup files
sed -i "s#${registry}:${version_to_replace}#${registry}:${new_version}#g" "${kata_deploy_yaml}"
sed -i "s#${registry}:${version_to_replace}#${registry}:${new_version}#g" "${kata_cleanup_yaml}"
git diff git diff
git add tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml git add "${kata_deploy_yaml}"
git add tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml git add "${kata_cleanup_yaml}"
## and remove the kata-deploy & kata-cleanup stable yaml files info "Creating the commit with the kata-deploy changes"
git rm tools/packaging/kata-deploy/kata-deploy/base/kata-deploy-stable.yaml local commit_msg="$(generate_kata_deploy_commit $new_version)"
git rm tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup-stable.yaml git commit -s -m "${commit_msg}"
elif [[ "${target_branch}" =~ "stable" ]]; then local kata_deploy_commit="$(git rev-parse HEAD)"
# case 3)
sed -i "s#quay.io/kata-containers/kata-deploy:${current_version}#quay.io/kata-containers/kata-deploy:${new_version}#g" tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml
sed -i "s#quay.io/kata-containers/kata-deploy:${current_version}#quay.io/kata-containers/kata-deploy:${new_version}#g" tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml
git diff
git add tools/packaging/kata-deploy/kata-deploy/base/kata-deploy.yaml
git add tools/packaging/kata-deploy/kata-cleanup/base/kata-cleanup.yaml
fi fi
fi fi
@@ -206,8 +244,31 @@ EOT
${hub_bin} push fork -f "${branch}" ${hub_bin} push fork -f "${branch}"
info "Create PR" info "Create PR"
out="" out=""
out=$("${hub_bin}" pull-request -b "${target_branch}" -F "${notes_file}" 2>&1) || echo "$out" | grep "A pull request already exists" out=$(LC_ALL=C LANG=C "${hub_bin}" pull-request -b "${target_branch}" -F "${notes_file}" 2>&1) || echo "$out" | grep "A pull request already exists"
fi 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=$(LC_ALL=C LANG=C "${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 popd >>/dev/null
} }
@@ -244,8 +305,8 @@ main(){
shift $((OPTIND - 1)) shift $((OPTIND - 1))
new_version=${1:-} new_version="${1:-}"
target_branch=${2:-} target_branch="${2:-}"
[ -n "${new_version}" ] || { echo "ERROR: no new version" && usage 1; } [ -n "${new_version}" ] || { echo "ERROR: no new version" && usage 1; }
[ -n "${target_branch}" ] || die "no target branch" [ -n "${target_branch}" ] || die "no target branch"
for repo in "${repos[@]}" for repo in "${repos[@]}"