Skip to content

Commit cc9f162

Browse files
authored
chore: add cloud release workflow (#746)
* chore: add cloud release workflow * chore: add cloud release workflow
1 parent e7527b4 commit cc9f162

4 files changed

Lines changed: 928 additions & 74 deletions

File tree

.github/utils/release_gitlab.sh

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Usage: $(basename "$0") <options>
2626
3) release helm chart
2727
4) update release latest
2828
5) delete release
29-
6) delete helm chart
29+
6) delete helm chart (KubeBlocks)
30+
7) delete helm chart
3031
-tn, --tag-name Release tag name
3132
-pi, --project-id Gitlab repo project id or "group%2Fproject"
3233
-at, --access-token Gitlab access token
@@ -64,6 +65,10 @@ main() {
6465
parse_command_line "$@"
6566

6667
local TAG_NAME_TMP=${TAG_NAME/v/}
68+
if [[ "${TAG_NAME}" == *"|"* ]]; then
69+
# Strip leading 'v' from all tag versions in the pipe-separated list
70+
local TAG_NAME_TMP=$(echo "$TAG_NAME" | sed 's/^v//;s/|v/|/g')
71+
fi
6772

6873
case $TYPE in
6974
5|6)
@@ -95,6 +100,9 @@ main() {
95100
6)
96101
delete_kubeblocks_helm_chart
97102
;;
103+
7)
104+
delete_helm_chart
105+
;;
98106
esac
99107

100108

@@ -475,29 +483,79 @@ filter_charts() {
475483
wait
476484
}
477485

478-
delete_helm_chart() {
479-
TAG_NAME="$TAG_NAME_TMP"
480-
get_addons_list
481-
local DELETE_CHARTS_DIR=""
482-
for charts_dir in $(echo "deploy" | sed 's/|/ /g'); do
483-
if [[ ! -d "$charts_dir" ]]; then
484-
echo "not found chart dir $charts_dir"
485-
continue
486-
fi
487-
DELETE_CHARTS_DIR=$charts_dir
488-
charts_files=$( ls -1 $charts_dir )
489-
echo "$charts_files" | filter_charts
490-
done
491-
}
492-
493486
delete_kubeblocks_helm_chart() {
494487
chart_file="deploy/helm/Chart.yaml"
495488
if [[ -f "$chart_file" ]]; then
496-
chart_name=$(cat $file | yq eval '.name' -)
489+
chart_name=$(cat $chart_file | yq eval '.name' -)
497490
echo "delete helm_chart $chart_name $TAG_NAME_TMP"
498491
PROJECT_ID_TMP="${DEFAULT_HELM_CHARTS_PROJECT_ID}"
499492
delete_release_packages "$chart_name" "$PROJECT_ID_TMP"
500493
fi
501494
}
502495

496+
delete_release_packages_all() {
497+
delete_name=${1:-""}
498+
project_id=${2:-""}
499+
request_type=DELETE
500+
page_num=1
501+
request_url=""
502+
503+
# Split TAG_NAME by '|' into a bash array for batch matching
504+
local -a tag_list
505+
IFS='|' read -r -a tag_list <<< "$TAG_NAME_TMP"
506+
local -a remaining_tags=("${tag_list[@]}")
507+
508+
while true; do
509+
request_url="$API_URL/$project_id/packages?page=$page_num&per_page=100"
510+
packages_info=$( gitlab_api_curl -s $request_url )
511+
length=$( echo "$packages_info" | jq length )
512+
if [[ $length -eq 0 ]]; then
513+
break
514+
fi
515+
for (( i=0; i<length; i++ )); do
516+
package_version_raw=$( echo "$packages_info" | jq -r ".[$i].version" )
517+
package_name_raw=$( echo "$packages_info" | jq -r ".[$i].name" )
518+
if [[ "$package_name_raw" != "$delete_name" ]]; then
519+
continue
520+
fi
521+
# Check if this version is in our remaining tags
522+
local found_idx=-1
523+
for idx in "${!remaining_tags[@]}"; do
524+
if [[ "${remaining_tags[$idx]}" == "$package_version_raw" || "v${remaining_tags[$idx]}" == "$package_version_raw" ]]; then
525+
found_idx=$idx
526+
break
527+
fi
528+
done
529+
if [[ $found_idx -ge 0 ]]; then
530+
package_id=$( echo "$packages_info" | jq ".[$i].id" )
531+
echo "package_id:$package_id"
532+
echo "delete packages $package_name_raw $package_version_raw"
533+
local delete_url=$API_URL/$project_id/packages/$package_id
534+
gitlab_api_curl --request $request_type $delete_url
535+
unset 'remaining_tags[found_idx]'
536+
if [[ ${#remaining_tags[@]} -eq 0 ]]; then
537+
return
538+
fi
539+
fi
540+
done
541+
page_num=$(( $page_num + 1 ))
542+
done
543+
}
544+
545+
delete_helm_chart() {
546+
if [[ -n "$CHARTS_DIR" ]]; then
547+
for chart_name in $(echo "$CHARTS_DIR" | sed 's/|/ /g'); do
548+
echo "delete helm_chart $chart_name"
549+
echo "delete versions $TAG_NAME_TMP"
550+
PROJECT_ID_TMP="${DEFAULT_APPLICATIONS_PROJECT_ID}"
551+
if [[ "$chart_name" == "kubeblocks-cloud" ]]; then
552+
PROJECT_ID_TMP="${DEFAULT_ENTERPRISE_PROJECT_ID}"
553+
elif [[ "$chart_name" == "kb-cloud-bootstrapper" ]]; then
554+
PROJECT_ID_TMP="${DEFAULT_CACHE_PROJECT_ID}"
555+
fi
556+
delete_release_packages_all "$chart_name" "$PROJECT_ID_TMP"
557+
done
558+
fi
559+
}
560+
503561
main "$@"

0 commit comments

Comments
 (0)