@@ -37,15 +37,25 @@ def __init__(self):
3737""" )
3838
3939 def get_version_for_tag (self , tag ) -> Tuple [int , int ]:
40- if tag ['matches' ][ ' major' ] is not None :
41- return int ( tag ['matches' ][ ' major' ]), int ( tag ['matches' ][ ' minor' ])
40+ if tag ['major' ] > 0 :
41+ return tag ['major' ], tag ['minor' ]
4242 else :
4343 # fetch number from version.h in the vehicle folder in the given tag
4444 self .repository .git .checkout (tag ["tag" ], force = True )
4545 # try to read <vehicle>/version.h
46- path1 = Path (f'{ self .repository_path } /{ tag ["matches" ]["name" ]} /version.h' )
47- path2 = Path (f'{ self .repository_path } /{ self .valid_name_map [tag ["matches" ]["name" ]]} /version.h' )
48- file = path1 if path1 .exists () else path2
46+ repo_path = Path (self .repository_path )
47+ potential_paths = (
48+ repo_path / tag ['name' ] / 'version.h' ,
49+ repo_path / tag ['vehicle_type' ] / 'version.h' ,
50+ repo_path / f'Ardu{ tag ["vehicle_type" ]} ' / 'version.h' ,
51+ )
52+ for file in potential_paths :
53+ if file .exists ():
54+ break # We found a valid file
55+ else :
56+ print (f'No version.h found for { tag ["name" ]} ' )
57+ return 0 , 0
58+
4959 with open (file = file , mode = 'r' ) as version_file :
5060 content = version_file .read ()
5161 match = re .search (r'#define\s+FW_MAJOR\s+(\d+)' , content )
@@ -78,31 +88,46 @@ def run(self):
7888 # TEMP-END
7989
8090 # Get only valid tag names
81- tags = [
82- {
83- 'tag' : self .tag_regex .search (tag )[0 ],
91+ tags = []
92+ for tag in tag_names :
93+ tag_data = self .tag_regex .search (tag )
94+ if not tag_data :
95+ continue # Not a recognisable tag --> ignore
96+ matches = tag_data .groupdict ()
97+ if not (vehicle_type := self .valid_name_map .get (matches ['name' ])):
98+ continue # Not a vehicle tag --> ignore
99+ major , minor , patch = (int (matches [field ] or 0 ) for field in ('major' , 'minor' , 'patch' ))
100+ tags .append ({
101+ 'tag' : tag_data [0 ],
84102 'reference' : tag ,
85- 'matches' : {** self .tag_regex .search (tag ).groupdict ()}
86- } for tag in tag_names if self .tag_regex .search (tag )
87- ]
88- tags = [tag for tag in tags if self .valid_name_map .get (tag ['matches' ]['name' ])]
103+ 'name' : matches ['name' ],
104+ 'vehicle_type' : vehicle_type ,
105+ 'major' : major ,
106+ 'minor' : minor ,
107+ 'patch' : patch ,
108+ 'beta' : matches ['beta' ],
109+ })
110+
111+ # Sort the tags so they appear in sequence, grouped by vehicle type
112+ tags .sort (key = lambda tag : tuple (tag [field ] for field in ('vehicle_type' , 'major' , 'minor' , 'patch' )))
113+
89114 # Get only the newest patch version
90115 old_versions = []
91116 previous_tag = None
92117 for tag in tags :
93118 # Beta releases are unique, we don't need to compare them
94- if tag ['matches' ][ ' beta' ]:
119+ if tag ['beta' ]:
95120 continue
96121 if previous_tag :
97122 print (f'{ previous_tag ["tag" ]} => { tag ["tag" ]} ' )
98123 if not previous_tag or (
99- tag ['matches' ][ 'name' ] != previous_tag ['matches' ][ 'name ' ]
100- or tag ['matches' ][ ' major' ] != previous_tag [ 'matches' ] ['major' ]
101- or tag ['matches' ][ ' minor' ] != previous_tag [ 'matches' ] ['minor' ]
124+ tag ['vehicle_type' ] != previous_tag ['vehicle_type ' ]
125+ or tag ['major' ] != previous_tag ['major' ]
126+ or tag ['minor' ] != previous_tag ['minor' ]
102127 ):
103128 previous_tag = tag
104129 continue
105- if tag ['matches' ][ ' patch' ] > previous_tag [ 'matches' ] ['patch' ]:
130+ if tag ['patch' ] > previous_tag ['patch' ]:
106131 print (f'Remove { previous_tag ["tag" ]} ' )
107132 old_versions .append (previous_tag ['tag' ])
108133 previous_tag = tag
@@ -114,11 +139,10 @@ def run(self):
114139
115140 # Generate parameters for all tags
116141 for tag in tags :
117- tag_name = tag ['tag' ]
118- tag_simple_name = tag ['matches' ]['name' ]
142+ tag_name , vehicle_type , tag_reference = (
143+ tag [field ] for field in ('tag' , 'vehicle_type' , 'reference' )
144+ )
119145 tag_major_version , tag_minor_version = self .get_version_for_tag (tag )
120- vehicle_type = self .valid_name_map .get (tag_simple_name )
121- tag_reference = tag ['reference' ]
122146 folder_name = f'{ vehicle_type } -{ tag_major_version } .{ tag_minor_version } '
123147
124148 if not vehicle_type :
0 commit comments