Skip to content

Commit 8f6aad5

Browse files
committed
Improving Docker integration, nuget.config generation.
1 parent 237b4c4 commit 8f6aad5

File tree

7 files changed

+59
-11
lines changed

7 files changed

+59
-11
lines changed

.idea/.idea.PostSharp.Engineering/.idea/copilot.data.migration.ask.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.PostSharp.Engineering/.idea/copilot.data.migration.ask2agent.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PostSharp.Engineering.BuildTools/Build/Model/Product.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ public bool PrepareVersionsFile(
12091209
}
12101210

12111211
// Generate nuget.config.
1212-
if ( this.GenerateNuGetConfig && !TryGenerateNuGetConfig( context, dependenciesOverrideFile, settings ) )
1212+
if ( !this.TryGenerateNuGetConfig( context, dependenciesOverrideFile, settings.BuildConfiguration ) )
12131213
{
12141214
return false;
12151215
}
@@ -1390,15 +1390,19 @@ private bool TryComputeVersion(
13901390
return true;
13911391
}
13921392

1393-
private static bool TryGenerateNuGetConfig( BuildContext context, DependenciesOverrideFile dependenciesOverrideFile, BuildSettings buildSettings )
1393+
internal bool TryGenerateNuGetConfig( BuildContext context, DependenciesOverrideFile dependenciesOverrideFile, BuildConfiguration configuration )
13941394
{
1395+
if ( !this.GenerateNuGetConfig )
1396+
{
1397+
return true;
1398+
}
1399+
13951400
// Fetch to resolve the VersionFile properties.
13961401
if ( !dependenciesOverrideFile.Fetch( context ) )
13971402
{
13981403
return false;
13991404
}
14001405

1401-
var product = context.Product;
14021406
var baseFilePath = Path.Combine( context.RepoDirectory, "nuget.base.config" );
14031407
var targetFilePath = Path.Combine( context.RepoDirectory, "nuget.config" );
14041408

@@ -1438,9 +1442,9 @@ private static bool TryGenerateNuGetConfig( BuildContext context, DependenciesOv
14381442
// Add the current artifact directory.
14391443
var artifactDirectory = Path.Combine(
14401444
context.RepoDirectory,
1441-
product.PrivateArtifactsDirectory.ToString( new BuildInfo( null, buildSettings.BuildConfiguration, product, null ) ) );
1445+
this.PrivateArtifactsDirectory.ToString( new BuildInfo( null, configuration, this, null ) ) );
14421446

1443-
AddDirectory( product.ProductName, artifactDirectory, product.DependencyDefinition.PackagePatterns );
1447+
AddDirectory( this.ProductName, artifactDirectory, this.DependencyDefinition.PackagePatterns );
14441448

14451449
// Add dependencies.
14461450
foreach ( var dependencySource in dependenciesOverrideFile.Dependencies )
@@ -1457,8 +1461,8 @@ private static bool TryGenerateNuGetConfig( BuildContext context, DependenciesOv
14571461
continue;
14581462
}
14591463

1460-
var dependencyDefinition = product.GetDependencyDefinition( dependencySource.Key );
1461-
var parametrizedDependency = product.ParametrizedDependencies.Single( d => d.Name == dependencySource.Key );
1464+
var dependencyDefinition = this.GetDependencyDefinition( dependencySource.Key );
1465+
var parametrizedDependency = this.ParametrizedDependencies.Single( d => d.Name == dependencySource.Key );
14621466
var dependencyDirectory = Path.GetDirectoryName( dependencySource.Value.VersionFile )!;
14631467

14641468
if ( dependencySource.Value.SourceKind == DependencySourceKind.Local )
@@ -1468,7 +1472,7 @@ private static bool TryGenerateNuGetConfig( BuildContext context, DependenciesOv
14681472
dependencyDefinition.PrivateArtifactsDirectory.ToString(
14691473
new BuildInfo(
14701474
null,
1471-
parametrizedDependency.ConfigurationMapping[buildSettings.BuildConfiguration],
1475+
parametrizedDependency.ConfigurationMapping[configuration],
14721476
dependencyDefinition,
14731477
null ) ) );
14741478
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ protected override bool ExecuteCore( BuildContext context, T settings )
113113

114114
// Writing the configurations neutral file.
115115
context.Product.PrepareConfigurationNeutralVersionsFile( context, settings, configuration );
116+
117+
// Generate nuget.config.
118+
if ( !context.Product.TryGenerateNuGetConfig( context, dependenciesOverrideFile, configuration ) )
119+
{
120+
return false;
121+
}
116122

117123
context.Console.WriteLine();
118124

src/PostSharp.Engineering.BuildTools/Docker/ContainerRequirements.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
22

3+
using JetBrains.Annotations;
34
using PostSharp.Engineering.BuildTools.Build;
45
using PostSharp.Engineering.BuildTools.ContinuousIntegration.Model;
56
using System;
@@ -9,6 +10,7 @@
910

1011
namespace PostSharp.Engineering.BuildTools.Docker;
1112

13+
[PublicAPI]
1214
public record ContainerRequirements : BuildAgentRequirements
1315
{
1416
public ContainerRequirements( ContainerHostKind hostKind ) : base( new BuildAgentRequirement( "env.BuildAgentType", GetBuildAgentType( hostKind ) ) ) { }

src/PostSharp.Engineering.BuildTools/Docker/DotNetComponent.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@ public class DotNetComponent : ContainerComponent
1111
{
1212
public string Version { get; }
1313

14+
public Version? ParsedVersion
15+
{
16+
get;
17+
18+
}
19+
1420
public DotNetComponentKind DotNetComponentKind { get; }
1521

1622
public DotNetComponent( string version, DotNetComponentKind dotNetComponentKind )
1723
{
1824
this.Version = version;
1925
this.DotNetComponentKind = dotNetComponentKind;
26+
27+
var v = this.Version.Split( "-" )[0];
28+
29+
if ( System.Version.TryParse( v, out var parsedVersion ) )
30+
{
31+
this.ParsedVersion = parsedVersion;
32+
}
2033
}
2134

2235
public override string Name => $"Install .NET {this.DotNetComponentKind} {this.Version}";
@@ -59,7 +72,6 @@ public override void WriteDockerfile( StreamWriter writer )
5972

6073
public override string ToString() => $"{this.Kind} {this.DotNetComponentKind} {this.Version}";
6174

62-
6375
public override int CompareTo( ContainerComponent? other )
6476
{
6577
var compareBase = base.CompareTo( other );
@@ -71,6 +83,18 @@ public override int CompareTo( ContainerComponent? other )
7183

7284
var otherDotNetComponent = (DotNetComponent) other!;
7385

74-
return string.Compare( this.Version, otherDotNetComponent.Version, StringComparison.Ordinal );
86+
// Compare the version number.
87+
if ( this.ParsedVersion != null && otherDotNetComponent.ParsedVersion != null )
88+
{
89+
var compareParsedVersion = this.ParsedVersion.CompareTo( otherDotNetComponent.ParsedVersion );
90+
91+
if ( compareParsedVersion != 0 )
92+
{
93+
return compareParsedVersion;
94+
}
95+
}
96+
97+
// Compare the string part of the version number..
98+
return -string.Compare( this.Version, otherDotNetComponent.Version, StringComparison.Ordinal );
7599
}
76100
}

src/PostSharp.Engineering.BuildTools/Utilities/EmbeddedResourceHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void ExtractResource(
5252
else
5353

5454
{
55-
context.Console.WriteMessage( $"File '{targetPath}' is already correct." );
55+
context.Console.WriteMessage( $"File '{targetPath}' is up to date." );
5656
}
5757
}
5858
}

0 commit comments

Comments
 (0)