@@ -8,12 +8,13 @@ public class BuildParameters
8
8
public string Target { get ; private set ; }
9
9
public string Configuration { get ; private set ; }
10
10
11
- public bool DisableUnitTests { get ; private set ; }
12
- public bool DisablePublishGem { get ; private set ; }
13
- public bool DisablePublishTfs { get ; private set ; }
14
- public bool DisablePublishNuget { get ; private set ; }
15
- public bool DisablePublishChocolatey { get ; private set ; }
16
- public bool DisablePublishDocker { get ; private set ; }
11
+ public bool EnabledUnitTests { get ; private set ; }
12
+ public bool EnabledPublishGem { get ; private set ; }
13
+ public bool EnabledPublishTfs { get ; private set ; }
14
+ public bool EnabledPublishNuget { get ; private set ; }
15
+ public bool EnabledPublishChocolatey { get ; private set ; }
16
+ public bool EnabledPublishDocker { get ; private set ; }
17
+ public bool EnabledPullRequestPublish { get ; private set ; }
17
18
18
19
public bool IsRunningOnUnix { get ; private set ; }
19
20
public bool IsRunningOnWindows { get ; private set ; }
@@ -28,6 +29,7 @@ public class BuildParameters
28
29
public bool IsMainRepo { get ; private set ; }
29
30
public bool IsMainBranch { get ; private set ; }
30
31
public bool IsTagged { get ; private set ; }
32
+ public bool IsPullRequest { get ; private set ; }
31
33
32
34
public BuildCredentials Credentials { get ; private set ; }
33
35
public BuildVersion Version { get ; private set ; }
@@ -36,8 +38,8 @@ public class BuildParameters
36
38
public BuildArtifacts Artifacts { get ; private set ; }
37
39
public Dictionary < string , DirectoryPath > PackagesBuildMap { get ; private set ; }
38
40
39
- public bool IsStableRelease ( ) => ! IsLocalBuild && IsMainRepo && IsMainBranch && IsTagged ;
40
- public bool IsPreRelease ( ) => ! IsLocalBuild && IsMainRepo && IsMainBranch && ! IsTagged ;
41
+ public bool IsStableRelease ( ) => ! IsLocalBuild && IsMainRepo && IsMainBranch && ! IsPullRequest && IsTagged ;
42
+ public bool IsPreRelease ( ) => ! IsLocalBuild && IsMainRepo && IsMainBranch && ! IsPullRequest && ! IsTagged ;
41
43
42
44
public bool CanPostToGitter => ! string . IsNullOrWhiteSpace ( Credentials . Gitter . Token ) && ! string . IsNullOrWhiteSpace ( Credentials . Gitter . RoomId ) ;
43
45
@@ -55,12 +57,13 @@ public class BuildParameters
55
57
Target = target ,
56
58
Configuration = context . Argument ( "configuration" , "Release" ) ,
57
59
58
- DisableUnitTests = IsDisabled ( context , "DISABLE_UNIT_TESTS" ) ,
59
- DisablePublishGem = IsDisabled ( context , "DISABLE_PUBLISH_GEM" ) ,
60
- DisablePublishTfs = IsDisabled ( context , "DISABLE_PUBLISH_TFS" ) ,
61
- DisablePublishNuget = IsDisabled ( context , "DISABLE_PUBLISH_NUGET" ) ,
62
- DisablePublishChocolatey = IsDisabled ( context , "DISABLE_PUBLISH_CHOCOLATEY" ) ,
63
- DisablePublishDocker = IsDisabled ( context , "DISABLE_PUBLISH_DOCKER" ) ,
60
+ EnabledUnitTests = IsEnabled ( context , "ENABLED_UNIT_TESTS" ) ,
61
+ EnabledPublishGem = IsEnabled ( context , "ENABLED_PUBLISH_GEM" ) ,
62
+ EnabledPublishTfs = IsEnabled ( context , "ENABLED_PUBLISH_TFS" ) ,
63
+ EnabledPublishNuget = IsEnabled ( context , "ENABLED_PUBLISH_NUGET" ) ,
64
+ EnabledPublishChocolatey = IsEnabled ( context , "ENABLED_PUBLISH_CHOCOLATEY" ) ,
65
+ EnabledPublishDocker = IsEnabled ( context , "ENABLED_PUBLISH_DOCKER" ) ,
66
+ EnabledPullRequestPublish = IsEnabled ( context , "ENABLED_PULL_REQUEST_PUBLISH" , false ) ,
64
67
65
68
IsRunningOnUnix = context . IsRunningOnUnix ( ) ,
66
69
IsRunningOnWindows = context . IsRunningOnWindows ( ) ,
@@ -105,9 +108,10 @@ public class BuildParameters
105
108
106
109
Credentials = BuildCredentials . GetCredentials ( context ) ;
107
110
108
- IsMainRepo = IsOnMainRepo ( context ) ;
109
- IsMainBranch = IsOnMainBranch ( context ) ;
110
- IsTagged = IsBuildTagged ( context , gitVersion ) ;
111
+ IsMainRepo = IsOnMainRepo ( context ) ;
112
+ IsMainBranch = IsOnMainBranch ( context ) ;
113
+ IsPullRequest = IsPullRequestBuild ( context ) ;
114
+ IsTagged = IsBuildTagged ( context , gitVersion ) ;
111
115
}
112
116
113
117
private static bool IsOnMainRepo ( ICakeContext context )
@@ -154,6 +158,25 @@ public class BuildParameters
154
158
return ! string . IsNullOrWhiteSpace ( repositoryBranch ) && StringComparer . OrdinalIgnoreCase . Equals ( "master" , repositoryBranch ) ;
155
159
}
156
160
161
+ private static bool IsPullRequestBuild ( ICakeContext context )
162
+ {
163
+ var buildSystem = context . BuildSystem ( ) ;
164
+ if ( buildSystem . IsRunningOnAppVeyor )
165
+ {
166
+ return buildSystem . AppVeyor . Environment . PullRequest . IsPullRequest ;
167
+ }
168
+ if ( buildSystem . IsRunningOnTravisCI )
169
+ {
170
+ return ! string . IsNullOrWhiteSpace ( buildSystem . TravisCI . Environment . Repository . PullRequest )
171
+ && ! string . Equals ( buildSystem . TravisCI . Environment . Repository . PullRequest , false . ToString ( ) , StringComparison . InvariantCultureIgnoreCase ) ;
172
+ }
173
+ else if ( buildSystem . IsRunningOnVSTS )
174
+ {
175
+ return false ; // need a way to check if it is from a PR on azure pipelines
176
+ }
177
+ return false ;
178
+ }
179
+
157
180
private static bool IsBuildTagged ( ICakeContext context , GitVersion gitVersion )
158
181
{
159
182
var gitPath = context . Tools . Resolve ( context . IsRunningOnWindows ( ) ? "git.exe" : "git" ) ;
@@ -162,10 +185,10 @@ public class BuildParameters
162
185
return redirectedOutput . Any ( ) ;
163
186
}
164
187
165
- private static bool IsDisabled ( ICakeContext context , string envVar )
188
+ private static bool IsEnabled ( ICakeContext context , string envVar , bool nullOrEmptyAsEnabled = true )
166
189
{
167
190
var value = context . EnvironmentVariable ( envVar ) ;
168
191
169
- return ! string . IsNullOrWhiteSpace ( value ) && bool . Parse ( value ) ;
192
+ return string . IsNullOrWhiteSpace ( value ) ? nullOrEmptyAsEnabled : bool . Parse ( value ) ;
170
193
}
171
194
}
0 commit comments