diff --git a/.buildkite/scripts/common.sh b/.buildkite/scripts/common.sh index 7685ba228ec..2ff75355597 100755 --- a/.buildkite/scripts/common.sh +++ b/.buildkite/scripts/common.sh @@ -728,7 +728,7 @@ is_pr_affected() { return 1 fi if ! is_supported_capability ; then - echo "[${package}] PR is not affected: capabilities not mached with the project (${SERVERLESS_PROJECT})" + echo "[${package}] PR is not affected: capabilities not matched with the project (${SERVERLESS_PROJECT})" return 1 fi if [[ "${package}" == "fleet_server" ]]; then @@ -763,10 +763,19 @@ is_pr_affected() { # Example: # https://buildkite.com/elastic/integrations/builds/25606 # https://github.com/elastic/integrations/pull/13810 - if git diff --name-only "${commit_merge}" "${to}" | grep -E -v '^(packages/|\.github/(CODEOWNERS|ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE|workflows/)|CODE_OF_CONDUCT\.md|README\.md|docs/|catalog-info\.yaml|\.buildkite/(pull-requests\.json|pipeline\.schedule-daily\.yml|pipeline\.schedule-weekly\.yml|pipeline\.backport\.yml))' > /dev/null; then + if git diff --name-only "${commit_merge}" "${to}" | grep -E -v '^(packages/|\.github/(CODEOWNERS|ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE|workflows/)|CODE_OF_CONDUCT\.md|README\.md|docs/|catalog-info\.yaml|\.buildkite/(pull-requests\.json|pipeline\.schedule-daily\.yml|pipeline\.schedule-weekly\.yml|pipeline\.backport\.yml|scripts/packages.+\.sh))' > /dev/null; then echo "[${package}] PR is affected: found non-package files" return 0 fi + echoerr "[${package}] git-diff: check custom package checker script file (${commit_merge}..${to})" + # Avoid using "-q" in grep in this pipe, it could cause that some files updated are not detected due to SIGPIPE errors when "set -o pipefail" + # Example: + # https://buildkite.com/elastic/integrations/builds/25606 + # https://github.com/elastic/integrations/pull/13810 + if git diff --name-only "${commit_merge}" "${to}" | grep -E "^\.buildkite/scripts/packages/${package}.sh" > /dev/null; then + echo "[${package}] PR is affected: found package checker script changes" + return 0 + fi echoerr "[${package}] git-diff: check package files (${commit_merge}..${to})" # Avoid using "-q" in grep in this pipe, it could cause that some files updated are not detected due to SIGPIPE errors when "set -o pipefail" # Example: diff --git a/.buildkite/scripts/packages/security_detection_engine.sh b/.buildkite/scripts/packages/security_detection_engine.sh new file mode 100755 index 00000000000..3722a38e126 --- /dev/null +++ b/.buildkite/scripts/packages/security_detection_engine.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +set -euo pipefail + +if [[ "${BUILDKITE_PULL_REQUEST}" == "false" ]]; then + exit 0 +fi + +# Fetch active Kibana versions +ACTIVE_KIBANA_VERSIONS=$(curl -sL https://raw.githubusercontent.com/elastic/kibana/main/versions.json | yq '.versions[].version' | xargs) +echo "Active Kibana versions: $ACTIVE_KIBANA_VERSIONS" + +# Extract version spec from the manifest +KIBANA_REQ=$(yq .conditions.kibana.version ./security_detection_engine/manifest.yml) +echo "Kibana requirement from the security_detection_engine manifest: $KIBANA_REQ" + +# Dump a trivial Go program to filter by semver constrains +TEMP_DIR=$(mktemp -d) +SEMVER_FILTER_PATH="$TEMP_DIR/semver.go" + +cat <<'GO' > "$SEMVER_FILTER_PATH" +package main + +import ( + "strings" + "fmt" + "os" + "github.com/Masterminds/semver/v3" +) + +func main() { + c, err := semver.NewConstraint(os.Args[1]) + if err != nil { + panic(err) + } + + for _, s := range strings.Split(os.Args[2], " ") { + if v, _ := semver.NewVersion(s); c.Check(v) { + fmt.Println(s + "-SNAPSHOT") + } + } +} +GO + +# Capture the "returned" array in STACK_VERSIONS +read -r -a STACK_VERSIONS <<< "$(go run "${SEMVER_FILTER_PATH}" "${KIBANA_REQ}" "${ACTIVE_KIBANA_VERSIONS}" | xargs)" + +if [[ ! -n "${STACK_VERSIONS+x}" ]]; then + echo "There are no active versions satisfying the constraint ${KIBANA_REQ}." + exit 0 +fi + +# Trigger OOM testing pipeline for each stack version +for STACK_VERSION in "${STACK_VERSIONS[@]}" +do + echo "--- [security_detection_engine] Trigger OOM testing pipeline against $STACK_VERSION ECH" + + cat < /dev/null exit_code=0 if ! process_package "${package}" ; then @@ -32,6 +34,11 @@ if ! process_package "${package}" ; then # is not hidden by the previous collapsed group. echo "--- [${package}] failed" exit_code=1 +elif [ -x "$custom_package_checker_script_path" ]; then + echo "--- [${package}] Run individual package checker" + "$custom_package_checker_script_path" +else + echo "--- [${package}] Individual package checker $custom_package_checker_script_path is not found, continue..." fi popd > /dev/null