From dd23beeb0525ad720b41d85b6976e8c4c8e58572 Mon Sep 17 00:00:00 2001 From: Hyounggyu Choi Date: Fri, 28 Jun 2024 12:33:23 +0200 Subject: [PATCH] CI: Eliminating dependency on clone_tests_repo() As part of archiving the tests repo, we are eliminating the dependency on `clone_tests_repo()`. The scripts using the function is as follows: - `ci/install_rust.sh`. - `ci/setup.sh` - `ci/lib.sh` This commit removes or replaces the files, and makes an adjustment accordingly. Signed-off-by: Hyounggyu Choi --- .../cargo-deny-generator.sh | 2 +- .github/workflows/docs-url-alive-check.yaml | 5 -- ci/docs-url-alive-check.sh | 2 +- ci/install_rust.sh | 16 ---- ci/lib.sh | 81 ------------------- ci/setup.sh | 16 ---- ci/static-checks.sh | 2 +- tests/common.bash | 47 +++++++++++ tests/functional/vfio-ap/run.sh | 11 --- .../kubernetes/confidential_kbs.sh | 2 +- tools/osbuilder/rootfs-builder/rootfs.sh | 2 +- tools/packaging/guest-image/build_se_image.sh | 2 +- 12 files changed, 53 insertions(+), 135 deletions(-) delete mode 100755 ci/install_rust.sh delete mode 100644 ci/lib.sh delete mode 100755 ci/setup.sh diff --git a/.github/cargo-deny-composite-action/cargo-deny-generator.sh b/.github/cargo-deny-composite-action/cargo-deny-generator.sh index 3d9eba242..e09c9bd70 100644 --- a/.github/cargo-deny-composite-action/cargo-deny-generator.sh +++ b/.github/cargo-deny-composite-action/cargo-deny-generator.sh @@ -8,7 +8,7 @@ script_dir=$(dirname "$(readlink -f "$0")") parent_dir=$(realpath "${script_dir}/../..") cidir="${parent_dir}/ci" -source "${cidir}/lib.sh" +source "${cidir}/../tests/common.bash" cargo_deny_file="${script_dir}/action.yaml" diff --git a/.github/workflows/docs-url-alive-check.yaml b/.github/workflows/docs-url-alive-check.yaml index 64f990560..7987188f4 100644 --- a/.github/workflows/docs-url-alive-check.yaml +++ b/.github/workflows/docs-url-alive-check.yaml @@ -26,11 +26,6 @@ jobs: with: fetch-depth: 0 path: ./src/github.com/${{ github.repository }} - - name: Setup - run: | - cd ${GOPATH}/src/github.com/${{ github.repository }} && ./ci/setup.sh - env: - GOPATH: ${{ runner.workspace }}/kata-containers # docs url alive check - name: Docs URL Alive Check run: | diff --git a/ci/docs-url-alive-check.sh b/ci/docs-url-alive-check.sh index 4b5371c34..235e62b39 100755 --- a/ci/docs-url-alive-check.sh +++ b/ci/docs-url-alive-check.sh @@ -7,6 +7,6 @@ set -e cidir=$(dirname "$0") -source "${cidir}/lib.sh" +source "${cidir}/../tests/common.bash" run_docs_url_alive_check diff --git a/ci/install_rust.sh b/ci/install_rust.sh deleted file mode 100755 index 6e4627491..000000000 --- a/ci/install_rust.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2019 Ant Financial -# -# SPDX-License-Identifier: Apache-2.0 -# - -set -e - -cidir=$(dirname "$0") -source "${cidir}/lib.sh" - -clone_tests_repo - -pushd ${tests_repo_dir} -.ci/install_rust.sh ${1:-} -popd diff --git a/ci/lib.sh b/ci/lib.sh deleted file mode 100644 index f5526bd1a..000000000 --- a/ci/lib.sh +++ /dev/null @@ -1,81 +0,0 @@ -# -# Copyright (c) 2018 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 - -set -o nounset - -GOPATH=${GOPATH:-${HOME}/go} -export kata_repo="github.com/kata-containers/kata-containers" -export kata_repo_dir="$GOPATH/src/$kata_repo" -export tests_repo="${tests_repo:-github.com/kata-containers/tests}" -export tests_repo_dir="$GOPATH/src/$tests_repo" -export branch="${target_branch:-main}" - -# Clones the tests repository and checkout to the branch pointed out by -# the global $branch variable. -# If the clone exists and `CI` is exported then it does nothing. Otherwise -# it will clone the repository or `git pull` the latest code. -# -clone_tests_repo() -{ - if [ -d "$tests_repo_dir" ]; then - [ -n "${CI:-}" ] && return - - pushd "${tests_repo_dir}" - git checkout "${branch}" - git pull - popd - else - git clone -q "https://${tests_repo}" "$tests_repo_dir" - pushd "${tests_repo_dir}" - git checkout "${branch}" - popd - fi -} - -run_static_checks() -{ - # Make sure we have the targeting branch - git remote set-branches --add origin "${branch}" - git fetch -a - bash "$kata_repo_dir/tests/static-checks.sh" "$@" -} - -run_docs_url_alive_check() -{ - # Make sure we have the targeting branch - git remote set-branches --add origin "${branch}" - git fetch -a - bash "$kata_repo_dir/tests/static-checks.sh" --docs --all "$kata_repo" -} - -run_get_pr_changed_file_details() -{ - # Make sure we have the targeting branch - git remote set-branches --add origin "${branch}" - git fetch -a - source "$kata_repo_dir/tests/common.bash" - get_pr_changed_file_details -} - -# Check if the 1st argument version is greater than and equal to 2nd one -# Version format: [0-9]+ separated by period (e.g. 2.4.6, 1.11.3 and etc.) -# -# Parameters: -# $1 - a version to be tested -# $2 - a target version -# -# Return: -# 0 if $1 is greater than and equal to $2 -# 1 otherwise -version_greater_than_equal() { - local current_version=$1 - local target_version=$2 - smaller_version=$(echo -e "$current_version\n$target_version" | sort -V | head -1) - if [ "${smaller_version}" = "${target_version}" ]; then - return 0 - else - return 1 - fi -} diff --git a/ci/setup.sh b/ci/setup.sh deleted file mode 100755 index a5f3fb7fd..000000000 --- a/ci/setup.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2018 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 - -set -e - -cidir=$(dirname "$0") -source "${cidir}/lib.sh" - -clone_tests_repo - -pushd "${tests_repo_dir}" -.ci/setup.sh -popd diff --git a/ci/static-checks.sh b/ci/static-checks.sh index 4297206d8..6d6281b51 100755 --- a/ci/static-checks.sh +++ b/ci/static-checks.sh @@ -7,6 +7,6 @@ set -e cidir=$(dirname "$0") -source "${cidir}/lib.sh" +source "${cidir}/../tests/common.bash" run_static_checks "${@:-github.com/kata-containers/kata-containers}" diff --git a/tests/common.bash b/tests/common.bash index 2570ffb37..99bf43656 100644 --- a/tests/common.bash +++ b/tests/common.bash @@ -28,6 +28,8 @@ KATA_HYPERVISOR="${KATA_HYPERVISOR:-qemu}" RUNTIME="${RUNTIME:-containerd-shim-kata-v2}" +export branch="${target_branch:-main}" + function die() { local msg="$*" @@ -792,3 +794,48 @@ function load_vhost_mods() { sudo modprobe vhost_net sudo modprobe vhost_vsock } + +function run_static_checks() +{ + # Make sure we have the targeting branch + git remote set-branches --add origin "${branch}" + git fetch -a + bash "$this_script_dir/static-checks.sh" "$@" +} + +function run_docs_url_alive_check() +{ + # Make sure we have the targeting branch + git remote set-branches --add origin "${branch}" + git fetch -a + bash "$this_script_dir/static-checks.sh" --docs --all "github.com/kata-containers/kata-containers" +} + +function run_get_pr_changed_file_details() +{ + # Make sure we have the targeting branch + git remote set-branches --add origin "${branch}" + git fetch -a + get_pr_changed_file_details +} + +# Check if the 1st argument version is greater than and equal to 2nd one +# Version format: [0-9]+ separated by period (e.g. 2.4.6, 1.11.3 and etc.) +# +# Parameters: +# $1 - a version to be tested +# $2 - a target version +# +# Return: +# 0 if $1 is greater than and equal to $2 +# 1 otherwise +function version_greater_than_equal() { + local current_version=$1 + local target_version=$2 + smaller_version=$(echo -e "$current_version\n$target_version" | sort -V | head -1) + if [ "${smaller_version}" = "${target_version}" ]; then + return 0 + else + return 1 + fi +} diff --git a/tests/functional/vfio-ap/run.sh b/tests/functional/vfio-ap/run.sh index 35106ba16..60128ce00 100755 --- a/tests/functional/vfio-ap/run.sh +++ b/tests/functional/vfio-ap/run.sh @@ -26,19 +26,8 @@ test_category="[kata][vfio-ap][containerd]" trap cleanup EXIT -# Check if the given function exists. -function_exists() { - [[ "$(type -t $1)" == "function" ]] -} - -if ! function_exists get_test_version; then - source "${script_path}/../../.ci/lib.sh" -fi - # Prevent the program from exiting on error trap - ERR -image_version=$(get_test_version "docker_images.registry_ibm.version") -registry_image=$(get_test_version "docker_images.registry_ibm.registry_url"):"${image_version}" setup_config_file() { local target_item=$1 diff --git a/tests/integration/kubernetes/confidential_kbs.sh b/tests/integration/kubernetes/confidential_kbs.sh index 2ca65b1db..ec5f0f8ee 100644 --- a/tests/integration/kubernetes/confidential_kbs.sh +++ b/tests/integration/kubernetes/confidential_kbs.sh @@ -11,7 +11,7 @@ kubernetes_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck disable=1091 source "${kubernetes_dir}/../../gha-run-k8s-common.sh" # shellcheck disable=1091 -source "${kubernetes_dir}/../../../ci/lib.sh" +source "${kubernetes_dir}/../../../tests/common.bash" KATA_HYPERVISOR="${KATA_HYPERVISOR:-qemu}" # Where the trustee (includes kbs) sources will be cloned diff --git a/tools/osbuilder/rootfs-builder/rootfs.sh b/tools/osbuilder/rootfs-builder/rootfs.sh index d7230c429..09eb95a04 100755 --- a/tools/osbuilder/rootfs-builder/rootfs.sh +++ b/tools/osbuilder/rootfs-builder/rootfs.sh @@ -651,7 +651,7 @@ EOF detect_rust_version || \ die "Could not detect the required rust version for AGENT_VERSION='${AGENT_VERSION:-main}'." fi - bash ${script_dir}/../../../ci/install_rust.sh ${RUST_VERSION} + bash ${script_dir}/../../../tests/install_rust.sh ${RUST_VERSION} fi test -r "${HOME}/.cargo/env" && source "${HOME}/.cargo/env" diff --git a/tools/packaging/guest-image/build_se_image.sh b/tools/packaging/guest-image/build_se_image.sh index 3f188ec6a..7169dc201 100755 --- a/tools/packaging/guest-image/build_se_image.sh +++ b/tools/packaging/guest-image/build_se_image.sh @@ -14,7 +14,7 @@ readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly packaging_root_dir="$(cd "${script_dir}/../" && pwd)" readonly kata_root_dir="$(cd "${packaging_root_dir}/../../" && pwd)" -source "$kata_root_dir/ci/lib.sh" +source "$kata_root_dir/tests/common.bash" source "${packaging_root_dir}/scripts/lib.sh" ARCH=${ARCH:-$(uname -m)}