Skip to content

Commit ab69493

Browse files
committed
Add build.cake script
1 parent a0be87d commit ab69493

9 files changed

+346
-20
lines changed

NUnit3TestAdapter.sln

166 Bytes
Binary file not shown.

appveyor.yml

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
version: 3.5.{build}
22
image: Visual Studio 2015
3-
configuration: Release
4-
before_build:
5-
- cmd: nuget restore
6-
build:
7-
project: NUnit3TestAdapter.sln
8-
publish_nuget: true
9-
verbosity: minimal
10-
test:
11-
assemblies: NUnit.VisualStudio.TestAdapter.Tests.dll
3+
4+
build_script:
5+
- ps: .\build.ps1 -Target "Appveyor"
6+
7+
# disable built-in tests.
8+
test: off

build.cake

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.1
2+
3+
//////////////////////////////////////////////////////////////////////
4+
// ARGUMENTS
5+
//////////////////////////////////////////////////////////////////////
6+
7+
var target = Argument("target", "Default");
8+
var configuration = Argument("configuration", "Debug");
9+
10+
//////////////////////////////////////////////////////////////////////
11+
// SET PACKAGE VERSION
12+
//////////////////////////////////////////////////////////////////////
13+
14+
var version = "3.5";
15+
var modifier = "";
16+
17+
var isAppveyor = BuildSystem.IsRunningOnAppVeyor;
18+
var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
19+
var packageVersion = version + modifier + dbgSuffix;
20+
21+
//////////////////////////////////////////////////////////////////////
22+
// DEFINE RUN CONSTANTS
23+
//////////////////////////////////////////////////////////////////////
24+
25+
// Directories
26+
var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
27+
var PACKAGE_DIR = PROJECT_DIR + "package/";
28+
var NUNIT3_CONSOLE = PROJECT_DIR + "tools/NUnit.ConsoleRunner/tools/nunit3-console.exe";
29+
30+
// TODO: Consolidate in one directory
31+
var ADAPTER_DIR = PROJECT_DIR + "src/NUnitTestAdapter/bin/" + configuration + "/";
32+
var TEST_DIR = PROJECT_DIR + "src/NUnitTestAdapterTests/bin/" + configuration + "/";
33+
var INSTALL_DIR = PROJECT_DIR + "src/NUnitTestAdapterInstall/bin/" + configuration + "/";
34+
35+
// Solution
36+
var ADAPTER_SOLUTION = PROJECT_DIR + "NUnit3TestAdapter.sln";
37+
38+
// Test Assembly
39+
var ADAPTER_TESTS = TEST_DIR + "NUnit.VisualStudio.TestAdapter.Tests.dll";
40+
41+
// Packages
42+
var SRC_PACKAGE = PACKAGE_DIR + "NUnit3TestAdapter-" + version + modifier + "-src.zip";
43+
var ZIP_PACKAGE = PACKAGE_DIR + "NUnit3TestAdapter-" + packageVersion + ".zip";
44+
45+
//////////////////////////////////////////////////////////////////////
46+
// CLEAN
47+
//////////////////////////////////////////////////////////////////////
48+
49+
Task("Clean")
50+
.Does(() =>
51+
{
52+
CleanDirectory(ADAPTER_DIR);
53+
CleanDirectory(TEST_DIR);
54+
CleanDirectory(INSTALL_DIR);
55+
});
56+
57+
58+
//////////////////////////////////////////////////////////////////////
59+
// INITIALIZE FOR BUILD
60+
//////////////////////////////////////////////////////////////////////
61+
62+
Task("InitializeBuild")
63+
.Does(() =>
64+
{
65+
NuGetRestore(ADAPTER_SOLUTION);
66+
67+
if (BuildSystem.IsRunningOnAppVeyor)
68+
{
69+
var tag = AppVeyor.Environment.Repository.Tag;
70+
71+
if (tag.IsTag)
72+
{
73+
packageVersion = tag.Name;
74+
}
75+
else
76+
{
77+
var buildNumber = AppVeyor.Environment.Build.Number;
78+
packageVersion = version + "-CI-" + buildNumber + dbgSuffix;
79+
if (AppVeyor.Environment.PullRequest.IsPullRequest)
80+
packageVersion += "-PR-" + AppVeyor.Environment.PullRequest.Number;
81+
else
82+
packageVersion += "-" + AppVeyor.Environment.Repository.Branch;
83+
}
84+
85+
AppVeyor.UpdateBuildVersion(packageVersion);
86+
}
87+
});
88+
89+
//////////////////////////////////////////////////////////////////////
90+
// BUILD
91+
//////////////////////////////////////////////////////////////////////
92+
93+
Task("Build")
94+
.IsDependentOn("InitializeBuild")
95+
.Does(() =>
96+
{
97+
MSBuild(ADAPTER_SOLUTION, new MSBuildSettings()
98+
.SetConfiguration(configuration)
99+
.SetMSBuildPlatform(MSBuildPlatform.x86)
100+
.SetVerbosity(Verbosity.Minimal)
101+
.SetNodeReuse(false)
102+
);
103+
});
104+
105+
//////////////////////////////////////////////////////////////////////
106+
// TEST
107+
//////////////////////////////////////////////////////////////////////
108+
109+
Task("Test")
110+
.IsDependentOn("Build")
111+
.Does(() =>
112+
{
113+
StartProcess(
114+
NUNIT3_CONSOLE,
115+
new ProcessSettings()
116+
{
117+
Arguments = ADAPTER_TESTS
118+
});
119+
});
120+
121+
//////////////////////////////////////////////////////////////////////
122+
// PACKAGE
123+
//////////////////////////////////////////////////////////////////////
124+
125+
Task("PackageSource")
126+
.Does(() =>
127+
{
128+
CreateDirectory(PACKAGE_DIR);
129+
RunGitCommand(string.Format("archive -o {0} HEAD", SRC_PACKAGE));
130+
});
131+
132+
Task("PackageZip")
133+
.IsDependentOn("Build")
134+
.Does(() =>
135+
{
136+
CreateDirectory(PACKAGE_DIR);
137+
138+
var zipFiles = new FilePath[]
139+
{
140+
PROJECT_DIR + "README.md",
141+
ADAPTER_DIR + "NUnit3.TestAdapter.dll",
142+
ADAPTER_DIR + "nunit.engine.dll",
143+
ADAPTER_DIR + "nunit.engine.api.dll",
144+
ADAPTER_DIR + "Mono.Cecil.dll",
145+
ADAPTER_DIR + "Mono.Cecil.Pdb.dll",
146+
ADAPTER_DIR + "Mono.Cecil.Mdb.dll",
147+
ADAPTER_DIR + "Mono.Cecil.Rocks.dll"
148+
};
149+
150+
Zip(ADAPTER_DIR, File(ZIP_PACKAGE), zipFiles);
151+
});
152+
153+
//////////////////////////////////////////////////////////////////////
154+
// HELPER METHODS
155+
//////////////////////////////////////////////////////////////////////
156+
157+
void RunGitCommand(string arguments)
158+
{
159+
StartProcess("git", new ProcessSettings()
160+
{
161+
Arguments = arguments
162+
});
163+
}
164+
165+
//////////////////////////////////////////////////////////////////////
166+
// TASK TARGETS
167+
//////////////////////////////////////////////////////////////////////
168+
169+
Task("Rebuild")
170+
.IsDependentOn("Clean")
171+
.IsDependentOn("Build");
172+
173+
Task("Package")
174+
.IsDependentOn("PackageSource")
175+
.IsDependentOn("PackageZip");
176+
177+
Task("Appveyor")
178+
.IsDependentOn("Build")
179+
.IsDependentOn("Test");
180+
//.IsDependentOn("Package");
181+
182+
Task("Default")
183+
.IsDependentOn("Build");
184+
185+
//////////////////////////////////////////////////////////////////////
186+
// EXECUTION
187+
//////////////////////////////////////////////////////////////////////
188+
189+
RunTarget(target);

build.cmd

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
powershell ./build.ps1 %CAKE_ARGS% %*

build.ps1

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
##########################################################################
2+
# This is the Cake bootstrapper script for PowerShell.
3+
# This file was downloaded from https://github.com/cake-build/resources
4+
# Feel free to change this file to fit your needs.
5+
##########################################################################
6+
7+
<#
8+
9+
.SYNOPSIS
10+
This is a Powershell script to bootstrap a Cake build.
11+
12+
.DESCRIPTION
13+
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
14+
and execute your Cake build script with the parameters you provide.
15+
16+
.PARAMETER Script
17+
The build script to execute.
18+
.PARAMETER Target
19+
The build script target to run.
20+
.PARAMETER Configuration
21+
The build configuration to use.
22+
.PARAMETER Verbosity
23+
Specifies the amount of information to be displayed.
24+
.PARAMETER Experimental
25+
Tells Cake to use the latest Roslyn release.
26+
.PARAMETER WhatIf
27+
Performs a dry run of the build script.
28+
No tasks will be executed.
29+
.PARAMETER Mono
30+
Tells Cake to use the Mono scripting engine.
31+
.PARAMETER SkipToolPackageRestore
32+
Skips restoring of packages.
33+
.PARAMETER ScriptArgs
34+
Remaining arguments are added here.
35+
36+
.LINK
37+
http://cakebuild.net
38+
39+
#>
40+
41+
[CmdletBinding()]
42+
Param(
43+
[string]$Script = "build.cake",
44+
[string]$Target = "Default",
45+
[string]$Configuration = "Release",
46+
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
47+
[string]$Verbosity = "Verbose",
48+
[switch]$Experimental,
49+
[Alias("DryRun","Noop")]
50+
[switch]$WhatIf,
51+
[switch]$Mono,
52+
[switch]$SkipToolPackageRestore,
53+
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
54+
[string[]]$ScriptArgs
55+
)
56+
57+
Write-Host "Preparing to run build script..."
58+
59+
$PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition;
60+
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
61+
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
62+
$NUGET_URL = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
63+
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
64+
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
65+
66+
# Should we use mono?
67+
$UseMono = "";
68+
if($Mono.IsPresent) {
69+
Write-Verbose -Message "Using the Mono based scripting engine."
70+
$UseMono = "-mono"
71+
}
72+
73+
# Should we use the new Roslyn?
74+
$UseExperimental = "";
75+
if($Experimental.IsPresent -and !($Mono.IsPresent)) {
76+
Write-Verbose -Message "Using experimental version of Roslyn."
77+
$UseExperimental = "-experimental"
78+
}
79+
80+
# Is this a dry run?
81+
$UseDryRun = "";
82+
if($WhatIf.IsPresent) {
83+
$UseDryRun = "-dryrun"
84+
}
85+
86+
# Make sure tools folder exists
87+
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
88+
Write-Verbose -Message "Creating tools directory..."
89+
New-Item -Path $TOOLS_DIR -Type directory | out-null
90+
}
91+
92+
# Make sure that packages.config exist.
93+
if (!(Test-Path $PACKAGES_CONFIG)) {
94+
Write-Verbose -Message "Downloading packages.config..."
95+
try { Invoke-WebRequest -Uri http://cakebuild.net/download/bootstrapper/packages -OutFile $PACKAGES_CONFIG } catch {
96+
Throw "Could not download packages.config."
97+
}
98+
}
99+
100+
# Try find NuGet.exe in path if not exists
101+
if (!(Test-Path $NUGET_EXE)) {
102+
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
103+
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) }
104+
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
105+
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
106+
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
107+
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
108+
}
109+
}
110+
111+
# Try download NuGet.exe if not exists
112+
if (!(Test-Path $NUGET_EXE)) {
113+
Write-Verbose -Message "Downloading NuGet.exe..."
114+
try {
115+
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
116+
} catch {
117+
Throw "Could not download NuGet.exe."
118+
}
119+
}
120+
121+
# Save nuget.exe path to environment to be available to child processed
122+
$ENV:NUGET_EXE = $NUGET_EXE
123+
124+
# Restore tools from NuGet?
125+
if(-Not $SkipToolPackageRestore.IsPresent) {
126+
Push-Location
127+
Set-Location $TOOLS_DIR
128+
Write-Verbose -Message "Restoring tools from NuGet..."
129+
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
130+
if ($LASTEXITCODE -ne 0) {
131+
Throw "An error occured while restoring NuGet tools."
132+
}
133+
Write-Verbose -Message ($NuGetOutput | out-string)
134+
Pop-Location
135+
}
136+
137+
# Make sure that Cake has been installed.
138+
if (!(Test-Path $CAKE_EXE)) {
139+
Throw "Could not find Cake.exe at $CAKE_EXE"
140+
}
141+
142+
# Start Cake
143+
Write-Host "Running build script..."
144+
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
145+
exit $LASTEXITCODE

nuget/NUnit3TestAdapter.nuspec

+4-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ The package works with Visual Studio 2012, 2013 and 2015.</description>
2525
<file src="${package.working.dir}\NUnit3.TestAdapter.dll" target="lib\NUnit3.TestAdapter.dll" />
2626
<file src="${package.working.dir}\nunit.engine.dll" target="lib\nunit.engine.dll" />
2727
<file src="${package.working.dir}\nunit.engine.api.dll" target="lib\nunit.engine.api.dll" />
28-
<file src="${package.working.dir}\Mono.Cecil.dll" target="lib\Mono.Cecil.dll" />
29-
<file src="${package.working.dir}\Mono.Cecil.Pdb.dll" target="lib\Mono.Cecil.Pdb.dll" />
30-
<file src="${package.working.dir}\Mono.Cecil.Mdb.dll" target="lib\Mono.Cecil.Mdb.dll" />
31-
<file src="${package.working.dir}\Mono.Cecil.Rocks.dll" target="lib\Mono.Cecil.Rocks.dll" />
32-
<file src="${package.working.dir}\ignore.addins" target="lib\ignore.addins" />
28+
<file src="${package.working.dir}\Mono.Cecil.dll" target="lib\Mono.Cecil.dll" />
29+
<file src="${package.working.dir}\Mono.Cecil.Pdb.dll" target="lib\Mono.Cecil.Pdb.dll" />
30+
<file src="${package.working.dir}\Mono.Cecil.Mdb.dll" target="lib\Mono.Cecil.Mdb.dll" />
31+
<file src="${package.working.dir}\Mono.Cecil.Rocks.dll" target="lib\Mono.Cecil.Rocks.dll" />
3332
<file src="${project.nuget.dir}\install.ps1" target="tools\install.ps1" />
3433
</files>
3534
</package>

nunit3-vs-adapter.build

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
<include name="Mono.Cecil.Pdb.dll"/>
6363
<include name="Mono.Cecil.Mdb.dll"/>
6464
<include name="Mono.Cecil.Rocks.dll"/>
65-
<include name="ignore.addins"/>
6665
</fileset>
6766
</copy>
6867

src/NUnitTestAdapterInstall/NUnit3TestAdapterInstall.csproj

-4
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@
101101
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
102102
<IncludeInVSIX>true</IncludeInVSIX>
103103
</Content>
104-
<Content Include="ignore.addins">
105-
<IncludeInVSIX>true</IncludeInVSIX>
106-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
107-
</Content>
108104
<None Include="app.config" />
109105
<None Include="packages.config" />
110106
<None Include="source.extension.vsixmanifest">

src/NUnitTestAdapterInstall/ignore.addins

-1
This file was deleted.

0 commit comments

Comments
 (0)