@@ -155,57 +155,97 @@ private static void MainInner(string? task, string? configs, int? currentSprintN
155
155
Dictionary < string , TaskStateStruct > taskVersionInfo = [ ] ;
156
156
157
157
{
158
- var tasks = MakeOptionsReader . ReadMakeOptions ( gitRootPath ) . AsEnumerable ( )
158
+ IEnumerable < KeyValuePair < string , MakeOptionsReader . AgentTask > > allTasksList = MakeOptionsReader . ReadMakeOptions ( gitRootPath ) . AsEnumerable ( )
159
159
. Where ( c => c . Value . Configs . Any ( ) ) ; // only tasks with configs
160
160
161
- if ( ! allTasks )
162
- {
163
- var taskList = task ! . Split ( ',' , '|' ) ;
161
+ IEnumerable < KeyValuePair < string , MakeOptionsReader . AgentTask > > tasks ;
164
162
165
- tasks = tasks . Where ( s => taskList . Where ( tl => string . Equals ( tl , s . Key , StringComparison . OrdinalIgnoreCase ) ) . Any ( ) ) ;
163
+ if ( allTasks )
164
+ {
165
+ tasks = allTasksList ;
166
166
}
167
-
168
- foreach ( var t in tasks )
167
+ else
169
168
{
170
- taskVersionInfo . Add ( t . Value . Name , new TaskStateStruct ( [ ] , [ ] ) ) ;
169
+ var taskList = task ! . Split ( ',' , '|' ) ;
170
+ tasks = allTasksList . Where ( s => taskList . Where ( tl => string . Equals ( tl , s . Key , StringComparison . OrdinalIgnoreCase ) ) . Any ( ) ) ;
171
171
}
172
172
173
- foreach ( var t in tasks )
173
+ if ( includeLocalPackagesBuildConfig )
174
174
{
175
- IEnumerable < string > configsList = FilterConfigsForTask ( configs , t ) ;
176
- HashSet < Config . ConfigRecord > targetConfigs = GetConfigRecords ( configsList , writeUpdates ) ;
177
- UpdateVersionsForTask ( t . Value . Name , taskVersionInfo [ t . Value . Name ] , targetConfigs , currentSprint , globalVersionPath , ref maxPatchForCurrentSprint , globalVersion , generatedFolder ) ;
178
- CheckForDuplicates ( t . Value . Name , taskVersionInfo [ t . Value . Name ] . configTaskVersionMapping ) ;
179
- }
175
+ Console . WriteLine ( "Updating global version..." ) ;
176
+ var tasksNeedingUpdates = new List < string > ( ) ;
177
+
178
+ // when generating global version, we must enumerate all tasks to generate correct maxPatchForCurrentSprint across all tasks to avoid collisions
179
+ foreach ( var t in allTasksList )
180
+ {
181
+ taskVersionInfo . Add ( t . Value . Name , new TaskStateStruct ( [ ] , [ ] ) ) ;
182
+ IEnumerable < string > configsList = FilterConfigsForTask ( configs , t ) ;
183
+ HashSet < Config . ConfigRecord > targetConfigs = GetConfigRecords ( configsList , writeUpdates ) ;
184
+ UpdateVersionsForTask ( t . Value . Name , taskVersionInfo [ t . Value . Name ] , targetConfigs , currentSprint , globalVersionPath , globalVersion , generatedFolder ) ;
180
185
181
- // bump patch number for global if any tasks invalidated.
182
- if ( taskVersionInfo . Values . Any ( x => x . versionsUpdated . Any ( ) ) )
186
+ bool taskTargettedForUpdating = allTasks || tasks . Where ( x => x . Key == t . Value . Name ) . Any ( ) ;
187
+ bool taskVersionsNeedUpdating = taskVersionInfo [ t . Value . Name ] . versionsUpdated . Any ( ) ;
188
+
189
+ if ( taskVersionsNeedUpdating && ! taskTargettedForUpdating )
190
+ {
191
+ tasksNeedingUpdates . Add ( t . Value . Name ) ;
192
+ }
193
+
194
+ UpdateMaxPatchForSprint ( taskVersionInfo [ t . Value . Name ] , currentSprint , ref maxPatchForCurrentSprint ) ;
195
+ CheckForDuplicates ( t . Value . Name , taskVersionInfo [ t . Value . Name ] . configTaskVersionMapping ) ;
196
+ }
197
+
198
+ if ( tasksNeedingUpdates . Count > 0 )
199
+ {
200
+ throw new Exception ( $ "The following tasks have versions that need updating (needed for updating global version): { string . Join ( ", " , tasksNeedingUpdates ) } . Please run 'node make.js build --task [taskname]' to update") ;
201
+ }
202
+
203
+ // bump patch number for global if any tasks invalidated or if there is no existing global version
204
+ if ( taskVersionInfo . Values . Any ( x => x . versionsUpdated . Any ( ) ) || globalVersion is null )
205
+ {
206
+ maxPatchForCurrentSprint = maxPatchForCurrentSprint + 1 ;
207
+
208
+ Console . WriteLine ( $ "Global version: maxPatchForCurrentSprint = maxPatchForCurrentSprint + 1") ;
209
+ }
210
+
211
+ Console . WriteLine ( $ "Global version update: globalVersion = { globalVersion } maxPatchForCurrentSprint={ maxPatchForCurrentSprint } " ) ;
212
+ }
213
+ else
183
214
{
184
- maxPatchForCurrentSprint = maxPatchForCurrentSprint + 1 ;
215
+ foreach ( var t in tasks )
216
+ {
217
+ taskVersionInfo . Add ( t . Value . Name , new TaskStateStruct ( [ ] , [ ] ) ) ;
218
+ IEnumerable < string > configsList = FilterConfigsForTask ( configs , t ) ;
219
+ HashSet < Config . ConfigRecord > targetConfigs = GetConfigRecords ( configsList , writeUpdates ) ;
220
+ UpdateVersionsForTask ( t . Value . Name , taskVersionInfo [ t . Value . Name ] , targetConfigs , currentSprint , globalVersionPath , globalVersion , generatedFolder ) ;
221
+ CheckForDuplicates ( t . Value . Name , taskVersionInfo [ t . Value . Name ] . configTaskVersionMapping ) ;
222
+ }
185
223
}
186
224
187
225
foreach ( var t in tasks )
188
226
{
189
227
IEnumerable < string > configsList = FilterConfigsForTask ( configs , t ) ;
190
228
229
+ int taskMajorVersion = taskVersionInfo [ t . Value . Name ] . configTaskVersionMapping [ Config . Default ] . Major ;
230
+
191
231
if ( includeLocalPackagesBuildConfig )
192
232
{
193
233
if ( globalVersion is null )
194
234
{
195
- globalVersion = new TaskVersion ( 0 , currentSprint , maxPatchForCurrentSprint ) ;
235
+ globalVersion = new TaskVersion ( taskMajorVersion , currentSprint , maxPatchForCurrentSprint ) ;
196
236
}
197
237
else
198
238
{
199
239
if ( globalVersion . Minor == currentSprint )
200
240
{
201
241
globalVersion = globalVersion . CloneWithMinorAndPatch ( currentSprint , Math . Max ( maxPatchForCurrentSprint , globalVersion . Patch ) ) ;
202
- globalVersion = globalVersion . CloneWithMajor ( taskVersionInfo [ t . Value . Name ] . configTaskVersionMapping [ Config . Default ] . Major ) ;
242
+ globalVersion = globalVersion . CloneWithMajor ( taskMajorVersion ) ;
203
243
}
204
244
else
205
245
{
206
246
// this could fail if there is a task with a future-sprint version, which should not be the case. If that happens, CheckForDuplicates will throw
207
247
globalVersion = globalVersion . CloneWithMinorAndPatch ( currentSprint , 0 ) ;
208
- globalVersion = globalVersion . CloneWithMajor ( taskVersionInfo [ t . Value . Name ] . configTaskVersionMapping [ Config . Default ] . Major ) ;
248
+ globalVersion = globalVersion . CloneWithMajor ( taskMajorVersion ) ;
209
249
}
210
250
}
211
251
}
@@ -226,7 +266,7 @@ private static void MainInner(string? task, string? configs, int? currentSprintN
226
266
}
227
267
228
268
ThrowWithUserFriendlyErrorToRerunWithWriteUpdatesIfVeriferError ( "(global)" , skipContentCheck : false ) ;
229
-
269
+
230
270
foreach ( var t in tasks )
231
271
{
232
272
IEnumerable < string > configsList = FilterConfigsForTask ( configs , t ) ;
@@ -1035,7 +1075,7 @@ private static void CopyConfig(string gitRootPath, string taskTargetPathOrUnders
1035
1075
}
1036
1076
}
1037
1077
1038
- private static void UpdateVersionsForTask ( string task , TaskStateStruct taskState , HashSet < Config . ConfigRecord > targetConfigs , int currentSprint , string globalVersionPath , ref int maxPatchForCurrentSprint , TaskVersion ? globalVersion , string generatedFolder )
1078
+ private static void UpdateVersionsForTask ( string task , TaskStateStruct taskState , HashSet < Config . ConfigRecord > targetConfigs , int currentSprint , string globalVersionPath , TaskVersion ? globalVersion , string generatedFolder )
1039
1079
{
1040
1080
string currentDir = Environment . CurrentDirectory ;
1041
1081
string gitRootPath = GitUtil . GetGitRootPath ( currentDir ) ;
@@ -1102,23 +1142,23 @@ private static void UpdateVersionsForTask(string task, TaskStateStruct taskState
1102
1142
}
1103
1143
}
1104
1144
1105
- TaskVersion baseVersion = maxVersion ;
1145
+ if ( ! allConfigsMappedAndValid )
1146
+ {
1147
+ TaskVersion baseVersion = maxVersion ;
1106
1148
1107
- bool baseVersionIsCurrentSprint = baseVersion . Minor == currentSprint ;
1149
+ bool baseVersionIsCurrentSprint = baseVersion . Minor == currentSprint ;
1108
1150
1109
- int offset = 0 ;
1151
+ int offset = 0 ;
1110
1152
1111
- if ( baseVersionIsCurrentSprint )
1112
- {
1113
- offset = 1 ;
1114
- }
1115
- else
1116
- {
1117
- baseVersion = inputVersion . CloneWithMinorAndPatch ( currentSprint , 0 ) ;
1118
- }
1153
+ if ( baseVersionIsCurrentSprint )
1154
+ {
1155
+ offset = 1 ;
1156
+ }
1157
+ else
1158
+ {
1159
+ baseVersion = inputVersion . CloneWithMinorAndPatch ( currentSprint , 0 ) ;
1160
+ }
1119
1161
1120
- if ( ! allConfigsMappedAndValid )
1121
- {
1122
1162
var old = new Dictionary < Config . ConfigRecord , TaskVersion > ( ) ;
1123
1163
foreach ( var x in taskState . configTaskVersionMapping )
1124
1164
{
@@ -1181,7 +1221,10 @@ private static void UpdateVersionsForTask(string task, TaskStateStruct taskState
1181
1221
}
1182
1222
}
1183
1223
}
1224
+ }
1184
1225
1226
+ private static void UpdateMaxPatchForSprint ( TaskStateStruct taskState , int currentSprint , ref int maxPatchForCurrentSprint )
1227
+ {
1185
1228
foreach ( var x in taskState . configTaskVersionMapping )
1186
1229
{
1187
1230
// accumulate the max patch, excluding existing globalversion (used for providing a new global version)
0 commit comments