1
- #tool "nuget:?package=GitVersion.CommandLine"
2
- #addin "Cake.FileHelpers"
1
+ #tool "nuget:?package=GitVersion.CommandLine&version=5.1.3"
2
+ #addin "Cake.FileHelpers&version=3.2.1"
3
+ #addin "Cake.Incubator&version=5.1.0"
3
4
4
5
using System . Text . RegularExpressions ;
5
6
@@ -11,7 +12,7 @@ var testProject = File("./SlackAPI.Tests/SlackApi.Tests.csproj");
11
12
var testConfig = File ( "./SlackAPI.Tests/Configuration/config.json" ) ;
12
13
var projects = new [ ] { project , testProject } ;
13
14
var artifactsDirectory = "./artifacts" ;
14
- var versionSuffix = string . Empty ;
15
+ GitVersion gitVersion = null ;
15
16
var isReleaseBuild = false ;
16
17
17
18
Task ( "Clean" )
@@ -24,67 +25,26 @@ Task("Clean")
24
25
Task ( "Configure" )
25
26
. Does ( ( ) =>
26
27
{
27
- var buildNumber = 0 ;
28
- if ( AppVeyor . IsRunningOnAppVeyor )
29
- {
30
- isReleaseBuild = AppVeyor . Environment . Repository . Branch == "master" && AppVeyor . Environment . Repository . Tag . IsTag ;
31
- buildNumber = AppVeyor . Environment . Build . Number ;
32
- Information ( "Build number is '{0}' (CI build)" , buildNumber ) ;
33
- }
34
- else
35
- {
36
- buildNumber = ( int ) ( DateTime . UtcNow - new DateTime ( 1970 , 1 , 1 ) ) . TotalSeconds ;
37
- Information ( "Build number is '{0}' (local build)" , buildNumber ) ;
38
- }
39
-
40
- // If the build is a tag on master, generate a clean version (1.0.0)
41
- // following SemVer 1.0.0 rules. NuGet supports only SemVer 1.0.0
42
- // In other cases, generate a prerelease version (1.0.0-branch.123+sha.abcdefg)
43
- // following SevVer 2.0.0 rules. MyGet supports SemVer 2.0.0
44
- if ( isReleaseBuild )
45
- {
46
- versionSuffix = "\" \" " ;
47
- }
48
- else
49
- {
50
- var gitVersion = GitVersion ( ) ;
51
- var gitBranch = ( AppVeyor . IsRunningOnAppVeyor
52
- ? AppVeyor . Environment . Repository . Branch
53
- : gitVersion . BranchName ) ;
54
- gitBranch = Regex . Replace ( gitBranch , @"[/\-_]" , string . Empty ) ;
55
- gitBranch = gitBranch . Substring ( 0 , Math . Min ( 10 , gitBranch . Length ) ) ;
56
-
57
- Information ( "Current git branch is '{0}' (normalized)" , gitBranch ) ;
58
-
59
- var gitCommitId = ( AppVeyor . IsRunningOnAppVeyor
60
- ? AppVeyor . Environment . Repository . Commit . Id
61
- : gitVersion . Sha )
62
- . Substring ( 0 , 8 ) ;
63
-
64
- Information ( "Current git sha is '{0}' (normalized)" , gitCommitId ) ;
65
-
66
- var isPullRequest = AppVeyor . IsRunningOnAppVeyor && AppVeyor . Environment . PullRequest . IsPullRequest ;
67
- if ( isPullRequest )
68
- {
69
- gitBranch = "PR" ;
70
- }
28
+ gitVersion = GitVersion ( ) ;
71
29
72
- Information ( "Is Pull Request: '{0}'" , isPullRequest ) ;
30
+ GitVersion ( new GitVersionSettings {
31
+ UpdateAssemblyInfo = true ,
32
+ UpdateAssemblyInfoFilePath = "GlobalAssemblyInfo.cs"
33
+ } ) ;
73
34
35
+ isReleaseBuild = AppVeyor . IsRunningOnAppVeyor
36
+ ? AppVeyor . Environment . Repository . Branch == "master"
37
+ : false ;
74
38
75
- versionSuffix = $ " { gitBranch } . { buildNumber } +sha. { gitCommitId } " ;
76
- }
39
+ Information ( "Is release build: '{0}'" , isReleaseBuild ) ;
40
+ Information ( "GitVersion details: \n {0}" , gitVersion . Dump ( ) ) ;
77
41
78
- var versionPrefix = XmlPeek ( "./Directory.Build.props" , "/Project/PropertyGroup/VersionPrefix" ) ;
79
- var version = isReleaseBuild ? $ "{ versionPrefix } -release.{ buildNumber } " : string . Join ( "-" , versionPrefix , versionSuffix ) ;
80
42
if ( AppVeyor . IsRunningOnAppVeyor )
81
43
{
82
- // Update AppVeyor build version so it will match the build version in assemblies and package
83
- AppVeyor . UpdateBuildVersion ( version ) ;
44
+ var buildVersion = gitVersion . SemVer + ".ci." + AppVeyor . Environment . Build . Number ;
45
+ Information ( "Using build version: {0}" , buildVersion ) ;
46
+ AppVeyor . UpdateBuildVersion ( buildVersion ) ;
84
47
}
85
-
86
- Information ( "Using version '{0}'" , version ) ;
87
- Information ( "Release type build (skip symbols): {0}" , isReleaseBuild ) ;
88
48
} ) ;
89
49
90
50
@@ -98,8 +58,7 @@ Task("Build")
98
58
project ,
99
59
new DotNetCoreBuildSettings
100
60
{
101
- Configuration = configuration ,
102
- VersionSuffix = versionSuffix
61
+ Configuration = configuration
103
62
}
104
63
) ;
105
64
}
@@ -186,9 +145,9 @@ Task("Package")
186
145
{
187
146
Configuration = configuration ,
188
147
OutputDirectory = artifactsDirectory ,
189
- VersionSuffix = versionSuffix ,
190
148
IncludeSymbols = ! isReleaseBuild ,
191
- IncludeSource = ! isReleaseBuild
149
+ IncludeSource = ! isReleaseBuild ,
150
+ ArgumentCustomization = args => args . Append ( "/p:Version=\" " + gitVersion . NuGetVersion + "\" " )
192
151
}
193
152
) ;
194
153
0 commit comments