Merge pull request #567 from devimc/topic/obs-packaging/gen_versions

obs-packaging/gen_versions: add --head option
This commit is contained in:
Julio Montes 2019-06-12 11:06:43 -05:00 committed by GitHub
commit 4cf8c1e9e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 15 deletions

View File

@ -26,22 +26,34 @@ get_kata_version() {
gen_version_file() { gen_version_file() {
local branch="$1" local branch="$1"
[ -n "${branch}" ] || exit 1 local use_head="$2"
local ref="refs/heads/${branch}"
local kata_version="${branch}"
local kata_version=$(get_kata_version "${branch}") if [ -n "$branch" ] && [ -z "${use_head}" ]; then
kata_runtime_hash=$(get_kata_hash_from_tag "runtime" "${kata_version}") kata_version=$(get_kata_version "${branch}")
kata_proxy_hash=$(get_kata_hash_from_tag "proxy" "${kata_version}") ref="refs/tags/${kata_version}^{}"
kata_shim_hash=$(get_kata_hash_from_tag "shim" "${kata_version}") fi
kata_agent_hash=$(get_kata_hash_from_tag "agent" "${kata_version}")
kata_ksm_throttler_hash=$(get_kata_hash_from_tag "ksm-throttler" "${kata_version}") kata_runtime_hash=$(get_kata_hash "runtime" "${ref}")
kata_proxy_hash=$(get_kata_hash "proxy" "${ref}")
kata_shim_hash=$(get_kata_hash "shim" "${ref}")
kata_agent_hash=$(get_kata_hash "agent" "${ref}")
kata_ksm_throttler_hash=$(get_kata_hash "ksm-throttler" "${ref}")
qemu_lite_branch=$(get_from_kata_deps "assets.hypervisor.qemu-lite.branch" "${kata_version}") qemu_lite_branch=$(get_from_kata_deps "assets.hypervisor.qemu-lite.branch" "${kata_version}")
qemu_lite_version=$(curl -s -L "https://raw.githubusercontent.com/${project}/qemu/${qemu_lite_branch}/VERSION") qemu_lite_version=$(curl -s -L "https://raw.githubusercontent.com/${project}/qemu/${qemu_lite_branch}/VERSION")
qemu_lite_hash=$(git ls-remote https://github.com/${project}/qemu.git | grep "refs/heads/${qemu_lite_branch}" | awk '{print $1}') qemu_lite_hash=$(git ls-remote https://github.com/${project}/qemu.git | grep "refs/heads/${qemu_lite_branch}" | awk '{print $1}')
qemu_vanilla_branch=$(get_from_kata_deps "assets.hypervisor.qemu.version" "${kata_version}") qemu_vanilla_branch=$(get_from_kata_deps "assets.hypervisor.qemu.version" "${kata_version}")
# Check if qemu.version can be used to get the version and hash, otherwise use qemu.tag
qemu_vanilla_ref="refs/heads/${qemu_vanilla_branch}"
if ! (git ls-remote --heads "https://github.com/qemu/qemu.git" | grep -q "refs/heads/${qemu_vanilla_branch}"); then
qemu_vanilla_branch=$(get_from_kata_deps "assets.hypervisor.qemu.tag" "${kata_version}")
qemu_vanilla_ref="refs/tags/${qemu_vanilla_branch}^{}"
fi
qemu_vanilla_version=$(curl -s -L "https://raw.githubusercontent.com/qemu/qemu/${qemu_vanilla_branch}/VERSION") qemu_vanilla_version=$(curl -s -L "https://raw.githubusercontent.com/qemu/qemu/${qemu_vanilla_branch}/VERSION")
qemu_vanilla_hash=$(git ls-remote https://github.com/qemu/qemu.git | grep "refs/heads/${qemu_vanilla_branch}" | awk '{print $1}') qemu_vanilla_hash=$(git ls-remote https://github.com/qemu/qemu.git | grep "${qemu_vanilla_ref}" | awk '{print $1}')
kernel_version=$(get_from_kata_deps "assets.kernel.version" "${kata_version}") kernel_version=$(get_from_kata_deps "assets.kernel.version" "${kata_version}")
#Remove extra 'v' #Remove extra 'v'
@ -52,6 +64,7 @@ gen_version_file() {
# - is not a valid char for rpmbuild # - is not a valid char for rpmbuild
# see https://github.com/semver/semver/issues/145 # see https://github.com/semver/semver/issues/145
kata_version=$(get_kata_version "${branch}")
kata_version=${kata_version/-/\~} kata_version=${kata_version/-/\~}
cat > "$versions_txt" <<EOT cat > "$versions_txt" <<EOT
# This is a generated file from ${script_name} # This is a generated file from ${script_name}
@ -114,12 +127,14 @@ Options:
-h, --help Print this help. -h, --help Print this help.
--compare Only compare the kata version at branch <kata-branch> with the --compare Only compare the kata version at branch <kata-branch> with the
one in ${versions_txt} and leave the file untouched. one in ${versions_txt} and leave the file untouched.
--head Use <kata-branch>'s head to generate the versions file.
EOT EOT
exit "${exit_code}" exit "${exit_code}"
} }
main() { main() {
local compareOnly= local compareOnly=
local use_head=
case "${1:-}" in case "${1:-}" in
"-h"|"--help") "-h"|"--help")
@ -129,6 +144,10 @@ main() {
compareOnly=1 compareOnly=1
shift shift
;; ;;
--head)
use_head=1
shift
;;
-*) -*)
die "Invalid option: ${1:-}" "1" die "Invalid option: ${1:-}" "1"
shift shift
@ -147,7 +166,8 @@ main() {
echo "${kata_version} in ${versions_txt} ${compare_result} the version at branch ${branch}" echo "${kata_version} in ${versions_txt} ${compare_result} the version at branch ${branch}"
return return
fi fi
gen_version_file "${branch}"
gen_version_file "${branch}" "${use_head}"
} }
main $@ main $@

View File

@ -59,7 +59,8 @@ main() {
kata_version=${1:-} kata_version=${1:-}
[ -n "${kata_version}" ] || usage "1" [ -n "${kata_version}" ] || usage "1"
agent_sha=$(get_kata_hash_from_tag "agent" "${kata_version}") ref="refs/tags/${kata_version}^{}"
agent_sha=$(get_kata_hash "agent" "${ref}")
agent_sha=${agent_sha:0:${short_commit_length}} agent_sha=${agent_sha:0:${short_commit_length}}
image_tarball=$(find -name 'kata-containers-*.tar.gz' | grep "${kata_version}" | grep "${agent_sha}") || image_tarball=$(find -name 'kata-containers-*.tar.gz' | grep "${kata_version}" | grep "${agent_sha}") ||
"${script_dir}/../obs-packaging/kata-containers-image/build_image.sh" -v "${kata_version}" "${script_dir}/../obs-packaging/kata-containers-image/build_image.sh" -v "${kata_version}"

View File

@ -96,11 +96,6 @@ build_hub() {
popd >>/dev/null popd >>/dev/null
} }
get_kata_hash_from_tag() {
repo=$1
git ls-remote --tags "https://github.com/${project}/${repo}.git" | grep "refs/tags/${kata_version}^{}" | awk '{print $1}'
}
arch_to_golang() arch_to_golang()
{ {
local -r arch="$1" local -r arch="$1"
@ -113,3 +108,9 @@ arch_to_golang()
*) die "unsupported architecture: $arch";; *) die "unsupported architecture: $arch";;
esac esac
} }
get_kata_hash() {
repo=$1
ref=$2
git ls-remote --heads --tags "https://github.com/${project}/${repo}.git" | grep "${ref}" | awk '{print $1}'
}