Greatly updates scripts/shell/job/gp/team-pipeline-local.sh script

This commit is contained in:
Matheus Albino Brunhara
2024-04-12 14:40:36 -03:00
parent 30e14285b2
commit 53c5807354

View File

@@ -7,6 +7,7 @@ show_help() {
echo "Options:"
echo " --help | -h (Optional) Display help information on how to use this script"
echo " --commit-hashes | -c (Required) Specify the commit hashes, separation by comma (,)"
echo " --commits-between | --cb (Required) Specify two commit hashes, separation by comma (,), so all commits between them will be considered"
echo " --repo-dir | -r (Required) Specify the git repository path that contains the commits"
echo " --deployments-path | -d (Required) Specify the Wildfly ports-XX/deployments path"
echo " --file-paths | -f (Optional) Specify file paths to consider in the update, separation by comma (,)"
@@ -17,6 +18,7 @@ show_help() {
}
commit_hashes_arg=''
commits_between_arg=''
repo_dir=''
deployments_path=''
file_paths_arg=''
@@ -29,6 +31,7 @@ while [ "$#" -gt 0 ]; do
--help|-h) show_help; exit ;;
--repo-dir|-r) repo_dir="$2"; shift 2;;
--commit-hashes|-c) commit_hashes_arg="$2"; shift 2;;
--commits-between|-cb) commits_between_arg="$2"; shift 2;;
--deployments-path|-d) deployments_path="$2"; shift 2;;
--file-paths|-f) file_paths_arg="$2"; shift 2;;
--no-build|-b) build_maven=false; shift 2;;
@@ -58,6 +61,12 @@ commit_exists() {
fi
}
get_target_paths_from_commit_hash() {
commit_hash=$1
echo `git show --oneline --name-only $c | tail -n +2`
}
find_pom_xml_file_recursively() {
path=$1
@@ -86,8 +95,7 @@ arr_uniq() {
build_mvn() {
echo "[INFO] Realizando build Maven no diretório \"`pwd`\"..."
# mvn --quiet clean install --file ./pom.xml --settings ~/.m2/settings.xml
mvn clean install --file ./pom.xml --settings ~/.m2/settings.xml
mvn --quiet clean install --file ./pom.xml --settings ~/.m2/settings.xml
if [ $? -ne 0 ]; then
echo "[INFO] A build Maven resultou em erros. O script irá encerrar agora."
@@ -128,6 +136,35 @@ get_substring_after_string() {
echo ${str#*$subs}
}
sort_pom_paths_for_compilation_order() {
local unsorted_pom_paths=("$@")
local -A compilation_order_list=(
['main']=''
['commons']=''
['security']=''
['tools']=''
['geo']=''
['meta']=''
['framework']=''
['faces']=''
['application']=''
['plugins']=''
['cdk']=''
['auditing']=''
)
local sorted_pom_paths=()
for dir in "${!compilation_order_list[@]}"; do
for path in "${unsorted_pom_paths[@]}"; do
if [[ $path == "${dir}/"* ]]; then
sorted_pom_paths+=("$path")
fi
done
done
printf "%s\n" "${sorted_pom_paths[@]}"
}
if [ -z "$file_paths_arg" ] \
&& [ -z "$commit_hashes_arg" ] \
&& ! $use_git_status; then
@@ -138,9 +175,11 @@ if [ -z "$file_paths_arg" ] \
exit 1
fi
if [ ! -z "$commit_hashes_arg" ] && [ -z "$repo_dir" ]; then
echo "Error: If you specify the Commit hashes (--commit-hashes or -c), the repository directory (--repo-dir or -r) is also required."
exit 1
if [ ! -z "$repo_dir" ]; then
if [ -z "$commit_hashes_arg" ] && [ -z "$commits_between_arg" ]; then
echo "Error: If you specify the Commit hashes (--commit-hashes or -c) and/or Commits between (--commits-between or -cb), the repository directory (--repo-dir or -r) is also required."
exit 1
fi
fi
if [ -z "$deployments_path" ]; then
@@ -169,7 +208,7 @@ if [ ! -z "$commit_hashes_arg" ]; then
continue
fi
target_paths+=(`git show --oneline --name-only $c | tail -n +2`)
target_paths+=(`get_target_paths_from_commit_hash "$c"`)
done
fi
@@ -177,9 +216,24 @@ if $use_git_status; then
target_paths+=(`git ls-files --modified`)
fi
cd $cur
if [ ! -z "$commits_between_arg" ]; then
commit_hashes=`git rev-list --ancestry-path "${commits_between_arg/","/".."}"`
target_paths_arg=()
dot_java_files=()
for c in ${commit_hashes[@]}; do
if ! commit_exists $c; then
continue
fi
target_paths_arg+=(`get_target_paths_from_commit_hash "$c"`)
done
for i in ${target_paths_arg[@]}; do
target_paths+=($i)
done
fi
cd $cur
if [ ! -z "$file_paths_arg" ]; then
file_paths=`convert_csv_to_array "$file_paths_arg"`
@@ -193,24 +247,31 @@ fi
cd $repo_dir
for f in ${target_paths[@]}; do
if [[ $f == *.java ]]; then
dot_java_files+=("$f")
fi
done
target_paths_uniq=$(for i in "${target_paths[@]}"; do echo $i; done | sort -u)
dot_java_files=()
pom_paths=()
for i in ${target_paths_uniq[@]}; do
if [[ $i == *.java ]]; then
dot_java_files+=("$i")
fi
res=`find_pom_xml_file_recursively $i`;
pom_paths+=("$res")
done
pom_paths_uniq=$(for i in "${pom_paths[@]}"; do echo $i; done | sort -u)
for p in ${pom_paths_uniq[@]}; do
sorted_pom_paths_uniq=($(sort_pom_paths_for_compilation_order "${pom_paths_uniq[@]}"))
echo "[INFO] Pom order:"
for p in ${sorted_pom_paths_uniq[@]}; do
echo "$p"
done
for p in ${sorted_pom_paths_uniq[@]}; do
pom_dir=`dirname $p`
cd $repo_dir/$pom_dir
@@ -220,7 +281,7 @@ done
non_root_deployments_files_to_explode=()
non_root_deployments_files_to_explode_full_path=()
for p in ${pom_paths_uniq[@]}; do
for p in ${sorted_pom_paths_uniq[@]}; do
pom_dir=$repo_dir/`dirname $p`
if [ ! -d "$pom_dir/target" ]; then
@@ -255,11 +316,14 @@ fi
src_path_const='src/main/java/'
unsuccessful_copies=()
for f in ${dot_java_files[@]}; do
printf "\n"
f_dirname=`dirname $f`
class_filename=`basename ${f%".java"}.class`
f_basename=`basename $f`
class_filename=`echo ${f_basename%".java"}.class`
path_in_deployments=`get_substring_after_string "$f_dirname" "$src_path_const"`
class_file_paths_in_deployments=`find $deployments_path -type f -wholename "**/$path_in_deployments/$class_filename"`
@@ -288,6 +352,13 @@ for f in ${dot_java_files[@]}; do
cp_dest=`dirname $p`
printf "\n"
if [ -z "$class_file_path_in_target" ]; then
unsuccessful_copies+=($f_basename)
echo "[WARN] O arquivo \"$f_basename\" não foi encontrado em alguma pasta target do repositório. Pulando cópia..."
continue
fi
echo "[INFO] Copiando arquivo:"
echo " De: $class_file_path_in_target"
echo " Para: $cp_dest"
@@ -303,6 +374,17 @@ for f in ${dot_java_files[@]}; do
done
done
if [ ${#unsuccessful_copies[@]} -ne 0 ]; then
unsuccessful_copies_uniq=$(for i in "${unsuccessful_copies[@]}"; do echo $i; done | sort -u)
printf "\n"
echo "[WARN] Houveram arquivos que não foram encontrados em alguma pasta target do repositório."
for i in ${unsuccessful_copies_uniq[@]}; do
echo " Arquivo mal-sucedido: $i"
done
fi
if $should_start_server; then
$cur/debugports-01.sh
fi