Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/scripts/expand-ci-module-roots.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

group_roots="${GROUP_ROOTS:-}"
modules=()

add_module() {
local module="$1"
local existing

for existing in "${modules[@]}"; do
if [[ "${existing}" == "${module}" ]]; then
return
fi
done

modules+=("${module}")
}

IFS=',' read -ra roots <<< "${group_roots}"
for root in "${roots[@]}"; do
[[ -n "${root}" ]] || continue

if [[ ! -f "${root}/pom.xml" ]]; then
echo "Maven module root is missing: ${root}" >&2
exit 1
fi

if grep -q "<modules>" "${root}/pom.xml"; then
while IFS= read -r pom; do
add_module "$(dirname "${pom}")"
done < <(find "${root}" -name pom.xml | sort)
else
add_module "${root}"
fi
done

if [[ "${#modules[@]}" -eq 0 ]]; then
echo "No Maven modules were resolved from GROUP_ROOTS." >&2
exit 1
fi

IFS=,
printf '%s\n' "${modules[*]}"
116 changes: 116 additions & 0 deletions .github/scripts/resolve-ci-modules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

changed_files_json="${CHANGED_FILES_JSON:-[]}"
max_modules="${MAX_CI_MODULES:-8}"
has_code_changes=false
full_build_required=false
modules=()

if ! command -v jq >/dev/null 2>&1; then
echo "jq is required to resolve changed Maven modules." >&2
exit 1
fi

add_module() {
local module="$1"
local existing

for existing in "${modules[@]}"; do
if [[ "${existing}" == "${module}" ]]; then
return
fi
done

modules+=("${module}")
}

find_module() {
local path="$1"
local dir

if [[ -d "${path}" ]]; then
dir="${path}"
else
dir="$(dirname "${path}")"
fi

while [[ "${dir}" != "." && "${dir}" != "/" ]]; do
if [[ -f "${dir}/pom.xml" ]]; then
printf '%s\n' "${dir#./}"
return
fi
dir="$(dirname "${dir}")"
done
}

is_ignored_change() {
local file="$1"

case "${file}" in
.github/*|*.md|*.txt|resources/static/*|.asf.yaml|.gitignore|.licenserc.yaml|LICENSE|NOTICE|*/LICENSE|*/NOTICE)
return 0
;;
esac

return 1
}

while IFS= read -r file; do
[[ -n "${file}" ]] || continue

if is_ignored_change "${file}"; then
continue
fi

has_code_changes=true

case "${file}" in
pom.xml|mvnw|mvnw.cmd|.mvn/*|actions/*)
full_build_required=true
;;
esac

if [[ "$(basename "${file}")" == "pom.xml" && -f "${file}" ]] && grep -q "<modules>" "${file}"; then
full_build_required=true
fi

if [[ "${file}" == *.java || "${file}" == *.xml || "${file}" == *.yml || "${file}" == *.yaml || "${file}" == *.properties || "${file}" == *.sh ]]; then
module="$(find_module "${file}")"
if [[ -n "${module:-}" ]]; then
add_module "${module}"
fi
fi
done < <(printf '%s' "${changed_files_json}" | jq -r '.[]')

if [[ "${has_code_changes}" == "true" && ("${#modules[@]}" -eq 0 || "${#modules[@]}" -gt "${max_modules}") ]]; then
full_build_required=true
fi

modules_csv="$(IFS=,; printf '%s' "${modules[*]}")"

{
echo "has_code_changes=${has_code_changes}"
echo "modules=${modules_csv}"
echo "full_build_required=${full_build_required}"
} >> "${GITHUB_OUTPUT}"

echo "Has code changes: ${has_code_changes}"
echo "Resolved modules: ${modules_csv:-<none>}"
echo "Full build required: ${full_build_required}"
Loading
Loading