@@ -46,7 +46,7 @@ internal static class Config
46
46
{
47
47
public static readonly string [ ] ExtensionsToPreprocess = new [ ] { ".ts" , ".json" } ;
48
48
49
- public record ConfigRecord ( string name , string constMappingKey , bool isDefault , bool isNode , string nodePackageVersion , bool isWif , string nodeHandler , string preprocessorVariableName , bool enableBuildConfigOverrides , bool deprecated , bool shouldUpdateTypescript , bool writeNpmrc , string ? overriddenDirectoryName = null , bool shouldUpdateLocalPkgs = false , bool useGlobalVersion = false , bool useAltGeneratedPath = false , bool mergeToBase = false ) ;
49
+ public record ConfigRecord ( string name , string constMappingKey , bool isDefault , bool isNode , string nodePackageVersion , bool isWif , string nodeHandler , string preprocessorVariableName , bool enableBuildConfigOverrides , bool deprecated , bool shouldUpdateTypescript , bool writeNpmrc , string ? overriddenDirectoryName = null , bool shouldUpdateLocalPkgs = false , bool useGlobalVersion = false , bool useAltGeneratedPath = false , bool mergeToBase = false , bool abTaskReleases = true ) ;
50
50
51
51
public static readonly ConfigRecord Default = new ConfigRecord ( name : nameof ( Default ) , constMappingKey : "Default" , isDefault : true , isNode : false , nodePackageVersion : "" , isWif : false , nodeHandler : "" , preprocessorVariableName : "DEFAULT" , enableBuildConfigOverrides : false , deprecated : false , shouldUpdateTypescript : false , writeNpmrc : false ) ;
52
52
public static readonly ConfigRecord Node16 = new ConfigRecord ( name : nameof ( Node16 ) , constMappingKey : "Node16-219" , isDefault : false , isNode : true , nodePackageVersion : "^16.11.39" , isWif : false , nodeHandler : "Node16" , preprocessorVariableName : "NODE16" , enableBuildConfigOverrides : true , deprecated : true , shouldUpdateTypescript : false , writeNpmrc : false ) ;
@@ -86,12 +86,22 @@ public record ConfigRecord(string name, string constMappingKey, bool isDefault,
86
86
/// <param name="getTaskVersionTable"></param>
87
87
/// <param name="debugAgentDir">When set to the local pipeline agent directory, this tool will produce tasks in debug mode with the corresponding visual studio launch configurations that can be used to attach to built tasks running on this agent</param>
88
88
/// <param name="includeLocalPackagesBuildConfig">Include LocalPackagesBuildConfig</param>
89
- static void Main ( string ? task = null , string ? configs = null , int ? currentSprint = null , bool writeUpdates = false , bool allTasks = false , bool getTaskVersionTable = false , string ? debugAgentDir = null , bool includeLocalPackagesBuildConfig = false )
89
+ /// <param name="useSemverBuildConfig">If true, the semver "build" (suffix) will be generated for each task configuration produced, but all tasks configurations will have the same version (for example '1.2.3-node20' and 1.2.3-wif). The default configuration gets no build suffix (e.g. 1.2.3).</param>
90
+ static void Main (
91
+ string ? task = null ,
92
+ string ? configs = null ,
93
+ int ? currentSprint = null ,
94
+ bool writeUpdates = false ,
95
+ bool allTasks = false ,
96
+ bool getTaskVersionTable = false ,
97
+ string ? debugAgentDir = null ,
98
+ bool includeLocalPackagesBuildConfig = false ,
99
+ bool useSemverBuildConfig = false )
90
100
{
91
101
try
92
102
{
93
103
ensureUpdateModeVerifier = new EnsureUpdateModeVerifier ( ! writeUpdates ) ;
94
- MainInner ( task , configs , currentSprint , writeUpdates , allTasks , getTaskVersionTable , debugAgentDir , includeLocalPackagesBuildConfig ) ;
104
+ MainInner ( task , configs , currentSprint , writeUpdates , allTasks , getTaskVersionTable , debugAgentDir , includeLocalPackagesBuildConfig , useSemverBuildConfig ) ;
95
105
}
96
106
catch ( Exception e2 )
97
107
{
@@ -113,7 +123,16 @@ static void Main(string? task = null, string? configs = null, int? currentSprint
113
123
}
114
124
}
115
125
116
- private static void MainInner ( string ? task , string ? configs , int ? currentSprintNullable , bool writeUpdates , bool allTasks , bool getTaskVersionTable , string ? debugAgentDir , bool includeLocalPackagesBuildConfig )
126
+ private static void MainInner (
127
+ string ? task ,
128
+ string ? configs ,
129
+ int ? currentSprintNullable ,
130
+ bool writeUpdates ,
131
+ bool allTasks ,
132
+ bool getTaskVersionTable ,
133
+ string ? debugAgentDir ,
134
+ bool includeLocalPackagesBuildConfig ,
135
+ bool useSemverBuildConfig )
117
136
{
118
137
if ( allTasks )
119
138
{
@@ -313,7 +332,18 @@ private static void MainInner(string? task, string? configs, int? currentSprintN
313
332
{
314
333
IEnumerable < string > configsList = FilterConfigsForTask ( configs , t ) ;
315
334
316
- MainUpdateTask ( taskVersionInfo [ t . Value . Name ] , t . Value . Name , configsList , writeUpdates , currentSprint , debugConfGen , includeLocalPackagesBuildConfig , hasGlobalVersion : globalVersion is not null , generatedFolder : generatedFolder , altGeneratedFolder : altGeneratedFolder ) ;
335
+ MainUpdateTask (
336
+ taskVersionInfo [ t . Value . Name ] ,
337
+ t . Value . Name ,
338
+ configsList ,
339
+ writeUpdates ,
340
+ currentSprint ,
341
+ debugConfGen ,
342
+ includeLocalPackagesBuildConfig ,
343
+ hasGlobalVersion : globalVersion is not null ,
344
+ generatedFolder : generatedFolder ,
345
+ altGeneratedFolder : altGeneratedFolder ,
346
+ useSemverBuildConfig : useSemverBuildConfig ) ;
317
347
}
318
348
319
349
debugConfGen . WriteLaunchConfigurations ( ) ;
@@ -464,6 +494,7 @@ private static void GetVersions(string task, string configsString, out List<(str
464
494
string gitRootPath = GetTasksRootPath ( currentDir ) ;
465
495
466
496
string taskTargetPath = Path . Combine ( gitRootPath , "Tasks" , task ) ;
497
+
467
498
if ( ! Directory . Exists ( taskTargetPath ) )
468
499
{
469
500
throw new Exception ( $ "expected { taskTargetPath } to exist!") ;
@@ -572,7 +603,8 @@ private static void MainUpdateTask(
572
603
bool includeLocalPackagesBuildConfig ,
573
604
bool hasGlobalVersion ,
574
605
string generatedFolder ,
575
- string altGeneratedFolder )
606
+ string altGeneratedFolder ,
607
+ bool useSemverBuildConfig )
576
608
{
577
609
if ( string . IsNullOrEmpty ( task ) )
578
610
{
@@ -717,7 +749,18 @@ private static void MainUpdateTask(
717
749
WriteWIFInputTaskJson ( taskOutput , config , "task.json" , isLoc : false ) ;
718
750
WriteWIFInputTaskJson ( taskOutput , config , "task.loc.json" , isLoc : true ) ;
719
751
720
- if ( ! config . mergeToBase )
752
+ if ( useSemverBuildConfig && ! config . mergeToBase )
753
+ {
754
+ var defaultConfig = targetConfigs . FirstOrDefault ( x => x . isDefault ) ;
755
+ if ( defaultConfig == null )
756
+ {
757
+ throw new Exception ( $ "There is no default config for task { task } ") ;
758
+ }
759
+
760
+ WriteTaskJson ( taskOutput , taskVersionState , config , "task.json" , existingLocalPackageVersion , useSemverBuildConfig : true , defaultConfig : defaultConfig ) ;
761
+ WriteTaskJson ( taskOutput , taskVersionState , config , "task.loc.json" , existingLocalPackageVersion , useSemverBuildConfig : true , defaultConfig : defaultConfig ) ;
762
+ }
763
+ else if ( ! config . mergeToBase )
721
764
{
722
765
WriteTaskJson ( taskOutput , taskVersionState , config , "task.json" , existingLocalPackageVersion ) ;
723
766
WriteTaskJson ( taskOutput , taskVersionState , config , "task.loc.json" , existingLocalPackageVersion ) ;
@@ -1048,7 +1091,12 @@ private static void PreprocessIfExtensionEnabledInConfig(string file, Config.Con
1048
1091
return outputTaskNodeObject [ "_buildConfigMapping" ] ? . AsObject ( ) ? [ Config . LocalPackages . constMappingKey ] ? . GetValue < string > ( ) ;
1049
1092
}
1050
1093
1051
- private static void WriteTaskJson ( string taskPath , TaskStateStruct taskState , Config . ConfigRecord config , string fileName , string ? existingLocalPackageVersion )
1094
+ /// <summary>
1095
+ /// Writes task.json with version information and build config mapping.
1096
+ /// When useSemverBuildConfig is true, uses the same major.minor.patch for all build configuration tasks,
1097
+ /// but the "build" suffix of semver is different and directly corresponds to the config name.
1098
+ /// </summary>
1099
+ private static void WriteTaskJson ( string taskPath , TaskStateStruct taskState , Config . ConfigRecord config , string fileName , string ? existingLocalPackageVersion , bool useSemverBuildConfig = false , Config . ConfigRecord ? defaultConfig = null )
1052
1100
{
1053
1101
string outputTaskPath = Path . Combine ( taskPath , fileName ) ;
1054
1102
JsonNode outputTaskNode = JsonNode . Parse ( ensureUpdateModeVerifier ! . FileReadAllText ( outputTaskPath ) ) ! ;
@@ -1057,6 +1105,12 @@ private static void WriteTaskJson(string taskPath, TaskStateStruct taskState, Co
1057
1105
outputTaskNode [ "version" ] ! [ "Minor" ] = taskState . configTaskVersionMapping [ config ] . Minor ;
1058
1106
outputTaskNode [ "version" ] ! [ "Patch" ] = taskState . configTaskVersionMapping [ config ] . Patch ;
1059
1107
1108
+ // Add semver build suffix if using semver config and not the default config
1109
+ if ( useSemverBuildConfig && defaultConfig != null && defaultConfig != config )
1110
+ {
1111
+ outputTaskNode [ "version" ] ! [ "Build" ] = config . constMappingKey ;
1112
+ }
1113
+
1060
1114
var outputTaskNodeObject = outputTaskNode . AsObject ( ) ;
1061
1115
outputTaskNodeObject . Remove ( "_buildConfigMapping" ) ;
1062
1116
@@ -1305,7 +1359,6 @@ private static void UpdateVersionsForTask(string task, TaskStateStruct taskState
1305
1359
string currentDir = Environment . CurrentDirectory ;
1306
1360
string gitRootPath = GetTasksRootPath ( currentDir ) ;
1307
1361
string taskTargetPath = Path . Combine ( gitRootPath , "Tasks" , task ) ;
1308
-
1309
1362
if ( ! Directory . Exists ( taskTargetPath ) )
1310
1363
{
1311
1364
throw new Exception ( $ "expected { taskTargetPath } to exist!") ;
@@ -1481,6 +1534,13 @@ private static void UpdateVersionsForTask(string task, TaskStateStruct taskState
1481
1534
}
1482
1535
while ( taskState . configTaskVersionMapping . Values . Contains ( targetVersion ) ) ;
1483
1536
1537
+ if ( config . abTaskReleases )
1538
+ {
1539
+ // In the first stage of refactoring, we keep different version numbers to retain the ability to rollback.
1540
+ // In the second stage of refactoring, we are going to use the same version, which is going to significantly reduce complexity of all this.
1541
+ targetVersion = targetVersion . CloneWithBuild ( config . constMappingKey ) ;
1542
+ }
1543
+
1484
1544
taskState . configTaskVersionMapping . Add ( config , targetVersion ) ;
1485
1545
1486
1546
if ( ! taskState . versionsUpdated . Contains ( config ) )
@@ -1555,11 +1615,20 @@ private static void UpdateVersionsGlobal(string task, TaskStateStruct taskState,
1555
1615
{
1556
1616
if ( config . useGlobalVersion )
1557
1617
{
1618
+ TaskVersion versionToUse = globalVersion ;
1619
+
1620
+ if ( config . abTaskReleases )
1621
+ {
1622
+ // In the first stage of refactoring, we keep different version numbers to retain the ability to rollback.
1623
+ // In the second stage of refactoring, we are going to use the same version, which is going to significantly reduce complexity of all this.
1624
+ versionToUse = globalVersion . CloneWithBuild ( config . constMappingKey ) ;
1625
+ }
1626
+
1558
1627
if ( taskState . configTaskVersionMapping . ContainsKey ( config ) )
1559
1628
{
1560
- if ( taskState . configTaskVersionMapping [ config ] != globalVersion )
1629
+ if ( taskState . configTaskVersionMapping [ config ] != versionToUse )
1561
1630
{
1562
- taskState . configTaskVersionMapping [ config ] = globalVersion ;
1631
+ taskState . configTaskVersionMapping [ config ] = versionToUse ;
1563
1632
1564
1633
if ( ! taskState . versionsUpdated . Contains ( config ) )
1565
1634
{
@@ -1569,7 +1638,7 @@ private static void UpdateVersionsGlobal(string task, TaskStateStruct taskState,
1569
1638
}
1570
1639
else
1571
1640
{
1572
- taskState . configTaskVersionMapping . Add ( config , globalVersion ) ;
1641
+ taskState . configTaskVersionMapping . Add ( config , versionToUse ) ;
1573
1642
1574
1643
if ( ! taskState . versionsUpdated . Contains ( config ) )
1575
1644
{
0 commit comments