diff --git a/.buildkite/scripts/changesets.sh b/.buildkite/scripts/changesets.sh index 5c6fd6c7b0d8..6134607f82bc 100644 --- a/.buildkite/scripts/changesets.sh +++ b/.buildkite/scripts/changesets.sh @@ -1,77 +1,62 @@ #!/usr/bin/env bash -# This script contains helper functions related to what should be run depending on Git changes +set -euo pipefail OSS_MODULE_PATTERN="^[a-z0-9]+beat\\/module\\/([^\\/]+)\\/.*" XPACK_MODULE_PATTERN="^x-pack\\/[a-z0-9]+beat\\/module\\/([^\\/]+)\\/.*" -are_paths_changed() { - local patterns=("${@}") - local changelist=() - for pattern in "${patterns[@]}"; do - changed_files=($(git diff --name-only HEAD@{1} HEAD | grep -E "$pattern")) - if [ "${#changed_files[@]}" -gt 0 ]; then - changelist+=("${changed_files[@]}") - fi - done +definePattern() { + pattern="${OSS_MODULE_PATTERN}" - if [ "${#changelist[@]}" -gt 0 ]; then - echo "Files changed:" - echo "${changelist[*]}" - return 0 - else - echo "No files changed within specified changeset:" - echo "${patterns[*]}" - return 1 + if [[ "$beatPath" == *"x-pack/"* ]]; then + pattern="${XPACK_MODULE_PATTERN}" fi } -are_changed_only_paths() { - local patterns=("${@}") - local changed_files=($(git diff --name-only HEAD@{1} HEAD)) - local matched_files=() - for pattern in "${patterns[@]}"; do - local matched=($(grep -E "${pattern}" <<< "${changed_files[@]}")) - if [ "${#matched[@]}" -gt 0 ]; then - matched_files+=("${matched[@]}") - fi - done - if [ "${#matched_files[@]}" -eq "${#changed_files[@]}" ] || [ "${#changed_files[@]}" -eq 0 ]; then - return 0 - fi - return 1 +defineExclusions() { + exclude="^$beatPath\/module\/(.*(?