From e12f1df807473b20459673d54d3237cd0ef9e565 Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Wed, 20 Jun 2018 16:12:27 -0500 Subject: [PATCH 1/4] release: add script to bump repositories Add script that will help to bump versions for all the projects. Fixes: #49 Signed-off-by: Jose Carlos Venegas Munoz --- release/update-repository-version.sh | 169 +++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100755 release/update-repository-version.sh diff --git a/release/update-repository-version.sh b/release/update-repository-version.sh new file mode 100755 index 000000000..bec22e597 --- /dev/null +++ b/release/update-repository-version.sh @@ -0,0 +1,169 @@ +#!/bin/bash +# +# Copyright (c) 2018 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# + +set -o errexit +set -o nounset +set -o pipefail + +readonly script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +readonly script_name="$(basename "${BASH_SOURCE[0]}")" + +readonly tmp_dir=$(mktemp -t -d pr-bump.XXXX) +readonly hub_bin="${tmp_dir}/hub-bin" +readonly organization="kata-containers" +PUSH="false" +GOPATH=${GOPATH:-${HOME}/go} + +cleanup (){ + [ -d "${tmp_dir}" ] && rm -rf "${tmp_dir}" +} + +trap cleanup EXIT + +die() +{ + msg="$*" + echo "ERROR: ${msg}" >&2 + exit 1 +} + +info() +{ + msg="$*" + echo "INFO: ${msg}" >&2 +} + +build_hub() { + info "Get hub" + local hub_repo="github.com/github/hub" + local hub_repo_dir="${GOPATH}/src/${hub_repo}" + [ -d "${hub_repo_dir}" ]|| git clone --quiet --depth 1 "https://${hub_repo}.git" "${hub_repo_dir}" + pushd "${hub_repo_dir}" >> /dev/null + git checkout master + git pull + ./script/build -o "${hub_bin}" + popd >> /dev/null +} + +get_changes() { + local current_version=$1 + [ -n "${current_version}" ] || die "current version not provided" + + changes=$(git log --oneline "${current_version}..HEAD") || die "failed to get logs" + if [ "${changes}" == "" ]; then + echo "Version bump no changes" + return + fi + + # list all PRs merged from $current_version to HEAD + git log --merges "${current_version}..HEAD" | awk '/Merge pull/{getline; getline;print }' | while read pr + do + echo "- ${pr}" + done + + echo "" + + # list all commits added in this new version. + git log --oneline "${current_version}..HEAD" --no-merges +} + +generate_commit() { + local new_version=$1 + local current_version=$2 + + [ -n "$new_version" ] || die "no new version" + [ -n "$current_version" ] || die "no current version" + + printf "release: Kata Containers %s\n\n" "${new_version}" + + get_changes "$current_version" +} + +bump_repo() { + repo=$1 + new_version=$2 + [ -n "${repo}" ] || die "repository not provided" + [ -n "$new_version" ] || die "no new version" + remote_github="https://github.com/${organization}/${repo}.git" + info "Update $repo to version $new_version" + + info "remote: ${remote_github}" + + git clone --quiet "${remote_github}" + + pushd "${repo}" >> /dev/null + + # All repos we build should have a VERSION file + [ -f "VERSION" ] || die "VERSION file not found " + current_version="$(cat ./VERSION | grep -v '#')" + + info "Creating PR message" + notes_file=notes.md + cat << EOT > "${notes_file}" +# Kata Containers ${new_version} + +$(get_changes "$current_version") + +EOT + + info "Updating VERSION file" + echo "${new_version}" > VERSION + branch="${new_version}-branch-bump" + git checkout -b "${branch}" master + git add -u + info "Creating commit with new changes" + commit_msg="$(generate_commit $new_version $current_version)" + git commit -s -m "${commit_msg}" + + if [[ "${PUSH}" == "true" ]]; then + build_hub + info "Forking remote" + ${hub_bin} fork --remote-name=fork + info "Push to fork" + ${hub_bin} push fork -f "${branch}" + info "Create PR" + out="" + out=$("${hub_bin}" pull-request -F "${notes_file}" 2>&1) || echo "$out" | grep "A pull request already exists" + fi + popd >> /dev/null +} + +usage(){ + exit_code="$1" + cat < +Args: + : Name of repository to fork and send PR from github.com/${organization} + : New version to bump the repository +Example: + ${script_name} 1.10 +Options + -h : Show this help + -p : create a PR +EOT + exit "$exit_code" +} + +while getopts "hp" opt +do + case $opt in + h) usage 0 ;; + p) PUSH="true" ;; + esac +done + +shift $(( $OPTIND - 1 )) + +repo=${1:-} +new_version=${2:-} +[ -n "${repo}" ] || (echo "ERROR: repository not provided" && usage 1) +[ -n "$new_version" ] || (echo "ERROR: no new version" && usage 1 ) + +pushd "$tmp_dir" >> /dev/null +bump_repo "${repo}" "${new_version}" +popd >> /dev/null From 4fef836ffdf70401a9974d41d29c5975751650da Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Wed, 20 Jun 2018 16:58:31 -0500 Subject: [PATCH 2/4] release: Add make target to bump repos. Add a target to bump all repos in one command. Signed-off-by: Jose Carlos Venegas Munoz --- release/Makefile | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 release/Makefile diff --git a/release/Makefile b/release/Makefile new file mode 100644 index 000000000..12c5e5f1f --- /dev/null +++ b/release/Makefile @@ -0,0 +1,30 @@ +# +# Copyright (c) 2018 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# +# + +MK_DIR :=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) +.PHONY: bump-kata-version + +NEW_VERSION := + +# Run update-repository-version.sh +# $1 : repository to bump +define BUMP_REPO + @echo "Create PR for $1 version $(NEW_VERSION)" + @$(MK_DIR)/update-repository-version.sh -p $1 $(NEW_VERSION) +endef + +bump-kata-version: $(REPOS) +ifeq ($(NEW_VERSION),) + $(error NEW_VERSION variable is empty, provide a version) +else + $(call BUMP_REPO,agent) + $(call BUMP_REPO,ksm-throttler) + $(call BUMP_REPO,osbuilder) + $(call BUMP_REPO,proxy) + $(call BUMP_REPO,runtime) + $(call BUMP_REPO,shim) +endif From d9736af0ba5142f8b2a8e07096fac93925d84c61 Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Wed, 20 Jun 2018 16:59:05 -0500 Subject: [PATCH 3/4] docs: Add information about new release tool. Add docs about the version bump script. Signed-off-by: Jose Carlos Venegas Munoz --- release/README.md | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/release/README.md b/release/README.md index c513517ae..10d4f4763 100644 --- a/release/README.md +++ b/release/README.md @@ -2,14 +2,43 @@ This directory contains tools for Kata Containers releases. +## update-repository-version.sh ## + +This script creates a GitHub pull request (a.k.a PR) to change the version in +all the Kata repositories. + +For more information on using the script, run the following: + +```bash +$ ./update-repository-version.sh -h +``` + +### Update Kata projects to a new version ### +Kata Containers is divided into multiple projects. With each release, all +project versions are updated to keep the version consistent. + +To update all versions for all projects, use the following: + +```bash +$ make bump-kata-version NEW_VERSION= +``` + +The makefile target bump-kata-version creates a GitHub pull request in the Kata +repositories. These pull requests are tested by the Kata CI to ensure the +entire project is working prior to the release. Next, the PR is approved and +merged by Kata Containers members. + ## tag_repos.sh ## -The `tag_repos.sh` script is used to create tags for the Kata Containers -repositories. This script ensures that all the repositories are in the -same version (by checking the `VERSION` file). +After all the Kata repositories are updated with a new version, they need to be +tagged. -The script creates an **annotated tag** for the new release version for -the following repositories: +The `tag_repos.sh` script is used to create tags for the Kata Containers +repositories. This script ensures that all the repositories are in the same +version (by checking the `VERSION` file). + +The script creates an **annotated tag** for the new release version for the +following repositories: - agent - proxy @@ -17,5 +46,5 @@ the following repositories: - shim - throttler -The script also tags the tests and osbuilder repositories to make it clear -which versions of these supporting repositories are used for the release. +The script also tags the tests and osbuilder repositories to make it clear which +versions of these supporting repositories are used for the release. From 4eb3a3dcd1108ae8d441c980eae4230e46a19fa9 Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Thu, 28 Jun 2018 20:44:07 -0500 Subject: [PATCH 4/4] test: Add test update-repository-version.sh Add some basic test to verify the script works. Signed-off-by: Jose Carlos Venegas Munoz --- Makefile | 1 + release/update-repository-version_test.sh | 54 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100755 release/update-repository-version_test.sh diff --git a/Makefile b/Makefile index 14308d14e..73ba5f7d9 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ test: test-release-tools: @$(MK_DIR)/release/tag_repos_test.sh + @$(MK_DIR)/release/update-repository-version_test.sh test-static-build: @make -f $(MK_DIR)/static-build/qemu/Makefile diff --git a/release/update-repository-version_test.sh b/release/update-repository-version_test.sh new file mode 100755 index 000000000..590a5d0e5 --- /dev/null +++ b/release/update-repository-version_test.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# +#Copyright (c) 2018 Intel Corporation +# +#SPDX-License-Identifier: Apache-2.0 +# + +set -o errexit +set -o nounset +set -o pipefail + +readonly script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +out="" + +handle_error(){ + echo "not ok" + echo "output: ${out}" +} + +OK(){ + echo "ok" +} +output_should_contain(){ + local output="$1" + local text_to_find="$2" + [ -n "$output" ] + [ -n "$text_to_find" ] + echo "${output}" | grep "${text_to_find}" +} + +trap handle_error ERR + +echo "Missing args show help" +out=$("${script_dir}/update-repository-version.sh" 2>&1) || (($?!=0)) +echo "${out}" | grep Usage >> /dev/null +output_should_contain "${out}" "Usage" +OK + +echo "Missing version show help" +out=$("${script_dir}/update-repository-version.sh" runtime 2>&1) || (($?!=0)) +echo "${out}" | grep Usage >> /dev/null +echo "${out}" | grep "no new version">> /dev/null +OK + +echo "help option" +out=$("${script_dir}/update-repository-version.sh" -h) +output_should_contain "${out}" "Usage" +OK + +echo "Local update version update should work" +new_version=50.0.0 +out=$("${script_dir}/update-repository-version.sh" runtime ${new_version} 2>&1) +output_should_contain "${out}" "release: Kata Containers ${new_version}" +OK