-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#34764 Consolidated public build triggering fixed.
- Loading branch information
Showing
10 changed files
with
124 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 38 additions & 10 deletions
48
src/PostSharp.Engineering.BuildTools/Build/Triggers/SourceBuildTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,55 @@ | ||
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. | ||
|
||
using JetBrains.Annotations; | ||
using PostSharp.Engineering.BuildTools.Build.Model; | ||
using PostSharp.Engineering.BuildTools.ContinuousIntegration.Model.Arguments; | ||
using System.IO; | ||
|
||
namespace PostSharp.Engineering.BuildTools.Build.Triggers; | ||
|
||
/// <summary> | ||
/// Generates a build trigger that triggers the build when the source code has changed in the default branch. | ||
/// </summary> | ||
[PublicAPI] | ||
public class SourceBuildTrigger : IBuildTrigger | ||
{ | ||
public bool WatchChangesInDependencies { get; set; } = true; | ||
public bool WatchChangesInDependencies { get; init; } = true; | ||
|
||
public string? BranchFilter { get; set; } | ||
public string? BranchFilter { get; init; } | ||
|
||
public TeamCityBuildConfigurationParameterBase[]? Parameters { get; init; } | ||
|
||
public void GenerateTeamcityCode( TextWriter writer, string branchFilter ) | ||
public void GenerateTeamcityCode( TextWriter writer, string? branchFilter = null ) | ||
{ | ||
writer.WriteLine( | ||
$@" vcs {{ | ||
watchChangesInDependencies = {this.WatchChangesInDependencies.ToString().ToLowerInvariant()} | ||
branchFilter = ""{this.BranchFilter ?? branchFilter}"" | ||
// Build will not trigger automatically if the commit message contains comment value. | ||
triggerRules = ""-:comment=<<VERSION_BUMP>>|<<DEPENDENCIES_UPDATED>>:**"" | ||
}}" ); | ||
void WriteIndented( string text ) | ||
{ | ||
writer.Write( " " ); | ||
writer.WriteLine( text ); | ||
} | ||
|
||
writer.WriteLine( " vcs {" ); | ||
|
||
WriteIndented( $"watchChangesInDependencies = {this.WatchChangesInDependencies.ToString().ToLowerInvariant()}" ); | ||
|
||
branchFilter = this.BranchFilter ?? branchFilter ?? "+:<default>"; | ||
WriteIndented( $"branchFilter = \"{branchFilter}\"" ); | ||
|
||
WriteIndented( "// Build will not trigger automatically if the commit message contains comment value." ); | ||
WriteIndented( "triggerRules = \"-:comment=<<VERSION_BUMP>>|<<DEPENDENCIES_UPDATED>>:**\"" ); | ||
|
||
if ( this.Parameters != null ) | ||
{ | ||
WriteIndented( "buildParams {" ); | ||
|
||
foreach ( var parameter in this.Parameters ) | ||
{ | ||
writer.Write( " " ); | ||
writer.WriteLine( parameter.GenerateTeamCityCode() ); | ||
} | ||
|
||
WriteIndented( "}" ); | ||
} | ||
|
||
writer.WriteLine( " }" ); | ||
} | ||
} |
13 changes: 7 additions & 6 deletions
13
...g.BuildTools/ContinuousIntegration/Model/Arguments/TeamCityBuildConfigurationParameter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. | ||
// Copyright (c) SharpCrafters s.r.o.See the LICENSE.md file in the root directory of this repository root for details. | ||
|
||
namespace PostSharp.Engineering.BuildTools.ContinuousIntegration.Model.Arguments; | ||
|
||
public abstract class TeamCityBuildConfigurationParameter | ||
public class TeamCityBuildConfigurationParameter : TeamCityBuildConfigurationParameterBase | ||
{ | ||
public string Name { get; } | ||
public string Value { get; } | ||
|
||
protected TeamCityBuildConfigurationParameter( string name ) | ||
public TeamCityBuildConfigurationParameter( string name, string value ) : base( name ) | ||
{ | ||
this.Name = name; | ||
this.Value = value; | ||
} | ||
|
||
public abstract string GenerateTeamCityCode(); | ||
public override string GenerateTeamCityCode() | ||
=> @$" param(""{this.Name}"", ""{this.Value}"")"; | ||
} |
15 changes: 15 additions & 0 deletions
15
...ildTools/ContinuousIntegration/Model/Arguments/TeamCityBuildConfigurationParameterBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details. | ||
|
||
namespace PostSharp.Engineering.BuildTools.ContinuousIntegration.Model.Arguments; | ||
|
||
public abstract class TeamCityBuildConfigurationParameterBase | ||
{ | ||
public string Name { get; } | ||
|
||
protected TeamCityBuildConfigurationParameterBase( string name ) | ||
{ | ||
this.Name = name; | ||
} | ||
|
||
public abstract string GenerateTeamCityCode(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters