Skip to content

Commit 12c91a5

Browse files
committed
update-eng displays warning if no update was done.
1 parent 19aac2c commit 12c91a5

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/PostSharp.Engineering.BuildTools/Dependencies/UpdateEngineeringCommand.cs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ protected override bool ExecuteCore( BuildContext context, CommonCommandSettings
4141

4242
var product = context.Product;
4343
var console = context.Console;
44+
var madeAnyChange = false;
4445

4546
if ( !product.GenerateNuGetConfig )
4647
{
@@ -77,13 +78,18 @@ protected override bool ExecuteCore( BuildContext context, CommonCommandSettings
7778

7879
if ( globalJsonProperty != null )
7980
{
80-
console.WriteMessage( $"Writing '{globalJsonPath}'." );
81+
if ( globalJsonProperty.Value<string>()?.Trim() != lastVersion )
82+
{
83+
madeAnyChange = true;
84+
85+
console.WriteMessage( $"Writing '{globalJsonPath}'." );
8186

82-
globalJsonProperty.Replace( new JValue( lastVersion ) );
83-
using var writer = new StreamWriter( globalJsonPath );
84-
var jsonTextWriter = new JsonTextWriter( writer ) { Formatting = Formatting.Indented };
87+
globalJsonProperty.Replace( new JValue( lastVersion ) );
88+
using var writer = new StreamWriter( globalJsonPath );
89+
var jsonTextWriter = new JsonTextWriter( writer ) { Formatting = Formatting.Indented };
8590

86-
globalJson.WriteTo( jsonTextWriter );
91+
globalJson.WriteTo( jsonTextWriter );
92+
}
8793
}
8894
else
8995
{
@@ -103,26 +109,35 @@ protected override bool ExecuteCore( BuildContext context, CommonCommandSettings
103109
? centralPackageManagementVersionsPath
104110
: Path.Combine( context.RepoDirectory, context.Product.VersionsFilePath );
105111

106-
console.WriteMessage( $"Writing '{versionsFilePath}'." );
107112
var versionsFile = XDocument.Load( versionsFilePath, LoadOptions.PreserveWhitespace );
108113
var versionProperties = versionsFile.XPathSelectElements( "/Project/PropertyGroup/PostSharpEngineeringVersion" ).ToList();
109114

110115
if ( versionProperties.Count == 1 )
111116
{
112-
versionProperties[0].Value = lastVersion;
117+
if ( versionProperties[0].Value != lastVersion )
118+
{
119+
console.WriteMessage( $"Writing '{versionsFilePath}'." );
120+
versionProperties[0].Value = lastVersion;
121+
versionsFile.Save( versionsFilePath );
122+
}
113123
}
114124
else
115125
{
116126
console.WriteWarning(
117127
$"File '{versionsFilePath}' not updated because there are {versionProperties.Count} properties named PostSharpEngineeringVersion." );
118128
}
119129

120-
versionsFile.Save( versionsFilePath );
121-
122-
console.WriteSuccess( "Engineering successfully updated." );
130+
if ( madeAnyChange )
131+
{
132+
console.WriteSuccess( $"PostSharp.Engineering successfully updated to version {lastVersion}." );
123133

124-
// Generate scripts.
125-
console.WriteWarning( "Now run `./Build.ps1 generate-scripts` with this new version." );
134+
// Generate scripts.
135+
console.WriteWarning( "Now run `./Build.ps1 generate-scripts` with this new version." );
136+
}
137+
else
138+
{
139+
console.WriteWarning( $"PostSharp.Engineering was already of the latest version ({lastVersion})." );
140+
}
126141

127142
return true;
128143
}

0 commit comments

Comments
 (0)