Skip to content

Commit

Permalink
Improved list for SMUD-GitOps repository
Browse files Browse the repository at this point in the history
  • Loading branch information
aho-dips committed Jan 31, 2024
1 parent 80665c1 commit 35fef80
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 65 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
## Version 1.0.10
- Improved list for SMUD-GitOps repository

## Version 1.0.9
- Improved upgrade. Already cherry-picket commits will be skipped.

## Version 1.0.8
- Implemented gitops-model upgrade

## Version 1.0.7
- Implemented gitops-model upgrade

## Version 1.0.6
- Implementet gitops-model list
- Implemented gitops-model list

## Version 1.0.5
- Changed list function from commit-focus to version-focus
Expand Down
162 changes: 126 additions & 36 deletions smud-cli/functions-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,15 @@ product_infos__print()
# echo "HIT ${product_stages[@]}"
for product_stage in "${product_stages[@]}"
do
if [ "$product_stage" = "development" ]; then has_development="true"; fi
if [ "$product_stage" = "internal-test" ]; then has_internal_test="true"; fi
if [ "$product_stage" = "external-test" ]; then has_external_test="true"; fi
if [ "$product_stage" = "production" ]; then has_production="true"; fi

if [ "$prev" = "external-test" ] && [ "$product_stage" = "internal-test" ]; then
ordered_product_stages[$iPrev]="$product_stage"
ordered_product_stages[$i]="$prev"
echo "set [$iPrev]=$product_stage and [$i]=$prev -- ${ordered_product_stages[@]}"
# echo "set [$iPrev]=$product_stage and [$i]=$prev -- ${ordered_product_stages[@]}"
else
ordered_product_stages[$i]=$product_stage
fi
Expand All @@ -358,6 +363,16 @@ product_infos__print()
for product_stage in "${ordered_product_stages[@]}"
do
# echo "hit:$product_stage"
if [ "$git_range" ]; then
show_latest_version_in_list="true"
show_tags_in_list="true"
fi
if [ "$is_smud_dev_repo" ]; then
show_latest_version_in_list=""
show_tags_in_list=""
fi
latest_version_header_text="LATEST VER."

printed_stage_label=""
printed_product_header=""
iMajor=0
Expand All @@ -374,7 +389,7 @@ product_infos__print()
product_latest_version=""
product_latest_commit=""
current_version=""
latest_version=""
local latest_version=""
commit=""
files=""
product_info=${product_infos[${stage_product_name}]}
Expand All @@ -384,16 +399,43 @@ product_infos__print()
fi
if [ "$product_info" ]; then
# echo "Found : $stage_product_name"
product_info__get_latest_version product_info latest_version

if [ ! "$latest_version" ] && [ "$git_range" ]; then
get_latest_version latest_version
fi
product_info__get_current_version product_info current_version
if [ ! "$current_version" ]; then
current_version="$(get_current_version)"
fi

if [ "$show_latest_version_in_list" = "true" ]; then
product_info__get_latest_version product_info latest_version

if [ ! "$latest_version" ] && [ "$git_range" ]; then
get_latest_version latest_version
fi
else
latest_version=""
if [ "$product_stage" = "development" ] && [ "$has_internal_test" ]; then
latest_version="$(get_next_stage_version "$product_name/internal-test")"
latest_version_header_text="INT-TEST VER."
show_latest_version_in_list="show"
show_tags_in_list="show"
fi
if ([ "$product_stage" = "internal-test" ] || [ "$product_stage" = "production" ]) && [ "$has_external_test" ]; then
latest_version="$(get_next_stage_version "$product_name/external-test")"
show_latest_version_in_list="show"
show_tags_in_list="show"
latest_version_header_text="EXT-TEST VER."
if [ "$product_stage" = "production" ]; then
show_tags_in_list="reverse"
fi

fi
if [ "$product_stage" = "external-test" ] && [ "$has_production" ]; then
latest_version="$(get_next_stage_version "$product_name/production")"
show_latest_version_in_list="show"
show_tags_in_list="show"
latest_version_header_text="PROD VER."
fi
fi

if [ "$show_files" ]; then
product_info__get_latest_files product_info files
fi
Expand All @@ -405,30 +447,44 @@ product_infos__print()

# echo "commit: [$commit]"
# echo "{ stage: '$product_stage', product_name: '$product_name', latest_version: '$latest_version', commit: '$commit', product_info: '${product_infos[${stage_product_name}]}' }"

tags="$(get_tags "'$current_version'" "'$latest_version'")"
if [ "$show_tags_in_list" ]; then
if [ "$show_tags_in_list" = "reverse" ]; then
tags="$(get_tags "'$latest_version'" "'$current_version'")"
else
tags="$(get_tags "'$current_version'" "'$latest_version'")"
fi

if [ "$major" ] && [ ! "$tags" = "MAJOR" ];then
continue
fi
if [ "$major" ] && [ ! "$tags" = "MAJOR" ];then
continue
fi

if [ "$minor" ] && [ ! "$tags" = "MINOR" ];then
continue
fi
if [ "$minor" ] && [ ! "$tags" = "MINOR" ];then
continue
fi

if [ "$patch" ] && [ ! "$tags" = "patch" ];then
continue
fi
if [ "$patch" ] && [ ! "$tags" = "patch" ];then
continue
fi

if [ "$same" ] && [ ! "$tags" = "" ] && [ ! "$current_version" = "$latest_version" ]; then
continue
if [ "$changed" ] && [ ! "$tags" ];then
continue
fi

if [ "$same" ] && [ ! "$tags" = "" ] && [ ! "$current_version" = "$latest_version" ]; then
continue
fi
if [ "$tags" = "MAJOR" ];then iMajor=$((iMajor+1)); fi
if [ "$tags" = "MINOR" ];then iMinor=$((iMinor+1)); fi
if [ "$tags" = "patch" ];then iPatch=$((iPatch+1)); fi
if [ "$tags" = "" ] && [ "$current_version" = "$latest_version" ];then iSame=$((iSame+1)); fi
if [ ! "$current_version" ];then iNew=$((iNew+1)); fi
else
if [ "$changed" ];then
continue
fi
fi
iProducts=$((iProducts+1))
if [ "$tags" = "MAJOR" ];then iMajor=$((iMajor+1)); fi
if [ "$tags" = "MINOR" ];then iMinor=$((iMinor+1)); fi
if [ "$tags" = "patch" ];then iPatch=$((iPatch+1)); fi
if [ "$tags" = "" ] && [ "$current_version" = "$latest_version" ];then iSame=$((iSame+1)); fi
if [ ! "$current_version" ];then iNew=$((iNew+1)); fi

fi
if [ ! "$printed_stage_label" ]; then
printf "\n$product_stage:\n"
Expand All @@ -442,11 +498,16 @@ product_infos__print()
fi

latest_version_header=""
if [ "$git_range" ]; then
latest_version_header="`printf %-${n_latest_ver_len}s "LATEST VER."`"
if [ "$show_latest_version_in_list" ]; then
latest_version_header="`printf %-${n_latest_ver_len}s "$latest_version_header_text"`"
fi

printf "`printf %-${n_products_len}s "PRODUCTS"` `printf %-${n_tags_len}s "TAGS"` `printf %-${n_current_ver_len}s "CURRENT VER."` $latest_version_header $files_header\n"
tags_header=""
if [ "$show_tags_in_list" ]; then
tags_header="`printf %-${n_tags_len}s "TAGS"`"
fi

printf "`printf %-${n_products_len}s "PRODUCTS"` $tags_header `printf %-${n_current_ver_len}s "CURRENT VER."` $latest_version_header $files_header\n"
printed_product_header="true"
fi

Expand All @@ -459,13 +520,18 @@ product_infos__print()

print_product_name=`printf %-${n_products_len}s "$product_name"`
print_current_version=`printf %-${n_current_ver_len}s "$current_version"`
print_tags=`printf %-${n_tags_len}s "$tags"`

print_latest_version="";
if [ "$latest_version_header" ]; then
print_latest_version=`printf %-${n_latest_ver_len}s "$latest_version"`
fi

print_tags=""
if [ "$tags_header" ]; then
print_tags=`printf %-${n_tags_len}s "$tags"`
fi


print_files="";
if [ "$files_header" ]; then
print_files="$(echo "$files" | sed -e $replace_regex)"
Expand Down Expand Up @@ -512,7 +578,18 @@ product_infos__print()
fi
echo ""
}
get_next_stage_version()
{
local next_stage_product_name=$1

local next_product_info=${product_infos[${next_stage_product_name}]}
local next_latest_version=""
if [ "$next_product_info" ]; then
local next_latest_version="$(get_current_version next_product_info next_stage_product_name)"
fi
echo "$next_latest_version"

}

get_tags()
{
Expand Down Expand Up @@ -578,16 +655,29 @@ set_product_info()

get_current_version()
{
if [ ! "$current_version" ] && [ "$stage_product_name" ]; then
get_product_info product_info
if [ "$product_info" ]; then
product_info__get_current_version product_info current_version
product_info_var=$1
if [ "$1" ]; then
local -n product_info_var=$1
local current_version=""
else
local product_info_var="$product_info"
fi
if [ "$2" ]; then
local -n stage_product_name_var=$2
else
local stage_product_name_var="$stage_product_name"
fi

if [ ! "$current_version" ] && [ "$stage_product_name_var" ]; then
get_product_info product_info_var
if [ "$product_info_var" ]; then
product_info__get_current_version product_info_var current_version
fi
if [ ! "$current_version" ] ; then
app_file="products/$stage_product_name/app.yaml"
app_file="products/$stage_product_name_var/app.yaml"
if [ -f $app_file ]; then
current_version=`cat $app_file | grep chartVersion: | cut -d ':' -f 2 |xargs|sed -e 's/"//g'|xargs|tr -d ['\n','\r'] |cut -d '#' -f 1 |xargs`
if [ "$current_version" ]; then
if [ "$current_version" ] && [ ! "$1$2" ]; then
set_product_info
fi
fi
Expand All @@ -598,7 +688,7 @@ get_current_version()

get_latest_version()
{
if [ ! "$product_latest_version" ] && [ "$stage_product_name" ]; then
if [ ! "$product_latest_version" ] && [ "$stage_product_name" ] && [ ! "$is_smud_dev_repo" ]; then
# echo "stage_product_name: $stage_product_name , file: $file"
if [ "$1" ]; then
local -n product_latest_version_local=$1
Expand Down
58 changes: 30 additions & 28 deletions smud-cli/functions-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,35 @@ upgrade()
print_gray "No $context found."
return
fi
list
commits_command="git rev-list $from_commit^..$to_commit $date_range $git_grep --reverse --no-merges $diff_filter -- $upgrade_filter"
run_command --commits --command-var=commits_command --return-var=rev_list --skip-error=true --error-code=upgrade_error_code --debug-title='Find commits to upgrade'

if [ $upgrade_error_code -eq 128 ]; then
commits_command="git rev-list $from_commit..$to_commit $date_range $git_grep --reverse --no-merges $diff_filter -- $upgrade_filter"
run_command --commits --command-var=commits_command --return-var=rev_list --debug-title='Find commits to upgrade' || return
fi

if [ ! "$rev_list" ]; then
print_gray "No $context found."
return
fi

IFS=$'\n';read -rd '' -a rev_list <<< "$rev_list"

correlate_against_already_cherripicked rev_list already_cherry_picked_commits

if [ ${#rev_list[@]} -eq 0 ]; then
if [ $already_cherry_picked_commits -gt 0 ];then
print_gray "All changes already cherry-picked!"
else
print_gray "No $context found."
fi
return
fi

# git_range="${rev_list[@]}"

list

yes_no="yes"
if [ ! "$silent" ]; then
Expand All @@ -108,32 +136,6 @@ upgrade()
local cherrypick_options="--keep-redundant-commits --allow-empty -x"
local upgrade_error_code=0
if [ "$yes_no" = "yes" ]; then
commits_command="git rev-list $from_commit^..$to_commit $date_range $git_grep --reverse --no-merges $diff_filter -- $upgrade_filter"
run_command --commits --command-var=commits_command --return-var=rev_list --skip-error=true --error-code=upgrade_error_code --debug-title='Find commits to upgrade'

if [ $upgrade_error_code -eq 128 ]; then
commits_command="git rev-list $from_commit..$to_commit $date_range $git_grep --reverse --no-merges $diff_filter -- $upgrade_filter"
run_command --commits --command-var=commits_command --return-var=rev_list --debug-title='Find commits to upgrade' || return
fi

if [ ! "$rev_list" ]; then
print_gray "No $context found."
return
fi

IFS=$'\n';read -rd '' -a rev_list <<< "$rev_list"

correlate_against_already_cherripicked rev_list already_cherry_picked_commits

if [ ${#rev_list[@]} -eq 0 ]; then
if [ $already_cherry_picked_commits -gt 0 ];then
print_gray "No $context found. All commits are already cherry-picked!"
else
print_gray "No $context found."
fi
return
fi

commits="${rev_list[@]}"
print_gray "Running: git cherry-pick [commits]...\n"
print_debug "$commits"
Expand Down Expand Up @@ -360,7 +362,7 @@ correlate_against_already_cherripicked()
run_command --has-commits --command-var=cherrypicked_changes_command --return-var='has_cherrypicked_commits' --skip-error --debug-title='Check fo already cherry-picked changes' || return
if [ "$has_cherrypicked_commits" ]; then

print_gray "Compute revision corrolated agains already cherry-picked commits..."
print_debug "Compute revision corrolated agains already cherry-picked commits..."
local cherrypicked_commits=""
local cherrypicked_changes_command="git log HEAD --no-merges --grep cherry.picked.from.commit --pretty=format:%b -- $upgrade_filter"
run_command --has-commits --command-var=cherrypicked_changes_command --return-var='cherrypicked_commits' --skip-error --debug-title='Collect already cherry-picked changes' || return
Expand Down
1 change: 1 addition & 0 deletions smud-cli/include.sh
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ get_arg major '--major'
get_arg minor '--minor'
get_arg patch '--patch'
get_arg same '--same'
get_arg changed '--changed,--changes'
get_arg installed '--installed,-I'
get_arg hide_title '--hide-title'
get_arg silent '--silent'
Expand Down

0 comments on commit 35fef80

Please sign in to comment.