Skip to content

Commit 09411a2

Browse files
committed
Moved all EnvironmentVariableNames to their own class.
1 parent 9b33ced commit 09411a2

File tree

17 files changed

+93
-65
lines changed

17 files changed

+93
-65
lines changed

src/PostSharp.Engineering.BuildTools/BillOfMaterials/LicenceNoticeDownloader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static async Task AppendLicenseAndNoticeFilesAsync(
2828
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli
2929
};
3030

31-
var gitHubToken = Environment.GetEnvironmentVariable( "GITHUB_TOKEN" );
31+
var gitHubToken = Environment.GetEnvironmentVariable( EnvironmentVariableNames.GitHubToken );
3232

3333
if ( string.IsNullOrEmpty( gitHubToken ) )
3434
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public string GetWorkingDirectory( string projectOrSolution )
5050
/// Gets a value indicating whether the current device is a guest device, as opposed to a device owned and configured by PostSharp.
5151
/// The main difference is that guest devices use feed packages while company devices use TeamCity artefacts.
5252
/// </summary>
53-
public static bool IsGuestDevice => !bool.TryParse( Environment.GetEnvironmentVariable( "IS_POSTSHARP_OWNED" ), out var value ) || !value;
53+
public static bool IsGuestDevice => !bool.TryParse( Environment.GetEnvironmentVariable( EnvironmentVariableNames.IsPostSharpOwned ), out var value ) || !value;
5454

5555
/// <summary>
5656
/// Gets the full path of the current manifest file (i.e. the file called <c>My.Product.version.props</c>)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public int? SolutionId
177177

178178
[Description( "Overrides the user name." )]
179179
[CommandOption( "--user" )]
180-
public string UserName { get; set; } = Environment.GetEnvironmentVariable( "ENG_USERNAME" ) ?? Environment.UserName;
180+
public string UserName { get; set; } = Environment.GetEnvironmentVariable( EnvironmentVariableNames.EngUserName ) ?? Environment.UserName;
181181

182182
public BuildSettings WithIncludeTests( bool value )
183183
{

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ public BuildAgentRequirements ResolvedBuildAgentRequirements
134134

135135
public ConfigurationSpecific<BuildConfigurationInfo> Configurations { get; init; } = DefaultConfigurations;
136136

137-
public TimeSpan BuildTimeOutThreshold { get; init; } = TimeSpan.FromMinutes( 5 );
137+
public TimeSpan BuildTimeOutThreshold { get; init; } = TimeSpan.FromMinutes( 60 );
138138

139-
public TimeSpan DeploymentTimeOutThreshold { get; init; } = TimeSpan.FromMinutes( 5 );
139+
public TimeSpan DeploymentTimeOutThreshold { get; init; } = TimeSpan.FromMinutes( 30 );
140140

141-
public TimeSpan SwapTimeOutThreshold { get; init; } = TimeSpan.FromMinutes( 5 );
141+
public TimeSpan SwapTimeOutThreshold { get; init; } = TimeSpan.FromMinutes( 15 );
142142

143-
public TimeSpan VersionBumpTimeOutThreshold { get; init; } = TimeSpan.FromMinutes( 5 );
143+
public TimeSpan VersionBumpTimeOutThreshold { get; init; } = TimeSpan.FromMinutes( 15 );
144144

145-
public TimeSpan DownstreamMergeTimeOutThreshold { get; init; } = TimeSpan.FromMinutes( 5 );
145+
public TimeSpan DownstreamMergeTimeOutThreshold { get; init; } = TimeSpan.FromMinutes( 15 );
146146

147147
public static ImmutableArray<Publisher> DefaultPublicPublishers { get; }
148148
=
@@ -488,7 +488,7 @@ void CreateEmptyPublicDirectory()
488488
{
489489
context.Console.WriteHeading( "Signing artifacts" );
490490

491-
var signToolSecret = Environment.GetEnvironmentVariable( "SIGNSERVER_SECRET" );
491+
var signToolSecret = Environment.GetEnvironmentVariable( EnvironmentVariableNames.SignServerSecret );
492492

493493
if ( signToolSecret == null )
494494
{

src/PostSharp.Engineering.BuildTools/Build/Publishers/NugetPublisher.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ public override SuccessCode PublishFile(
5353
return SuccessCode.Fatal;
5454
}
5555

56-
const string azEndpointsEnvironmentVariableName = "VSS_NUGET_EXTERNAL_FEED_ENDPOINTS";
57-
58-
if ( apiKey == "az" && Environment.GetEnvironmentVariable( azEndpointsEnvironmentVariableName ) == null )
56+
57+
if ( apiKey == "az" && Environment.GetEnvironmentVariable( EnvironmentVariableNames.AzEndpoints ) == null )
5958
{
6059
context.Console.WriteImportantMessage(
61-
$"{azEndpointsEnvironmentVariableName} environment variable not set. If the authorization fails, set this variable or sign in interactively. See https://github.com/microsoft/artifacts-credprovider#use for details." );
60+
$"{EnvironmentVariableNames.AzEndpoints} environment variable not set. If the authorization fails, set this variable or sign in interactively. See https://github.com/microsoft/artifacts-credprovider#use for details." );
6261
}
6362

6463
var exe = "dotnet";

src/PostSharp.Engineering.BuildTools/Build/Publishers/VsixPublisher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override SuccessCode PublishFile(
3333
hasEnvironmentError = true;
3434
}
3535

36-
if ( string.IsNullOrEmpty( Environment.GetEnvironmentVariable( "VS_MARKETPLACE_ACCESS_TOKEN" ) ) )
36+
if ( string.IsNullOrEmpty( Environment.GetEnvironmentVariable( EnvironmentVariableNames.VsMarketplaceAccessToken ) ) )
3737
{
3838
context.Console.WriteError( $"The VS_MARKETPLACE_ACCESS_TOKEN environment variable is not defined." );
3939
hasEnvironmentError = true;

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ public static class AzureDevOpsHelper
1919
{
2020
private static bool TryConnect( ConsoleHelper console, string url, [NotNullWhen( true )] out VssConnection? connection )
2121
{
22-
var user = Environment.GetEnvironmentVariable( "AZURE_DEVOPS_USER" ) ?? "[email protected]";
22+
var user = Environment.GetEnvironmentVariable( EnvironmentVariableNames.AzureDevOpsUser ) ?? "[email protected]";
2323

24-
const string tokenEnvironmentVariableName = "AZURE_DEVOPS_TOKEN";
25-
26-
var token = Environment.GetEnvironmentVariable( tokenEnvironmentVariableName );
24+
25+
var token = Environment.GetEnvironmentVariable( EnvironmentVariableNames.AzureDevOpsToken );
2726

2827
if ( string.IsNullOrEmpty( token ) )
2928
{
30-
console.WriteError( $"The '{tokenEnvironmentVariableName}' environment variable is not defined." );
29+
console.WriteError( $"The '{EnvironmentVariableNames.AzureDevOpsToken}' environment variable is not defined." );
3130
connection = null;
3231

3332
return false;

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ namespace PostSharp.Engineering.BuildTools.ContinuousIntegration;
2020

2121
public static class GitHubHelper
2222
{
23-
private const string _tokenEnvironmentVariableName = "GITHUB_TOKEN";
24-
private const string _reviewerTokenEnvironmentVariableName = "GITHUB_REVIEWER_TOKEN";
2523
private const string _productHeaderName = "PostSharp.Engineering";
2624
private static readonly string _productHeaderVersion = typeof(GitHubHelper).Assembly.GetName().Version!.ToString();
2725

2826
private static bool TryGetToken(
2927
ConsoleHelper console,
3028
[NotNullWhen( true )] out string? token,
31-
string tokenEnvironmentVariableName = _tokenEnvironmentVariableName )
29+
string tokenEnvironmentVariableName = EnvironmentVariableNames.GitHubToken )
3230
{
3331
token = Environment.GetEnvironmentVariable( tokenEnvironmentVariableName );
3432

@@ -49,7 +47,7 @@ private static GitHubClient ConnectRestApi( string token )
4947
private static bool TryConnectRestApi(
5048
ConsoleHelper console,
5149
[NotNullWhen( true )] out GitHubClient? client,
52-
string tokenEnvironmentVariableName = _tokenEnvironmentVariableName )
50+
string tokenEnvironmentVariableName = EnvironmentVariableNames.GitHubToken )
5351
{
5452
if ( !TryGetToken( console, out var token, tokenEnvironmentVariableName ) )
5553
{
@@ -109,7 +107,7 @@ bool TryConnectRestApis( [NotNullWhen( true )] out GitHubClient? c, [NotNullWhen
109107
return false;
110108
}
111109

112-
if ( !TryGetToken( console, out var reviewerToken, _reviewerTokenEnvironmentVariableName ) )
110+
if ( !TryGetToken( console, out var reviewerToken, EnvironmentVariableNames.GitHubReviewerToken ) )
113111
{
114112
return false;
115113
}
@@ -157,7 +155,7 @@ bool TryConnectRestApis( [NotNullWhen( true )] out GitHubClient? c, [NotNullWhen
157155

158156
var pullRequestId = await graphQl.Run( pullRequestQuery );
159157

160-
var authorEmail = Environment.GetEnvironmentVariable( "GITHUB_AUTHOR_EMAIL" ) ?? "[email protected]";
158+
var authorEmail = Environment.GetEnvironmentVariable( EnvironmentVariableNames.GitHubAuthorEmail ) ?? "[email protected]";
161159

162160
var enableAutoMergeMutation = new Mutation()
163161
.EnablePullRequestAutoMerge(

src/PostSharp.Engineering.BuildTools/ContinuousIntegration/Model/BuildSteps/TeamCityPowerShellBuildStep.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ public TeamCityPowerShellBuildStep( string id, string name, string scriptPath, s
2929

3030
public override string GenerateTeamCityCode()
3131
{
32-
var parameters = this.TimeOut != null ? $"param(\"TimeOut\", \"{this.TimeOut.Value.TotalSeconds}\")" : "";
33-
3432
return $@" powerShell {{
3533
name = ""{this.Name}""
3634
id = ""{this.Id}""{(this.WorkingDirectory == null ? "" : $@"
3735
workingDir = ""{this.WorkingDirectory.Replace( Path.DirectorySeparatorChar, '/' )}""")}
38-
{parameters}
3936
scriptMode = file {{
4037
path = ""{this.ScriptPath}""
4138
}}

src/PostSharp.Engineering.BuildTools/ContinuousIntegration/Model/TeamCityBuildConfiguration.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ public void GenerateTeamcityCode( TextWriter writer )
113113
{
114114
var timeOutParameter = new TeamCityTextBuildConfigurationParameterBase(
115115
"TimeOut",
116-
"Time-Out Threshold",
117-
"Seconds after the duration of the last successful build.",
118-
$"{(int) this.BuildTimeOutThreshold.Value.TotalSeconds}" ) { Validation = (@"\d+", "The timeout has to be an integer number.") };
116+
"Time-Out",
117+
"Timeout, in minutes.",
118+
$"{(int) this.BuildTimeOutThreshold.Value.TotalMinutes}" ) { Validation = (@"\d+", "The timeout has to be an integer number.") };
119119

120120
buildParameters.Add( timeOutParameter );
121121
}
@@ -185,19 +185,11 @@ public void GenerateTeamcityCode( TextWriter writer )
185185
if ( this.BuildTimeOutThreshold.HasValue )
186186
{
187187
writer.WriteLine(
188-
@$"
189-
failureConditions {{
190-
failOnMetricChange {{
191-
metric = BuildFailureOnMetric.MetricType.BUILD_DURATION
192-
units = BuildFailureOnMetric.MetricUnit.DEFAULT_UNIT
193-
comparison = BuildFailureOnMetric.MetricComparison.MORE
194-
compareTo = build {{
195-
buildRule = lastSuccessful()
196-
}}
197-
stopBuildOnFailure = true
198-
param(""metricThreshold"", ""%TimeOut%"")
199-
}}
200-
}}" );
188+
$$"""
189+
failureConditions {
190+
executionTimeoutMin = {{(int) this.BuildTimeOutThreshold.Value.TotalMinutes}}
191+
}
192+
""" );
201193
}
202194

203195
if ( !this.IsComposite && this.BuildAgentRequirements != null )

0 commit comments

Comments
 (0)