Skip to content

Commit a868be2

Browse files
committed
Expose Docker and Teamcity flags to BuildContext.
1 parent ea01cce commit a868be2

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

src/PostSharp.Engineering.BuildTools/BaseCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public sealed override int Execute( CommandContext context, T settings )
3030
Debugger.Launch();
3131
}
3232

33-
if ( !BuildContext.TryCreate( context, out var buildContext ) )
33+
if ( !BuildContext.TryCreate( context, settings, out var buildContext ) )
3434
{
3535
return 1;
3636
}

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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.Model;
5+
using PostSharp.Engineering.BuildTools.ContinuousIntegration;
46
using PostSharp.Engineering.BuildTools.Utilities;
57
using Spectre.Console.Cli;
68
using System;
@@ -71,21 +73,24 @@ private BuildContext(
7173
BaseCommandData commandData,
7274
string branch,
7375
CommandContext commandContext,
74-
bool useProjectDirectoryAsWorkingDirectory )
76+
bool useProjectDirectoryAsWorkingDirectory,
77+
CommonCommandSettings settings )
7578
{
7679
this.Console = console;
7780
this.RepoDirectory = repoDirectory;
7881
this.CommandData = commandData;
7982
this.Branch = branch;
8083
this.CommandContext = commandContext;
8184
this.UseProjectDirectoryAsWorkingDirectory = useProjectDirectoryAsWorkingDirectory;
85+
this.Settings = settings;
8286
}
8387

8488
/// <summary>
8589
/// Tries to create a <see cref="BuildContext"/> from a <see cref="Spectre.Console.Cli.CommandContext"/>.
8690
/// </summary>
8791
public static bool TryCreate(
8892
CommandContext commandContext,
93+
CommonCommandSettings settings,
8994
[NotNullWhen( true )] out BuildContext? buildContext )
9095
{
9196
buildContext = null;
@@ -110,7 +115,8 @@ public static bool TryCreate(
110115
(BaseCommandData) commandContext.Data!,
111116
currentBranch,
112117
commandContext,
113-
useProjectDirectoryAsWorkingDirectory: false );
118+
useProjectDirectoryAsWorkingDirectory: false,
119+
settings );
114120

115121
return true;
116122
}
@@ -147,9 +153,19 @@ public static bool TryCreate(
147153
}
148154

149155
public BuildContext WithConsoleHelper( ConsoleHelper consoleHelper )
150-
=> new( consoleHelper, this.RepoDirectory, this.CommandData, this.Branch, this.CommandContext, this.UseProjectDirectoryAsWorkingDirectory );
156+
=> new( consoleHelper, this.RepoDirectory, this.CommandData, this.Branch, this.CommandContext, this.UseProjectDirectoryAsWorkingDirectory, this.Settings );
151157

152158
public BuildContext WithUseProjectDirectoryAsWorkingDirectory( bool useProjectDirectoryAsWorkingDirectory )
153-
=> new( this.Console, this.RepoDirectory, this.CommandData, this.Branch, this.CommandContext, useProjectDirectoryAsWorkingDirectory );
159+
=> new( this.Console, this.RepoDirectory, this.CommandData, this.Branch, this.CommandContext, useProjectDirectoryAsWorkingDirectory, this.Settings );
160+
161+
[PublicAPI]
162+
#pragma warning disable CA1822
163+
public bool IsRunningUnderContainer => DockerHelper.IsDockerBuild();
164+
#pragma warning restore CA1822
165+
166+
public bool IsContinuousIntegrationBuild => TeamCityHelper.IsTeamCityBuild( this.Settings );
167+
168+
[PublicAPI]
169+
public CommonCommandSettings Settings { get; }
154170
}
155171
}

src/PostSharp.Engineering.BuildTools/ContinuousIntegration/TeamCityHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static class TeamCityHelper
2929
public const string TeamCityApiRunningBuildsPath = "/app/rest/builds?locator=state:running";
3030
public const string TeamCityApiFinishedBuildsPath = "/app/rest/builds?locator=state:finished";
3131

32-
public static bool IsTeamCityBuild( CommonCommandSettings? settings = null )
32+
public static bool IsTeamCityBuild( CommonCommandSettings? settings )
3333
=> settings?.SimulateContinuousIntegration == true
3434
|| Environment.GetEnvironmentVariable( EnvironmentVariableNames.IsTeamCityAgent )?.ToLowerInvariant() is "true" or "1";
3535

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public override int CompareTo( ContainerComponent? other )
9494
}
9595
}
9696

97-
// Compare the string part of the version number..
97+
// Compare the string part of the version number.
9898
return -string.Compare( this.Version, otherDotNetComponent.Version, StringComparison.Ordinal );
9999
}
100100
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public static bool Login( ConsoleHelper console, bool dry = false )
5151

5252
if ( string.IsNullOrEmpty( azureTenantId ) || string.IsNullOrEmpty( azureClientId ) || string.IsNullOrEmpty( azureClientSecret ) )
5353
{
54-
console.WriteWarning( $"Cannot do `az login`: The environment variables {EnvironmentVariableNames.AzureTenantId}, {EnvironmentVariableNames.AzureClientId}, {EnvironmentVariableNames.AzureClientSecret} must be defined." );
54+
console.WriteWarning(
55+
$"Cannot do `az login`: The environment variables {EnvironmentVariableNames.AzureTenantId}, {EnvironmentVariableNames.AzureClientId}, {EnvironmentVariableNames.AzureClientSecret} must be defined." );
5556

5657
return false;
5758
}
@@ -70,11 +71,9 @@ public static bool Login( ConsoleHelper console, bool dry = false )
7071

7172
return true;
7273
}
73-
74-
azArgs = $"login --identity --username {identityUserName}";
75-
}
7674

77-
75+
azArgs = $"login --identity --username {identityUserName}";
76+
}
7877

7978
if ( !TryFormatCmdArgs( console, azArgs, out var cmdArgs ) )
8079
{

0 commit comments

Comments
 (0)