Skip to content

Commit 9cc525e

Browse files
authored
[CI] Update CI scripts (#13410)
Update CI scripts. Some refactors to place all the code related to filtering out packages in the same function. Avoid creating kind clusters in CI build testing with Serverless. Remove some output in the trigger step.
1 parent ebb60b4 commit 9cc525e

File tree

4 files changed

+68
-66
lines changed

4 files changed

+68
-66
lines changed

.buildkite/scripts/common.sh

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,9 @@ prepare_serverless_stack() {
570570
}
571571

572572
is_spec_3_0_0() {
573-
local pkg_spec
573+
local pkg_spec=""
574574
pkg_spec=$(cat manifest.yml | yq '.format_version')
575-
local major_version
575+
local major_version=""
576576
major_version=$(echo "$pkg_spec" | cut -d '.' -f 1)
577577

578578
if [ "${major_version}" -ge 3 ]; then
@@ -670,10 +670,8 @@ get_to_changeset() {
670670

671671
is_pr_affected() {
672672
local package="${1}"
673-
local from=${2:-""}
674-
local to=${3:-""}
675-
676-
echoerr "[${package}] Original commits: from '${from}' - to: '${to}'"
673+
local from="${2}"
674+
local to="${3}"
677675

678676
if ! is_supported_stack ; then
679677
echo "[${package}] PR is not affected: unsupported stack (${STACK_VERSION})"
@@ -689,30 +687,31 @@ is_pr_affected() {
689687
echo "[${package}] PR is not affected: capabilities not mached with the project (${SERVERLESS_PROJECT})"
690688
return 1
691689
fi
690+
if [[ "${package}" == "fleet_server" ]]; then
691+
echoerr "fleet_server not supported. Skipped"
692+
echo "[${package}] not supported"
693+
return 1
694+
fi
695+
if ! is_spec_3_0_0 ; then
696+
echoerr "Not v3 spec version. Skipped"
697+
echo "[${package}] spec <3.0.0"
698+
return 1
699+
fi
692700
fi
693701

694702
if [[ "${FORCE_CHECK_ALL}" == "true" ]];then
695703
echo "[${package}] PR is affected: \"force_check_all\" parameter enabled"
696704
return 0
697705
fi
698706

699-
if [[ "${from}" == "" || "${to}" == "" ]]; then
700-
echo "[${package}] Calculating commits: from '${from}' - to: '${to}'"
701-
# setting range of changesets to check differences
702-
from="$(get_from_changeset)"
703-
to="$(get_to_changeset)"
704-
fi
705-
706-
echo "[${package}]: commits: from: '${from}' - to: '${to}'"
707-
708-
echo "[${package}] git-diff: check non-package files"
709707
commit_merge=$(git merge-base "${from}" "${to}")
710-
if git diff --name-only "${commit_merge}" "${to}" | grep -E -v '^(packages/|\.github/(CODEOWNERS|ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE)|README\.md|docs/)' ; then
708+
echoerr "[${package}] git-diff: check non-package files (${commit_merge}..${to})"
709+
if git diff --name-only "${commit_merge}" "${to}" | grep -q -E -v '^(packages/|\.github/(CODEOWNERS|ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE)|README\.md|docs/)' ; then
711710
echo "[${package}] PR is affected: found non-package files"
712711
return 0
713712
fi
714-
echo "[${package}] git-diff: check package files"
715-
if git diff --name-only "${commit_merge}" "${to}" | grep -E "^packages/${package}/" ; then
713+
echoerr "[${package}] git-diff: check package files (${commit_merge}..${to})"
714+
if git diff --name-only "${commit_merge}" "${to}" | grep -q -E "^packages/${package}/" ; then
716715
echo "[${package}] PR is affected: found package files"
717716
return 0
718717
fi
@@ -728,7 +727,11 @@ is_pr() {
728727
}
729728

730729
kubernetes_service_deployer_used() {
731-
find . -type d | grep -E '_dev/deploy/k8s$'
730+
# Not able to use -q in parameter
731+
# as set -o pipefail is defined, when adding "-q" parameter, grep finishes with its first match
732+
# but find still is writing to the pipe causing the SIGPIPE
733+
# https://tldp.org/LDP/lpg/node20.html
734+
find . -type d | grep -E "_dev/deploy/k8s$" > /dev/null
732735
}
733736

734737
teardown_serverless_test_package() {
@@ -954,54 +957,35 @@ upload_safe_logs_from_package() {
954957

955958
# Helper to run all tests and checks for a package
956959
process_package() {
957-
local package="$1"
958-
local from=${2:-""}
959-
local to=${3:-""}
960+
local package="${1}"
961+
local failed_packages_file="${2:-""}"
960962
local exit_code=0
961963

962964
echo "--- Package ${package}: check"
963965
pushd "${package}" > /dev/null
964966

965967
clean_safe_logs
966968

967-
if is_serverless ; then
968-
if [[ "${package}" == "fleet_server" ]]; then
969-
echo "fleet_server not supported. Skipped"
970-
echo "- [${package}] not supported" >> "${SKIPPED_PACKAGES_FILE_PATH}"
971-
popd > /dev/null
972-
return
973-
fi
974-
if ! is_spec_3_0_0 ; then
975-
echo "Not v3 spec version. Skipped"
976-
echo "- [${package}] spec <3.0.0" >> "${SKIPPED_PACKAGES_FILE_PATH}"
977-
popd > /dev/null
978-
return
979-
fi
980-
fi
981-
982-
if ! reason=$(is_pr_affected "${package}" "${from}" "${to}") ; then
983-
echo "${reason}"
984-
echo "- ${reason}" >> "${SKIPPED_PACKAGES_FILE_PATH}"
985-
popd > /dev/null
986-
return
987-
fi
988-
989-
echo "${reason}"
990-
991969
use_kind=0
992-
if kubernetes_service_deployer_used ; then
993-
echo "Kubernetes service deployer is used. Creating Kind cluster"
994-
use_kind=1
995-
if ! create_kind_cluster ; then
996-
popd > /dev/null
997-
return 1
970+
if ! is_serverless ; then
971+
# TODO: in serverless system tests are not triggered,
972+
# there is no need to create the kind cluster in these CI builds.
973+
if kubernetes_service_deployer_used ; then
974+
echo "Kubernetes service deployer is used. Creating Kind cluster"
975+
use_kind=1
976+
if ! create_kind_cluster ; then
977+
popd > /dev/null
978+
return 1
979+
fi
998980
fi
999981
fi
1000982

1001983
if ! run_tests_package "${package}" ; then
1002984
exit_code=1
1003985
echo "[${package}] run_tests_package failed"
1004-
echo "- ${package}" >> "${FAILED_PACKAGES_FILE_PATH}"
986+
if [[ "${failed_packages_file}" != "" ]]; then
987+
echo "- ${package}" >> "${failed_packages_file}"
988+
fi
1005989
fi
1006990

1007991
if ! is_serverless ; then

.buildkite/scripts/test_integrations_with_serverless.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,32 @@ echo "Done."
6161

6262
# setting range of changesets to check differences
6363
from="$(get_from_changeset)"
64+
if [[ "${from}" == "" ]]; then
65+
echo "Missing \"from\" changset".
66+
exit 1
67+
fi
6468
to="$(get_to_changeset)"
69+
if [[ "${to}" == "" ]]; then
70+
echo "Missing \"to\" changset".
71+
exit 1
72+
fi
73+
echo "Checking with commits: from: '${from}' to: '${to}'"
6574

6675
any_package_failing=0
6776

6877
pushd packages > /dev/null
6978
for package in $(list_all_directories); do
70-
if ! process_package "${package}" "${from}" "${to}"; then
79+
pushd "${package}" > /dev/null
80+
if ! reason=$(is_pr_affected "${package}" "${from}" "${to}") ; then
81+
echo "${reason}"
82+
echo "- ${reason}" >> "${SKIPPED_PACKAGES_FILE_PATH}"
83+
popd > /dev/null
84+
continue
85+
fi
86+
echo "${reason}"
87+
popd > /dev/null
88+
89+
if ! process_package "${package}" "${FAILED_PACKAGES_FILE_PATH}" ; then
7190
any_package_failing=1
7291
fi
7392
done

.buildkite/scripts/test_one_package.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,8 @@ source .buildkite/scripts/common.sh
44

55
set -euo pipefail
66

7-
8-
# used in common.sh
9-
SKIPPED_PACKAGES_FILE_PATH="${WORKSPACE}/skipped_packages.txt"
10-
FAILED_PACKAGES_FILE_PATH="${WORKSPACE}/failed_packages.txt"
11-
127
# package name
138
package="$1"
14-
# changesets
15-
from=${2:-""}
16-
to=${3:-""}
17-
189

1910
if [ ! -d packages ]; then
2011
echo "Missing packages folder"
@@ -36,7 +27,7 @@ use_elastic_package
3627

3728
pushd packages > /dev/null
3829
exit_code=0
39-
if ! process_package "${package}" "${from}" "${to}"; then
30+
if ! process_package "${package}" ; then
4031
echo "[${package}] failed"
4132
exit_code=1
4233
fi

.buildkite/scripts/trigger_integrations_in_parallel.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ EOF
2525

2626
# setting range of changesets to check differences
2727
from="$(get_from_changeset)"
28+
if [[ "${from}" == "" ]]; then
29+
echo "Missing \"from\" changset".
30+
exit 1
31+
fi
2832
to="$(get_to_changeset)"
33+
if [[ "${to}" == "" ]]; then
34+
echo "Missing \"to\" changset".
35+
exit 1
36+
fi
2937

30-
echo "[DEBUG] Checking with commits: from: '${from}' to: '${to}'"
38+
echo "Checking with commits: from: '${from}' to: '${to}'"
3139

3240
# This variable does not exist in builds triggered automatically
3341
GITHUB_PR_TRIGGER_COMMENT="${GITHUB_PR_TRIGGER_COMMENT:-""}"

0 commit comments

Comments
 (0)