@@ -10,41 +10,75 @@ if [ "$#" -lt 1 ]; then
1010 exit 1
1111fi
1212
13+ version_grep () {
14+ grep -E ' ^ version:'
15+ }
16+
17+ version_sed () {
18+ sed -r ' s/^ version:[[:space:]]+([^[:space:]]+).*$/\1/;s|"||g'
19+ }
20+
1321epoch_grep () {
14- grep -E ' ^[[:space:]]+ epoch:'
22+ grep -E ' ^ epoch:'
1523}
1624
1725epoch_sed () {
18- sed -r ' s/^[[:space:]]+ epoch:[[:space:]]+([0-9]+).*$/\1/'
26+ sed -r ' s/^ epoch:[[:space:]]+([0-9]+).*$/\1/'
1927}
2028
2129for yaml_file in " $@ " ; do
2230 echo " Checking $yaml_file :"
2331
24- # Extract the epoch from the current file using grep and sed
32+ # Extract version and epoch from the current file using grep and sed
2533 # (not assuming `yq` is available)
34+ version_line=" $( version_grep < " $yaml_file " ) "
35+ version_local=" $( echo " $version_line " | version_sed) "
36+ if [ -z " $version_local " ]; then
37+ version_local=" 0"
38+ fi
39+
2640 epoch_line=" $( epoch_grep < " $yaml_file " ) "
2741 epoch_local=" $( echo " $epoch_line " | epoch_sed) "
2842 if [ -z " $epoch_local " ]; then
29- echo " Warning: 'epoch' field not found in $yaml_file "
30- echo " "
31- continue
43+ epoch_local=" 0"
3244 fi
3345
34- # Extract the epoch from the file on the main branch using git show
35- epoch_main_line=" $( git show main:" $yaml_file " 2> /dev/null | epoch_grep) "
36- epoch_main=" $( echo " $epoch_main_line " | epoch_sed) "
37- if [ -z " $epoch_main " ]; then
38- echo " Warning: 'epoch' field not found in $yaml_file on branch 'main'"
39- echo " "
40- continue
46+ # Extract version and epoch from the file on the main branch using git show
47+ # Treat missing file as version 0 and epoch 0
48+ main_content=" $( git show main:" $yaml_file " 2> /dev/null) "
49+ if [ -z " $main_content " ]; then
50+ version_main=" 0"
51+ epoch_main=" 0"
52+ else
53+ version_main_line=" $( echo " $main_content " | version_grep) "
54+ version_main=" $( echo " $version_main_line " | version_sed) "
55+ if [ -z " $version_main " ]; then
56+ version_main=" 0"
57+ fi
58+
59+ epoch_main_line=" $( echo " $main_content " | epoch_grep) "
60+ epoch_main=" $( echo " $epoch_main_line " | epoch_sed) "
61+ if [ -z " $epoch_main " ]; then
62+ epoch_main=" 0"
63+ fi
4164 fi
4265
43- # Compare the two epoch values (assumed to be integers)
44- if (( epoch_local > epoch_main )) ; then
45- echo " ✅ Epoch has been increased compared to main: $epoch_local > $epoch_main "
66+ # Compare version first, then epoch only if versions are the same
67+ if [ " $version_local " != " $version_main " ]; then
68+ # Versions are different - version comparison is sufficient
69+ # Use sort -V for version comparison
70+ if [ " $( printf ' %s\n' " $version_local " " $version_main " | sort -V | head -n1) " = " $version_main " ] && [ " $version_local " != " $version_main " ]; then
71+ echo " ✅ Version has been increased compared to main: $version_local > $version_main "
72+ else
73+ echo " ⚠️ Version HAS NOT been increased compared to main: $version_local <= $version_main "
74+ fi
4675 else
47- echo " ⚠️ Epoch HAS NOT been increased compared to main: $epoch_local <= $epoch_main "
76+ # Versions are the same - check epoch
77+ if (( epoch_local > epoch_main )) ; then
78+ echo " ✅ Epoch has been increased compared to main: $epoch_local > $epoch_main (version: $version_local )"
79+ else
80+ echo " ⚠️ Epoch HAS NOT been increased compared to main: $epoch_local <= $epoch_main (version: $version_local )"
81+ fi
4882 fi
4983
5084done
0 commit comments