Merge pull request #86 from jcvenegas/update-repository-version

Update repository version
This commit is contained in:
Eric Ernst
2018-07-10 14:43:47 -07:00
committed by GitHub
5 changed files with 290 additions and 7 deletions

View File

@@ -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

30
release/Makefile Normal file
View File

@@ -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

View File

@@ -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=<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.

View File

@@ -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 <<EOT
Usage:
${script_name} [options] <args>
Args:
<repository-name> : Name of repository to fork and send PR from github.com/${organization}
<new-version> : 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

View File

@@ -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