Skip to content

Commit e69b7fc

Browse files
committed
Warnings. Bumping improvements.
1 parent 8f4595a commit e69b7fc

File tree

69 files changed

+575
-591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+575
-591
lines changed

src/PostSharp.Engineering.BuildTools/Build/BaseBuildSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public override void Initialize( BuildContext context )
5656
if ( this._specifiedConfiguration != null )
5757
{
5858
this._resolvedConfiguration = this._specifiedConfiguration;
59-
59+
6060
return;
6161
}
6262

src/PostSharp.Engineering.BuildTools/Build/BuildSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected override void AppendSettings( StringBuilder stringBuilder )
4343
{
4444
stringBuilder.Append( "--no-dependencies " );
4545
}
46-
46+
4747
if ( this.NoRestore )
4848
{
4949
stringBuilder.Append( "--no-restore " );
@@ -116,7 +116,7 @@ protected override void AppendSettings( StringBuilder stringBuilder )
116116
[Description( "Executes only the current command, but not the previous command" )]
117117
[CommandOption( "--no-dependencies" )]
118118
public bool NoDependencies { get; set; }
119-
119+
120120
[Description( "Does not restore package before executing the command" )]
121121
[CommandOption( "--no-restore" )]
122122
public bool NoRestore { get; set; }

src/PostSharp.Engineering.BuildTools/Build/Bumping/BumpCommand.cs

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
using PostSharp.Engineering.BuildTools.Build.Helpers;
66
using PostSharp.Engineering.BuildTools.Utilities;
77
using System;
8-
using System.Collections.Generic;
9-
using System.Diagnostics.CodeAnalysis;
10-
using System.IO;
11-
using System.Linq;
128

139
namespace PostSharp.Engineering.BuildTools.Build.Bumping;
1410

@@ -96,11 +92,31 @@ private static bool Execute( BuildContext context, BumpSettings settings )
9692

9793
// Doing a dry run of AutoUpdatedVersionsFile both gets the versions of all dependencies and gets the current version.
9894
// Do not write the AutoUpdatedVersions.props file yet - we will do it after we set our own version.
99-
if ( !AutoUpdatedVersionsFile.TryWrite( context, true, out var hasChangesInDependencies, out var hasChangesInAutoUpdatedVersionsFile, out _, out var currentVersion ) )
95+
if ( !AutoUpdatedVersionsFile.TryWrite(
96+
context,
97+
true,
98+
out var hasChangesInDependencies,
99+
out var hasChangesInAutoUpdatedVersionsFile,
100+
out _,
101+
out var currentVersion ) )
100102
{
101103
return false;
102104
}
103105

106+
// If the currentVersion differs from MainVersion, update it now, irrespective of bumping.
107+
if ( currentVersion != currentMainVersionFile.MainVersion )
108+
{
109+
if ( !currentMainVersionFile.TryWrite( context, currentVersion, null, out currentMainVersionFile ) )
110+
{
111+
return false;
112+
}
113+
114+
if ( !GitIntegrationHelper.TryCommitMainVersion( context ) )
115+
{
116+
return false;
117+
}
118+
}
119+
104120
if ( hasBumpSinceLastDeployment && !settings.OverridePreviousBump )
105121
{
106122
console.WriteWarning( "Version has already been bumped since the last deployment." );
@@ -130,59 +146,56 @@ private static bool Execute( BuildContext context, BumpSettings settings )
130146
}
131147
}
132148
}
133-
134-
return true;
135149
}
136-
137-
if ( !hasChangesInDependencies && !hasChangesSinceLastDeployment )
150+
else if ( !hasChangesInDependencies && !hasChangesSinceLastDeployment )
138151
{
139152
console.WriteWarning( $"There are no changes since the last deployment." );
140-
141-
return true;
142153
}
143-
144-
Version? oldVersion;
145-
146-
if ( product.MainVersionDependency == null )
154+
else
147155
{
148-
// This updates MainVersion.props.
149-
if ( !product.BumpStrategy.TryBumpVersion( product, context, out oldVersion, out _ ) )
156+
Version? oldVersion;
157+
158+
if ( product.MainVersionDependency == null )
150159
{
151-
return false;
160+
// This updates MainVersion.props.
161+
if ( !product.BumpStrategy.TryBumpVersion( product, context, out oldVersion, out _ ) )
162+
{
163+
return false;
164+
}
152165
}
153-
}
154-
else
155-
{
156-
if ( hasChangesSinceLastDeployment && !hasChangesInDependencies )
166+
else
157167
{
158-
const string message =
159-
"There are changes in the current repo but no changes in dependencies. However, the current repo does not have its own versioning.";
160-
161-
if ( settings.Force )
168+
if ( hasChangesSinceLastDeployment && !hasChangesInDependencies )
162169
{
163-
console.WriteImportantMessage( $"{message} This is being ignored using --force." );
170+
const string message =
171+
"There are changes in the current repo but no changes in dependencies. However, the current repo does not have its own versioning.";
164172

165-
return true;
173+
if ( settings.Force )
174+
{
175+
console.WriteImportantMessage( $"{message} This is being ignored using --force." );
176+
177+
return true;
178+
}
179+
180+
console.WriteError( $"{message} Do a fake change in a parent repo or use --force." );
181+
182+
return false;
166183
}
167184

168-
console.WriteError( $"{message} Do a fake change in a parent repo or use --force." );
185+
oldVersion = new Version( currentVersion );
186+
}
169187

188+
// Now save AutoUpdatedVersions.props.
189+
if ( !AutoUpdatedVersionsFile.TryWrite( context, false, out _, out _, out _, out var newVersion ) )
190+
{
170191
return false;
171192
}
172193

173-
oldVersion = new Version( currentVersion );
174-
}
175-
176-
// Now save AutoUpdatedVersions.props.
177-
if ( !AutoUpdatedVersionsFile.TryWrite( context, false, out _, out _, out _, out var newVersion ) )
178-
{
179-
return false;
180-
}
181-
182-
// Commit the version bump.
183-
if ( !GitIntegrationHelper.TryCommitVersionBump( context, oldVersion, new Version( newVersion ) ) )
184-
{
185-
return false;
194+
// Commit the version bump.
195+
if ( !GitIntegrationHelper.TryCommitVersionFilesWithBumpMessage( context, oldVersion, new Version( newVersion ) ) )
196+
{
197+
return false;
198+
}
186199
}
187200

188201
// If we are running in TeamCity, push.

src/PostSharp.Engineering.BuildTools/Build/Bumping/DefaultBumpStrategy.cs

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
using PostSharp.Engineering.BuildTools.Build.Model;
55
using System;
66
using System.Diagnostics.CodeAnalysis;
7-
using System.IO;
8-
using System.Text;
9-
using System.Xml;
10-
using System.Xml.Linq;
117

128
namespace PostSharp.Engineering.BuildTools.Build.Bumping;
139

@@ -19,7 +15,7 @@ public bool TryBumpVersion(
1915
[NotNullWhen( true )] out Version? oldVersion,
2016
[NotNullWhen( true )] out Version? newVersion )
2117
{
22-
if ( !MainVersionFile.TryRead( context, out var currentMainVersionFile, out var mainVersionFile ) )
18+
if ( !MainVersionFile.TryRead( context, out var currentMainVersionFile, out _ ) )
2319
{
2420
oldVersion = null;
2521
newVersion = null;
@@ -36,7 +32,7 @@ public bool TryBumpVersion(
3632
oldVersion.Build + 1 );
3733

3834
// Save the MainVersion.props with new version.
39-
if ( !TrySaveMainVersion( context, mainVersionFile, newVersion ) )
35+
if ( !currentMainVersionFile.TryWrite( context, newVersion, null, out _ ) )
4036
{
4137
return false;
4238
}
@@ -45,37 +41,4 @@ public bool TryBumpVersion(
4541

4642
return true;
4743
}
48-
49-
private static bool TrySaveMainVersion(
50-
BuildContext context,
51-
string mainVersionFile,
52-
Version version )
53-
{
54-
if ( !File.Exists( mainVersionFile ) )
55-
{
56-
context.Console.WriteError( $"Could not save '{mainVersionFile}': the file does not exist." );
57-
58-
return false;
59-
}
60-
61-
var document = XDocument.Load( mainVersionFile );
62-
var project = document.Root;
63-
var properties = project!.Element( "PropertyGroup" );
64-
var mainVersionElement = properties!.Element( "MainVersion" );
65-
66-
mainVersionElement!.Value = version.ToString();
67-
68-
// Using settings to keep the indentation as well as encoding identical to original MainVersion.props.
69-
var xmlWriterSettings =
70-
new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true, IndentChars = " ", Encoding = new UTF8Encoding( false ) };
71-
72-
using ( var xmlWriter = XmlWriter.Create( mainVersionFile, xmlWriterSettings ) )
73-
{
74-
document.Save( xmlWriter );
75-
}
76-
77-
context.Console.WriteMessage( $"Writing '{mainVersionFile}'." );
78-
79-
return true;
80-
}
8144
}

src/PostSharp.Engineering.BuildTools/Build/Bumping/PatchVersionBumpStrategy.cs

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
using PostSharp.Engineering.BuildTools.Build.Model;
55
using System;
66
using System.Diagnostics.CodeAnalysis;
7-
using System.Globalization;
8-
using System.IO;
9-
using System.Text;
10-
using System.Xml;
11-
using System.Xml.Linq;
127

138
namespace PostSharp.Engineering.BuildTools.Build.Bumping;
149

@@ -20,7 +15,7 @@ public bool TryBumpVersion(
2015
[NotNullWhen( true )] out Version? oldVersion,
2116
[NotNullWhen( true )] out Version? newVersion )
2217
{
23-
if ( !MainVersionFile.TryRead( context, out var currentMainVersionFile, out var mainVersionFile ) )
18+
if ( !MainVersionFile.TryRead( context, out var currentMainVersionFile, out _ ) )
2419
{
2520
oldVersion = null;
2621
newVersion = null;
@@ -44,15 +39,7 @@ public bool TryBumpVersion(
4439
var newOurPatchVersion = oldOurPatchVersion + 1;
4540

4641
// Save the MainVersion.props with new version.
47-
if ( !TrySavePatchedMainVersion( context, mainVersionFile, newOurPatchVersion.Value ) )
48-
{
49-
oldVersion = null;
50-
newVersion = null;
51-
52-
return false;
53-
}
54-
55-
if ( !MainVersionFile.TryRead( context, out var updatedMainVersionFile ) )
42+
if ( !currentMainVersionFile.TryWrite( context, currentMainVersionFile.MainVersion, newOurPatchVersion, out var updatedMainVersionFile ) )
5643
{
5744
oldVersion = null;
5845
newVersion = null;
@@ -62,48 +49,8 @@ public bool TryBumpVersion(
6249

6350
newVersion = new Version( updatedMainVersionFile.MainVersion );
6451

65-
context.Console.WriteSuccess( $"Bumping the '{context.Product.ProductName}' version from '{oldVersion}' to '{newVersion}' was successful." );
66-
67-
return true;
68-
}
69-
70-
private static bool TrySavePatchedMainVersion(
71-
BuildContext context,
72-
string mainVersionFile,
73-
int ourPatchVersion )
74-
{
75-
if ( !File.Exists( mainVersionFile ) )
76-
{
77-
context.Console.WriteError( $"Could not save '{mainVersionFile}': the file does not exist." );
78-
79-
return false;
80-
}
81-
82-
var document = XDocument.Load( mainVersionFile );
83-
var project = document.Root;
84-
var properties = project!.Element( "PropertyGroup" );
85-
var ourPatchVersionElement = properties!.Element( "OurPatchVersion" );
86-
87-
// Fail on missing <OurPatchVersion> property or replace its value.
88-
if ( ourPatchVersionElement == null )
89-
{
90-
context.Console.WriteError( $"OurPatchVersion property is missing in '{mainVersionFile}'" );
91-
92-
return false;
93-
}
94-
95-
ourPatchVersionElement.Value = ourPatchVersion.ToString( CultureInfo.InvariantCulture );
96-
97-
// Using settings to keep the indentation as well as encoding identical to original MainVersion.props.
98-
var xmlWriterSettings =
99-
new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true, IndentChars = " ", Encoding = new UTF8Encoding( false ) };
100-
101-
using ( var xmlWriter = XmlWriter.Create( mainVersionFile, xmlWriterSettings ) )
102-
{
103-
document.Save( xmlWriter );
104-
}
105-
106-
context.Console.WriteMessage( $"Writing '{mainVersionFile}'." );
52+
context.Console.WriteSuccess(
53+
$"Bumping the '{context.Product.ProductName}' version from '{oldVersion}' to '{updatedMainVersionFile.MainVersion}' was successful." );
10754

10855
return true;
10956
}

src/PostSharp.Engineering.BuildTools/Build/Files/ArtifactManifestFile.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public static bool TryWrite(
5252
}
5353
else
5454
{
55-
var packageSuffix = string.IsNullOrEmpty( version.VersionSuffix ) ? "" : "-" + version.VersionSuffix;
56-
5755
manifestFileContent += $@"
5856
<{product.ProductNameWithoutDot}Version>{version.PackageVersion}</{product.ProductNameWithoutDot}Version>
5957
<{product.ProductNameWithoutDot}PreviewVersion>{version.PackagePreviewVersion}</{product.ProductNameWithoutDot}PreviewVersion>

0 commit comments

Comments
 (0)