@@ -647,7 +647,7 @@ private static void MainUpdateTask(
647
647
var targetConfigsWithMergeToBaseOrderedFirst = targetConfigs . OrderBy ( x => x . mergeToBase ? 0 : 1 ) ;
648
648
649
649
var defaultConfig = targetConfigs . FirstOrDefault ( x => x . isDefault )
650
- ?? throw new ArgumentException ( $ "There is no default config for task { task } which is required if { nameof ( useSemverBuildConfig ) } is true ") ;
650
+ ?? throw new Exception ( $ "There is no default config for task { task } ") ;
651
651
652
652
foreach ( var config in targetConfigsWithMergeToBaseOrderedFirst )
653
653
{
@@ -751,10 +751,10 @@ private static void MainUpdateTask(
751
751
WriteWIFInputTaskJson ( taskOutput , config , "task.json" , isLoc : false ) ;
752
752
WriteWIFInputTaskJson ( taskOutput , config , "task.loc.json" , isLoc : true ) ;
753
753
754
- if ( useSemverBuildConfig )
754
+ if ( useSemverBuildConfig && ! config . mergeToBase )
755
755
{
756
- WriteTaskJsonWithSemverConfig ( taskOutput , taskVersionState , defaultConfig , config , "task.json" , existingLocalPackageVersion ) ;
757
- WriteTaskJsonWithSemverConfig ( taskOutput , taskVersionState , defaultConfig , config , "task.loc.json" , existingLocalPackageVersion ) ;
756
+ WriteTaskJson ( taskOutput , taskVersionState , config , "task.json" , existingLocalPackageVersion , useSemverBuildConfig : true , defaultConfig : defaultConfig ) ;
757
+ WriteTaskJson ( taskOutput , taskVersionState , config , "task.loc.json" , existingLocalPackageVersion , useSemverBuildConfig : true , defaultConfig : defaultConfig ) ;
758
758
}
759
759
else if ( ! config . mergeToBase )
760
760
{
@@ -1087,62 +1087,12 @@ private static void PreprocessIfExtensionEnabledInConfig(string file, Config.Con
1087
1087
return outputTaskNodeObject [ "_buildConfigMapping" ] ? . AsObject ( ) ? [ Config . LocalPackages . constMappingKey ] ? . GetValue < string > ( ) ;
1088
1088
}
1089
1089
1090
- private static void WriteTaskJson ( string taskPath , TaskStateStruct taskState , Config . ConfigRecord config , string fileName , string ? existingLocalPackageVersion )
1091
- {
1092
- string outputTaskPath = Path . Combine ( taskPath , fileName ) ;
1093
- JsonNode outputTaskNode = JsonNode . Parse ( ensureUpdateModeVerifier ! . FileReadAllText ( outputTaskPath ) ) ! ;
1094
-
1095
- outputTaskNode [ "version" ] ! [ "Major" ] = taskState . configTaskVersionMapping [ config ] . Major ;
1096
- outputTaskNode [ "version" ] ! [ "Minor" ] = taskState . configTaskVersionMapping [ config ] . Minor ;
1097
- outputTaskNode [ "version" ] ! [ "Patch" ] = taskState . configTaskVersionMapping [ config ] . Patch ;
1098
-
1099
- var outputTaskNodeObject = outputTaskNode . AsObject ( ) ;
1100
- outputTaskNodeObject . Remove ( "_buildConfigMapping" ) ;
1101
-
1102
- bool anyVersionsUpdatedExceptForGlobal = taskState . versionsUpdated . Where ( x => ! x . useGlobalVersion ) . Any ( ) ;
1103
-
1104
- JsonObject configMapping = new JsonObject ( ) ;
1105
- var configTaskVersionMappingSortedByConfig = taskState . configTaskVersionMapping . OrderBy ( x => x . Key . name ) ;
1106
- foreach ( var cfg in configTaskVersionMappingSortedByConfig )
1107
- {
1108
- if ( ! config . useGlobalVersion && cfg . Key . useGlobalVersion && ! anyVersionsUpdatedExceptForGlobal )
1109
- {
1110
- // To minimize noise in version control when adding the globalVersion,
1111
- // unless the config being generated is the globalVersion (written to _generated_local),
1112
- // if no other versions are updated other than the globalVersion,
1113
- // don't change the global version in the existing generated file.
1114
- if ( existingLocalPackageVersion != null )
1115
- {
1116
- configMapping . Add ( new ( cfg . Key . constMappingKey , existingLocalPackageVersion ) ) ;
1117
- }
1118
- }
1119
- else
1120
- {
1121
- configMapping . Add ( new ( cfg . Key . constMappingKey , cfg . Value . ToString ( ) ) ) ;
1122
- }
1123
- }
1124
-
1125
- outputTaskNode . AsObject ( ) . Add ( "_buildConfigMapping" , configMapping ) ;
1126
-
1127
- ensureUpdateModeVerifier ! . WriteAllText ( outputTaskPath , outputTaskNode . ToJsonString ( jso ) , suppressValidationErrorIfTargetPathDoesntExist : false ) ;
1128
- }
1129
-
1130
1090
/// <summary>
1131
- /// This uses the same major.minor.patch for all build configuration tasks, but the "build" suffix of semver is different, and directly corresponds to the name.
1132
- /// We no longer populate the '_buildConfigMapping' property of the task.json, since server won't expect this property to be set.
1091
+ /// Writes task.json with version information and build config mapping.
1092
+ /// When useSemverBuildConfig is true, uses the same major.minor.patch for all build configuration tasks,
1093
+ /// but the "build" suffix of semver is different and directly corresponds to the config name.
1133
1094
/// </summary>
1134
- /// <param name="taskPath"></param>
1135
- /// <param name="taskState"></param>
1136
- /// <param name="defaultConfig"></param>
1137
- /// <param name="config"></param>
1138
- /// <param name="fileName"></param>
1139
- /// <param name="existingLocalPackageVersion"></param>
1140
- private static void WriteTaskJsonWithSemverConfig ( string taskPath ,
1141
- TaskStateStruct taskState ,
1142
- Config . ConfigRecord defaultConfig ,
1143
- Config . ConfigRecord config ,
1144
- string fileName ,
1145
- string ? existingLocalPackageVersion )
1095
+ private static void WriteTaskJson ( string taskPath , TaskStateStruct taskState , Config . ConfigRecord config , string fileName , string ? existingLocalPackageVersion , bool useSemverBuildConfig = false , Config . ConfigRecord ? defaultConfig = null )
1146
1096
{
1147
1097
string outputTaskPath = Path . Combine ( taskPath , fileName ) ;
1148
1098
JsonNode outputTaskNode = JsonNode . Parse ( ensureUpdateModeVerifier ! . FileReadAllText ( outputTaskPath ) ) ! ;
@@ -1151,7 +1101,8 @@ private static void WriteTaskJsonWithSemverConfig(string taskPath,
1151
1101
outputTaskNode [ "version" ] ! [ "Minor" ] = taskState . configTaskVersionMapping [ config ] . Minor ;
1152
1102
outputTaskNode [ "version" ] ! [ "Patch" ] = taskState . configTaskVersionMapping [ config ] . Patch ;
1153
1103
1154
- if ( defaultConfig != config )
1104
+ // Add semver build suffix if using semver config and not the default config
1105
+ if ( useSemverBuildConfig && defaultConfig != null && defaultConfig != config )
1155
1106
{
1156
1107
outputTaskNode [ "version" ] ! [ "Build" ] = config . constMappingKey ;
1157
1108
}
@@ -1167,6 +1118,10 @@ private static void WriteTaskJsonWithSemverConfig(string taskPath,
1167
1118
{
1168
1119
if ( ! config . useGlobalVersion && cfg . Key . useGlobalVersion && ! anyVersionsUpdatedExceptForGlobal )
1169
1120
{
1121
+ // To minimize noise in version control when adding the globalVersion,
1122
+ // unless the config being generated is the globalVersion (written to _generated_local),
1123
+ // if no other versions are updated other than the globalVersion,
1124
+ // don't change the global version in the existing generated file.
1170
1125
if ( existingLocalPackageVersion != null )
1171
1126
{
1172
1127
configMapping . Add ( new ( cfg . Key . constMappingKey , existingLocalPackageVersion ) ) ;
@@ -1400,7 +1355,6 @@ private static void UpdateVersionsForTask(string task, TaskStateStruct taskState
1400
1355
string currentDir = Environment . CurrentDirectory ;
1401
1356
string gitRootPath = GetTasksRootPath ( currentDir ) ;
1402
1357
string taskTargetPath = Path . Combine ( gitRootPath , "Tasks" , task ) ;
1403
-
1404
1358
if ( ! Directory . Exists ( taskTargetPath ) )
1405
1359
{
1406
1360
throw new Exception ( $ "expected { taskTargetPath } to exist!") ;
@@ -1449,7 +1403,6 @@ private static void UpdateVersionsForTask(string task, TaskStateStruct taskState
1449
1403
{
1450
1404
throw new Exception ( $ "Multiple configs for task being merged. This is not supported. task={ task } mergingConfig.name={ mergingConfig . name } ") ;
1451
1405
}
1452
-
1453
1406
// versionMap contains a version that needs to be merged to base
1454
1407
allConfigsMappedAndValid = false ;
1455
1408
mergingConfig = config ;
@@ -1568,7 +1521,6 @@ private static void UpdateVersionsForTask(string task, TaskStateStruct taskState
1568
1521
else
1569
1522
{
1570
1523
TaskVersion targetVersion ;
1571
-
1572
1524
do
1573
1525
{
1574
1526
targetVersion = baseVersion . CloneWithPatch ( baseVersion . Patch + offset ) ;
0 commit comments