@@ -37,6 +37,28 @@ get_latest_tag() {
3737 echo " "
3838}
3939
40+ check_version () {
41+ local current=$1
42+ local latest=$2
43+
44+ current_major=$( echo " $current " | cut -d. -f1)
45+ current_minor=$( echo " $current " | cut -d. -f2)
46+ current_patch=$( echo " $current " | cut -d. -f3)
47+ latest_major=$( echo " $latest " | cut -d. -f1)
48+ latest_minor=$( echo " $latest " | cut -d. -f2)
49+ latest_patch=$( echo " $latest " | cut -d. -f3)
50+
51+ if [[ " $current_major " -lt " $latest_major " ]]; then
52+ echo " available"
53+ elif [[ " $current_major " -eq " $latest_major " && " $current_minor " -lt " $latest_minor " ]]; then
54+ echo " available"
55+ elif [[ " $current_major " -eq " $latest_major " && " $current_minor " -eq " $latest_minor " && " $current_patch " -lt " $latest_patch " ]]; then
56+ echo " available"
57+ else
58+ echo " up-to-date"
59+ fi
60+ }
61+
4062check_image () {
4163 local full_image=$1
4264
@@ -49,7 +71,7 @@ check_image() {
4971 echo " {
5072 \" image\" :\" $image_name \" ,
5173 \" current\" :\" $current_version \" ,
52- \" latest\" :null ,
74+ \" latest\" :\" N/A \" ,
5375 \" status\" :\" skipped\"
5476 }"
5577 return
@@ -75,28 +97,34 @@ check_image() {
7597 echo " {
7698 \" image\" :\" $image_name \" ,
7799 \" current\" :\" ${prefix}${current_version} \" ,
78- \" latest\" :null ,
100+ \" latest\" :\" N/A \" ,
79101 \" status\" :\" error\"
80102 }"
81103 return
82104 fi
83105
84- if [[ " $current_version " == " $latest " ]]; then
106+ if [[ " $prefix " == " v" ]]; then
107+ latest=" ${latest# v} "
108+ fi
109+
110+ check=$( check_version " $current_version " " $latest " )
111+
112+ if [[ $check == " up-to-date" ]]; then
85113 echo " {
86114 \" image\" :\" $image_name \" ,
87115 \" current\" :\" ${prefix}${current_version} \" ,
88- \" latest\" :\" $latest \" ,
116+ \" latest\" :\" ${prefix}${ latest} \" ,
89117 \" status\" :\" up-to-date\"
90118 }"
91119 return
92120 fi
93121
94122 if [[ " $WRITE_MODE " == true ]]; then
95- sed -i " s|${image_name} :${prefix}${current_version} |${image_name} :${latest} |g" " $COMPOSE_FILE "
123+ sed -i " s|${image_name} :${prefix}${current_version} |${image_name} :i ${prefix} ${latest} |g" " $COMPOSE_FILE "
96124 echo " {
97125 \" image\" :\" $image_name \" ,
98126 \" current\" :\" ${prefix}${current_version} \" ,
99- \" latest\" :\" $latest \" ,
127+ \" latest\" :\" ${prefix}${ latest} \" ,
100128 \" status\" :\" updated\"
101129 }"
102130 return
@@ -105,7 +133,7 @@ check_image() {
105133 echo " {
106134 \" image\" :\" $image_name \" ,
107135 \" current\" :\" ${prefix}${current_version} \" ,
108- \" latest\" :\" $latest \" ,
136+ \" latest\" :\" ${prefix}${ latest} \" ,
109137 \" status\" :\" available\"
110138 }"
111139}
0 commit comments