Skip to content

Commit 60b1c41

Browse files
committed
Added proper build script and fixed up test failures
1 parent 273ace1 commit 60b1c41

File tree

12 files changed

+314
-115
lines changed

12 files changed

+314
-115
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ TestStack.BDDfy.sln.ide/
2121
src/packages/
2222
src/.vs/
2323
project.lock.json
24+
tools/Cake/
25+
tools/GitReleaseNotes/
26+
artifacts/

appveyor.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
install:
2-
- choco install gitversion.portable -pre -y
3-
1+
assembly_info:
2+
patch: false
3+
44
platform:
55
- Any CPU
66

77
configuration:
88
- Release
99

10-
assembly_info:
11-
patch: false
12-
13-
before_build:
14-
- nuget restore src\
15-
- ps: gitversion /l console /output buildserver /updateAssemblyInfo
10+
build_script:
11+
- ps: .\build.ps1
1612

17-
build:
18-
project: src\TestStack.BDDfy.sln
13+
test: off
14+
skip_tags: true
1915

2016
after_build:
2117
- cmd: nuget pack src\TestStack.BDDfy\TestStack.BDDfy.nuspec -BasePath src\TestStack.BDDfy\ -version "%GitVersion_NuGetVersion%" -prop "configuration=%CONFIGURATION%"

build.cake

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#tool "nuget:?package=GitReleaseNotes"
2+
3+
var target = Argument("target", "Default");
4+
var bddfyProj = "./src/TestStack.BDDfy/project.json";
5+
var outputDir = "./artifacts/";
6+
7+
Task("Clean")
8+
.Does(() => {
9+
if (DirectoryExists(outputDir))
10+
{
11+
DeleteDirectory(outputDir, recursive:true);
12+
}
13+
});
14+
15+
Task("Restore")
16+
.Does(() => {
17+
DotNetCoreRestore("src");
18+
});
19+
20+
GitVersion versionInfo = null;
21+
Task("Version")
22+
.Does(() => {
23+
GitVersion(new GitVersionSettings{
24+
UpdateAssemblyInfo = true,
25+
OutputType = GitVersionOutput.BuildServer
26+
});
27+
versionInfo = GitVersion(new GitVersionSettings{ OutputType = GitVersionOutput.Json });
28+
// Update project.json
29+
var updatedProjectJson = System.IO.File.ReadAllText(bddfyProj)
30+
.Replace("1.0.0-*", versionInfo.NuGetVersion);
31+
32+
System.IO.File.WriteAllText(bddfyProj, updatedProjectJson);
33+
});
34+
35+
Task("Build")
36+
.IsDependentOn("Clean")
37+
.IsDependentOn("Version")
38+
.IsDependentOn("Restore")
39+
.Does(() => {
40+
MSBuild("./src/TestStack.BDDfy.sln");
41+
});
42+
43+
Task("Test")
44+
.IsDependentOn("Build")
45+
.Does(() => {
46+
DotNetCoreTest("./src/TestStack.BDDfy.Tests");
47+
DotNetCoreTest("./src/Samples/TestStack.BDDfy.Samples");
48+
});
49+
50+
Task("Package")
51+
.IsDependentOn("Test")
52+
.Does(() => {
53+
var settings = new DotNetCorePackSettings
54+
{
55+
OutputDirectory = outputDir,
56+
NoBuild = true
57+
};
58+
59+
DotNetCorePack(bddfyProj, settings);
60+
61+
var releaseNotesExitCode = StartProcess(
62+
@"tools\GitReleaseNotes\tools\gitreleasenotes.exe",
63+
new ProcessSettings { Arguments = ". /o artifacts/releasenotes.md" });
64+
if (string.IsNullOrEmpty(System.IO.File.ReadAllText("./artifacts/releasenotes.md")))
65+
System.IO.File.WriteAllText("./artifacts/releasenotes.md", "No issues closed since last release");
66+
67+
if (releaseNotesExitCode != 0) throw new Exception("Failed to generate release notes");
68+
69+
System.IO.File.WriteAllLines(outputDir + "artifacts", new[]{
70+
"nuget:TestStack.BDDfy." + versionInfo.NuGetVersion + ".nupkg",
71+
"nugetSymbols:TestStack.BDDfy." + versionInfo.NuGetVersion + ".symbols.nupkg",
72+
"releaseNotes:releasenotes.md"
73+
});
74+
75+
if (AppVeyor.IsRunningOnAppVeyor)
76+
{
77+
foreach (var file in GetFiles(outputDir + "**/*"))
78+
AppVeyor.UploadArtifact(file.FullPath);
79+
}
80+
});
81+
82+
Task("Default")
83+
.IsDependentOn("Package");
84+
85+
RunTarget(target);

build.ps1

Lines changed: 145 additions & 0 deletions
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
Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
{
2-
"version": "1.0.0-*",
3-
"testRunner": "xunit",
4-
5-
"dependencies": {
6-
"dotnet-test-xunit": "2.2.0-preview2-build1029",
7-
"Microsoft.NETCore.Platforms": "1.0.1",
8-
"Shouldly": "2.8.0",
9-
"TestStack.BDDfy": {
10-
"target": "project"
2+
"dependencies": {
3+
"dotnet-test-xunit": "2.2.0-preview2-build1029",
4+
"Microsoft.NETCore.Platforms": "1.0.1",
5+
"Shouldly": "2.8.0",
6+
"TestStack.BDDfy": {
7+
"target": "project"
8+
},
9+
"xunit.core": "2.2.0-beta2-build3300"
1110
},
12-
"xunit.core": "2.2.0-beta2-build3300"
13-
},
14-
15-
"runtimes": {
16-
"win10-x64": {}
17-
},
1811

19-
"frameworks": {
20-
"netcoreapp1.0": {
21-
"dependencies": {
22-
"Microsoft.NETCore.App": "1.0.0",
23-
"System.Linq": "4.1.0"
24-
},
25-
"imports": [
26-
"dnxcore50",
27-
"portable-net45+win8"
28-
]
12+
"frameworks": {
13+
"netcoreapp1.0": {
14+
"dependencies": {
15+
"Microsoft.NETCore.App": {
16+
"type": "platform",
17+
"version": "1.0.0"
18+
},
19+
"System.Linq": "4.1.0"
20+
},
21+
"imports": [
22+
"dnxcore50",
23+
"portable-net45+win8"
24+
]
25+
},
26+
"net46": {
27+
"dependencies": {
28+
},
29+
"buildOptions": {
30+
"define": [
31+
"Approvals",
32+
"Culture",
33+
"NSubstitute"
34+
]
35+
}
36+
}
37+
},
38+
"runtimes": {
39+
"win10-x64": {}
2940
},
30-
"net46": {
31-
"dependencies": {
32-
},
33-
"buildOptions": {
34-
"define": [
35-
"Approvals",
36-
"Culture",
37-
"NSubstitute"
38-
]
39-
}
40-
}
41-
}
41+
"testRunner": "xunit",
42+
"version": "1.0.0-*"
4243
}

0 commit comments

Comments
 (0)