Skip to content

Commit aaf37c5

Browse files
gep13JakeGinnivan
authored andcommitted
Initial Cake Build Script
- Lets see how well this works - Thrown together over lunch - Opening this as a point of discussion
1 parent aa5bb19 commit aaf37c5

File tree

7 files changed

+487
-51
lines changed

7 files changed

+487
-51
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Auto detect text files and perform LF normalization
22
* text=auto eol=crlf
33

4+
# Declare files that will always have LF line endings on checkout.
5+
*.sh text eol=lf
6+
47
# Don't check these into the repo as LF to work around TeamCity bug
58
*.xml -text
69
*.targets -text

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,10 @@ site/
101101
# Visual Studio Code
102102
####################
103103

104-
.vscode
104+
.vscode
105+
106+
####################
107+
# Cake
108+
####################
109+
/tools
110+
/*.zip

.travis.yml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
language: csharp
2-
solution: src/GitVersion.sln
32
sudo: false
43
mono:
54
- latest
65
os:
76
- linux
87
- osx
9-
before_install: # We need to download nuget.exe due to: https://github.com/travis-ci/travis-ci/issues/5932
8+
before_install:
109
- git fetch --unshallow # Travis always does a shallow clone, but GitVersion needs the full history including branches and tags
11-
- mkdir -p .nuget
12-
- wget -O .nuget/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
13-
- mono .nuget/nuget.exe
14-
install:
15-
- mono .nuget/nuget.exe restore src/GitVersion.sln -Verbosity detailed
16-
- mono .nuget/nuget.exe install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages
1710
script:
18-
- xbuild ./src/GitVersion.sln /property:Configuration="Debug" /verbosity:detailed
19-
- mono ./build/NuGetCommandLineBuild/tools/GitVersion.exe -l console -output buildserver -updateAssemblyInfo
20-
- xbuild ./src/GitVersion.sln /property:Configuration="Debug" /verbosity:detailed
21-
- mono ./src/packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionCore.Tests/bin/Debug/GitVersionCore.Tests.dll ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionExe.Tests/bin/Debug/GitVersionExe.Tests.dll --where "cat != NoMono" --noresult
22-
23-
#
24-
# To run a clean build with Mono, executing just one test, do:
25-
# xbuild ./src/GitVersion.sln /t:Clean /verbosity:quiet && xbuild ./src/GitVersion.sln /property:Configuration="Debug" /verbosity:quiet && mono ./src/packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionCore.Tests/bin/Debug/GitVersionCore.Tests.dll ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionExe.Tests/bin/Debug/GitVersionExe.Tests.dll --noresult --where "test =~ /TheNameOfTheTest/"
26-
#
27-
# To run a clean build with Mono, executing all tests, do:
28-
# xbuild ./src/GitVersion.sln /t:Clean /verbosity:quiet && xbuild ./src/GitVersion.sln /property:Configuration="Debug" /verbosity:quiet && mono ./src/packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionCore.Tests/bin/Debug/GitVersionCore.Tests.dll ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionExe.Tests/bin/Debug/GitVersionExe.Tests.dll --noresult --where "cat != NoMono" --noresult
29-
#
11+
- ./build.sh
12+
cache:
13+
directories:
14+
- src/packages
15+
- tools

appveyor.yml

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,8 @@
1-
assembly_info:
2-
patch: false
3-
4-
platform:
5-
- Any CPU
6-
71
configuration:
82
- Debug
93

104
build_script:
11-
- cmd: nuget restore src/GitVersion.sln
12-
- cmd: npm i -g tfx-cli
13-
14-
- cmd: msbuild src/GitVersion.sln "/p:Configuration=%CONFIGURATION%;Platform=%PLATFORM%"
15-
- ps: .\build\NuGetCommandLineBuild\tools\GitVersion.exe /l console /output buildserver /updateAssemblyInfo
16-
- cmd: msbuild src/GitVersion.sln "/p:Configuration=%CONFIGURATION%;Platform=%PLATFORM%"
17-
18-
- cmd: appveyor PushArtifact "build\NuGetExeBuild\GitVersion.Portable.%GitVersion_NuGetVersion%.nupkg"
19-
20-
- cmd: appveyor PushArtifact "build\NuGetCommandLineBuild\GitVersion.CommandLine.%GitVersion_NuGetVersion%.nupkg"
21-
- cmd: appveyor PushArtifact "build\NuGetRefBuild\GitVersion.%GitVersion_NuGetVersion%.nupkg"
22-
- cmd: appveyor PushArtifact "build\NuGetTaskBuild\GitVersionTask.%GitVersion_NuGetVersion%.nupkg"
23-
- ps: appveyor PushArtifact ("build\GemBuild\gitversion-$env:GitVersion_MajorMinorPatch" + (&{If($env:GitVersion_PreReleaseTag -eq '' -or $env:GitVersion_PreReleaseTag -eq $null) {""} Else {"."+$env:GitVersion_PreReleaseTag}}) + ".gem")
24-
25-
- cmd: 7z a "GitVersion_%GitVersion_NuGetVersion%.zip" -r .\build\NuGetCommandLineBuild\Tools\*.*
26-
- cmd: appveyor PushArtifact "GitVersion_%GitVersion_NuGetVersion%.zip"
27-
28-
- cmd: 7z a "GitVersionTfsBuildTask_%GitVersion_NuGetVersion%.zip" -r .\build\GitVersionTfsTaskBuild\GitVersionTask\*.*
29-
- cmd: appveyor PushArtifact "GitVersionTfsBuildTask_%GitVersion_NuGetVersion%.zip"
30-
- cmd: appveyor PushArtifact "build\GitVersionTfsTaskBuild\gittools.gitversion-%GitVersion_SemVer%.vsix"
31-
32-
test_script:
33-
- nunit3-console "src\GitVersionTask.Tests\bin\%CONFIGURATION%\GitVersionTask.Tests.dll" "src\GitVersionExe.Tests\bin\%CONFIGURATION%\GitVersionExe.Tests.dll" "src\GitVersionCore.Tests\bin\%CONFIGURATION%\GitVersionCore.Tests.dll"
5+
- ps: .\build.ps1 -Target "AppVeyor"
346

357
cache:
36-
- src\packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified
8+
- src\packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified

build.cake

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
#tool "nuget:?package=GitVersion.CommandLine"
2+
#tool "nuget:?package=NUnit.ConsoleRunner"
3+
4+
var target = Argument("target", "Default");
5+
var configuration = Argument("configuration", "Release");
6+
7+
string version = null;
8+
string nugetVersion = null;
9+
string preReleaseTag = null;
10+
string semVersion = null;
11+
string milestone = null;
12+
bool publishingError = false;
13+
bool IsTagged = (BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag &&
14+
!string.IsNullOrWhiteSpace(BuildSystem.AppVeyor.Environment.Repository.Tag.Name));
15+
bool IsMainGitVersionRepo = StringComparer.OrdinalIgnoreCase.Equals("gittools/gitversion", BuildSystem.AppVeyor.Environment.Repository.Name);
16+
bool IsPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest;
17+
18+
Setup(context =>
19+
{
20+
if(!BuildSystem.IsLocalBuild)
21+
{
22+
GitVersion(new GitVersionSettings{
23+
UpdateAssemblyInfo = true,
24+
LogFilePath = "console",
25+
OutputType = GitVersionOutput.BuildServer
26+
});
27+
28+
version = context.EnvironmentVariable("GitVersion_MajorMinorPatch");
29+
nugetVersion = context.EnvironmentVariable("GitVersion_NuGetVersion");
30+
preReleaseTag = context.EnvironmentVariable("GitVersion_PreReleaseTag");
31+
semVersion = context.EnvironmentVariable("GitVersion_LegacySemVerPadded");
32+
milestone = string.Concat("v", version);
33+
}
34+
35+
GitVersion assertedVersions = GitVersion(new GitVersionSettings
36+
{
37+
OutputType = GitVersionOutput.Json
38+
});
39+
40+
version = assertedVersions.MajorMinorPatch;
41+
nugetVersion = assertedVersions.NuGetVersion;
42+
preReleaseTag = assertedVersions.PreReleaseTag;
43+
semVersion = assertedVersions.LegacySemVerPadded;
44+
milestone = string.Concat("v", version);
45+
});
46+
47+
Task("NuGet-Package-Restore")
48+
.Does(() =>
49+
{
50+
NuGetRestore("./src/GitVersion.sln");
51+
});
52+
53+
Task("Build")
54+
.IsDependentOn("NuGet-Package-Restore")
55+
.Does(() =>
56+
{
57+
if(IsRunningOnUnix())
58+
{
59+
XBuild("./Source/Gep13.Cake.Sample.WebApplication.sln", new XBuildSettings()
60+
.SetConfiguration(configuration)
61+
.WithProperty("POSIX", "True")
62+
.SetVerbosity(Verbosity.Verbose)
63+
);
64+
}
65+
else
66+
{
67+
MSBuild("./src/GitVersion.sln", new MSBuildSettings()
68+
.SetConfiguration(configuration)
69+
.SetPlatformTarget(PlatformTarget.MSIL)
70+
.WithProperty("Windows", "True")
71+
.UseToolVersion(MSBuildToolVersion.VS2015)
72+
.SetVerbosity(Verbosity.Minimal)
73+
.SetNodeReuse(false));
74+
}
75+
});
76+
77+
Task("Run-NUnit-Tests")
78+
.IsDependentOn("Build")
79+
.Does(() =>
80+
{
81+
NUnit3("src/*.Tests/bin/" + configuration + "/*.Tests.dll");
82+
});
83+
84+
Task("Zip-Files")
85+
.IsDependentOn("Run-NUnit-Tests")
86+
.Does(() =>
87+
{
88+
var files = GetFiles("./build/NuGetCommandLineBuild/Tools/*.*");
89+
90+
Zip("./", "GitVersion_" + nugetVersion + ".zip", files);
91+
92+
files = GetFiles("./build/GitVersionTfsTaskBuild/GitVersionTask/*.*");
93+
94+
Zip("./", "GitVersionTfsBuildTask_" + nugetVersion + ".zip", files);
95+
});
96+
97+
Task("Create-NuGet-Packages")
98+
.Does(() =>
99+
{
100+
101+
});
102+
103+
Task("Create-Chocolatey-Packages")
104+
.Does(() =>
105+
{
106+
107+
});
108+
109+
Task("Create-Release-Notes")
110+
.Does(() =>
111+
{
112+
//GitReleaseManagerCreate(parameters.GitHub.UserName, parameters.GitHub.Password, "cake-build", "cake", new GitReleaseManagerCreateSettings {
113+
// Milestone = parameters.Version.Milestone,
114+
// Name = parameters.Version.Milestone,
115+
// Prerelease = true,
116+
// TargetCommitish = "main"
117+
//});
118+
});
119+
120+
Task("Package")
121+
.IsDependentOn("Zip-Files")
122+
.IsDependentOn("Create-NuGet-Packages")
123+
.IsDependentOn("Create-Chocolatey-Packages");
124+
125+
Task("Upload-AppVeyor-Artifacts")
126+
.IsDependentOn("Package")
127+
.WithCriteria(() => BuildSystem.AppVeyor.IsRunningOnAppVeyor)
128+
.Does(() =>
129+
{
130+
AppVeyor.UploadArtifact("build/NuGetExeBuild/GitVersion.Portable." + nugetVersion +".nupkg");
131+
AppVeyor.UploadArtifact("build/NuGetCommandLineBuild/GitVersion.CommandLine." + nugetVersion +".nupkg");
132+
AppVeyor.UploadArtifact("build/NuGetRefBuild/GitVersion." + nugetVersion +".nupkg");
133+
AppVeyor.UploadArtifact("build/NuGetTaskBuild/GitVersionTask." + nugetVersion +".nupkg");
134+
AppVeyor.UploadArtifact("build/GitVersionTfsTaskBuild/gittools.gitversion-" + semVersion + ".vsix");
135+
AppVeyor.UploadArtifact("GitVersion_" + nugetVersion + ".zip");
136+
AppVeyor.UploadArtifact("GitVersionTfsBuildTask_" + nugetVersion + ".zip");
137+
});
138+
139+
Task("Publish-MyGet")
140+
.IsDependentOn("Package")
141+
.WithCriteria(() => !BuildSystem.IsLocalBuild)
142+
.WithCriteria(() => !IsPullRequest)
143+
.WithCriteria(() => IsMainGitVersionRepo)
144+
.Does(() =>
145+
{
146+
147+
})
148+
.OnError(exception =>
149+
{
150+
Information("Publish-MyGet Task failed, but continuing with next Task...");
151+
publishingError = true;
152+
});
153+
154+
Task("Publish-NuGet")
155+
.IsDependentOn("Package")
156+
.WithCriteria(() => !BuildSystem.IsLocalBuild)
157+
.WithCriteria(() => !IsPullRequest)
158+
.WithCriteria(() => IsMainGitVersionRepo)
159+
.WithCriteria(() => IsTagged)
160+
.Does(() =>
161+
{
162+
163+
})
164+
.OnError(exception =>
165+
{
166+
Information("Publish-NuGet Task failed, but continuing with next Task...");
167+
publishingError = true;
168+
});
169+
170+
Task("Publish-Chocolatey")
171+
.IsDependentOn("Package")
172+
.WithCriteria(() => !BuildSystem.IsLocalBuild)
173+
.WithCriteria(() => !IsPullRequest)
174+
.WithCriteria(() => IsMainGitVersionRepo)
175+
.WithCriteria(() => IsTagged)
176+
.Does(() =>
177+
{
178+
179+
})
180+
.OnError(exception =>
181+
{
182+
Information("Publish-Chocolatey Task failed, but continuing with next Task...");
183+
publishingError = true;
184+
});
185+
186+
Task("Publish-Gem")
187+
.IsDependentOn("Package")
188+
.WithCriteria(() => !BuildSystem.IsLocalBuild)
189+
.WithCriteria(() => !IsPullRequest)
190+
.WithCriteria(() => IsMainGitVersionRepo)
191+
.WithCriteria(() => IsTagged)
192+
.Does(() =>
193+
{
194+
195+
})
196+
.OnError(exception =>
197+
{
198+
Information("Publish-Gem Task failed, but continuing with next Task...");
199+
publishingError = true;
200+
});
201+
202+
Task("Publish-GitHub-Release")
203+
.IsDependentOn("Package")
204+
.WithCriteria(() => !BuildSystem.IsLocalBuild)
205+
.WithCriteria(() => !IsPullRequest)
206+
.WithCriteria(() => IsMainGitVersionRepo)
207+
.WithCriteria(() => IsTagged)
208+
.Does(() =>
209+
{
210+
211+
})
212+
.OnError(exception =>
213+
{
214+
Information("Publish-GitHub-Release Task failed, but continuing with next Task...");
215+
publishingError = true;
216+
});
217+
218+
Task("AppVeyor")
219+
.IsDependentOn("Upload-AppVeyor-Artifacts")
220+
.IsDependentOn("Publish-MyGet")
221+
.IsDependentOn("Publish-NuGet")
222+
.IsDependentOn("Publish-Chocolatey")
223+
.IsDependentOn("Publish-Gem")
224+
.IsDependentOn("Publish-GitHub-Release")
225+
.Finally(() =>
226+
{
227+
if(publishingError)
228+
{
229+
throw new Exception("An error occurred during the publishing of Cake. All publishing tasks have been attempted.");
230+
}
231+
});
232+
233+
Task("Travis")
234+
.IsDependentOn("Run-NUnit-Tests");
235+
236+
Task("ReleaseNotes")
237+
.IsDependentOn("Create-Release-Notes");
238+
239+
Task("Default")
240+
.IsDependentOn("Package");
241+
242+
RunTarget(target);

0 commit comments

Comments
 (0)