From ebec6903b803e54032f60ba02609f9fe5b5059e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Fri, 18 Mar 2022 12:50:07 +0100 Subject: [PATCH] static-build,clh: Add the ability to build from a PR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Right now it doesn't do much for us, as we're always building from a specific version. However, this opens the possibility for us to add a CI, similar to the one we have for CRI-O, for testing against each cloud-hypervisor PR, on the cloud-hypervisor branch. Fixes: #3908 Signed-off-by: Fabiano FidĂȘncio --- .../cloud-hypervisor/build-static-clh.sh | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh b/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh index cf2aaec381..ff26822cc9 100755 --- a/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh +++ b/tools/packaging/static-build/cloud-hypervisor/build-static-clh.sh @@ -22,6 +22,8 @@ source "${script_dir}/../../scripts/lib.sh" cloud_hypervisor_repo="${cloud_hypervisor_repo:-}" cloud_hypervisor_version="${cloud_hypervisor_version:-}" +cloud_hypervisor_pr="${cloud_hypervisor_pr:-}" +cloud_hypervisor_pull_ref_branch="${cloud_hypervisor_pull_ref_branch:-main}" if [ -z "$cloud_hypervisor_repo" ]; then info "Get cloud_hypervisor information from runtime versions.yaml" @@ -31,8 +33,13 @@ if [ -z "$cloud_hypervisor_repo" ]; then fi [ -n "$cloud_hypervisor_repo" ] || die "failed to get cloud_hypervisor repo" -[ -n "$cloud_hypervisor_version" ] || cloud_hypervisor_version=$(get_from_kata_deps "assets.hypervisor.cloud_hypervisor.version" "${kata_version}") -[ -n "$cloud_hypervisor_version" ] || die "failed to get cloud_hypervisor version" +if [ -n "$cloud_hypervisor_pr" ]; then + force_build_from_source=true + cloud_hypervisor_version="PR $cloud_hypervisor_pr" +else + [ -n "$cloud_hypervisor_version" ] || cloud_hypervisor_version=$(get_from_kata_deps "assets.hypervisor.cloud_hypervisor.version" "${kata_version}") + [ -n "$cloud_hypervisor_version" ] || die "failed to get cloud_hypervisor version" +fi pull_clh_released_binary() { info "Download cloud-hypervisor version: ${cloud_hypervisor_version}" @@ -50,8 +57,19 @@ build_clh_from_source() { repo_dir="${repo_dir//.git}" [ -d "${repo_dir}" ] || git clone "${cloud_hypervisor_repo}" pushd "${repo_dir}" - git fetch || true - git checkout "${cloud_hypervisor_version}" + + if [ -n "${cloud_hypervisor_pr}" ]; then + local pr_branch="PR_${cloud_hypervisor_pr}" + git fetch origin "pull/${cloud_hypervisor_pr}/head:${pr_branch}" || return 1 + git checkout "${pr_branch}" + git rebase "origin/${cloud_hypervisor_pull_ref_branch}" + + git log --oneline main~1..HEAD + else + git fetch || true + git checkout "${cloud_hypervisor_version}" + fi + if [ -n "${features}" ]; then info "Build cloud-hypervisor enabling the following features: ${features}" ./scripts/dev_cli.sh build --release --libc musl --features "${features}"