Skip to content

Commit 75102dc

Browse files
authored
Merge pull request #231 from TestStack/netcore
Netcore
2 parents 716b790 + 8fc0b81 commit 75102dc

File tree

92 files changed

+1308
-1258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1308
-1258
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ TestStack.BDDfy.sln.ide/graph
1919
_NCrunch_TestStack.BDDfy/
2020
TestStack.BDDfy.sln.ide/
2121
src/packages/
22+
src/.vs/
23+
project.lock.json
24+
tools/Cake/
25+
tools/GitReleaseNotes/
26+
artifacts/

appveyor.deploy.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
assembly_info:
2+
patch: false
3+
4+
platform:
5+
- Any CPU
6+
7+
configuration:
8+
- Debug
9+
10+
build_script:
11+
- ps: ./deploy.ps1
12+
13+
test: off
14+
skip_non_tags: true

appveyor.yml

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +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
16-
17-
build:
18-
project: src\TestStack.BDDfy.sln
19-
20-
after_build:
21-
- cmd: nuget pack src\TestStack.BDDfy\TestStack.BDDfy.nuspec -BasePath src\TestStack.BDDfy\ -version "%GitVersion_NuGetVersion%" -prop "configuration=%CONFIGURATION%"
22-
- cmd: appveyor PushArtifact "TestStack.BDDfy.%GitVersion_NuGetVersion%.nupkg"
10+
build_script:
11+
- ps: .\build.ps1
2312

24-
- cmd: 7z a "TestStack.BDDfy_%GitVersion_NuGetVersion%.zip" -r src\TestStack.BDDfy\bin\%CONFIGURATION%\*.*
25-
- cmd: appveyor PushArtifact "TestStack.BDDfy_%GitVersion_NuGetVersion%.zip"
13+
test: off
14+
skip_tags: true
2615

2716
cache:
2817
- 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: 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

deploy.cake

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#addin "Cake.Json"
2+
3+
using System.Net;
4+
using System.Linq;
5+
6+
var target = Argument("target", "Default");
7+
8+
string Get(string url)
9+
{
10+
var assetsRequest = WebRequest.CreateHttp(url);
11+
assetsRequest.Method = "GET";
12+
assetsRequest.Accept = "application/vnd.github.v3+json";
13+
assetsRequest.UserAgent = "BuildScript";
14+
15+
using (var assetsResponse = assetsRequest.GetResponse())
16+
{
17+
var assetsStream = assetsResponse.GetResponseStream();
18+
var assetsReader = new StreamReader(assetsStream);
19+
var assetsBody = assetsReader.ReadToEnd();
20+
return assetsBody;
21+
}
22+
}
23+
24+
Task("EnsureRequirements")
25+
.Does(() =>
26+
{
27+
if (!AppVeyor.IsRunningOnAppVeyor)
28+
throw new Exception("Deployment should happen via appveyor");
29+
30+
var isTag =
31+
AppVeyor.Environment.Repository.Tag.IsTag &&
32+
!string.IsNullOrWhiteSpace(AppVeyor.Environment.Repository.Tag.Name);
33+
if (!isTag)
34+
throw new Exception("Deployment should happen from a published GitHub release");
35+
});
36+
37+
var tag = "";
38+
39+
Task("UpdateVersionInfo")
40+
.IsDependentOn("EnsureRequirements")
41+
.Does(() =>
42+
{
43+
tag = AppVeyor.Environment.Repository.Tag.Name;
44+
AppVeyor.UpdateBuildVersion(tag);
45+
});
46+
47+
Task("DownloadGitHubReleaseArtifacts")
48+
.IsDependentOn("UpdateVersionInfo")
49+
.Does(() =>
50+
{
51+
var assets_url = ParseJson(Get("https://api.github.com/repos/shouldly/shouldly/releases/tags/" + tag))
52+
.GetValue("assets_url").Value<string>();
53+
EnsureDirectoryExists("./releaseArtifacts");
54+
foreach(var asset in DeserializeJson<JArray>(Get(assets_url)))
55+
{
56+
DownloadFile(asset.Value<string>("browser_download_url"), "./releaseArtifacts/" + asset.Value<string>("name"));
57+
}
58+
});
59+
60+
Task("DeployNuget")
61+
.IsDependentOn("DownloadGitHubReleaseArtifacts")
62+
.Does(() =>
63+
{
64+
// Turns .artifacts file into a lookup
65+
var fileLookup = System.IO.File
66+
.ReadAllLines("./releaseArtifacts/artifacts")
67+
.Select(l => l.Split(':'))
68+
.ToDictionary(v => v[0], v => v[1]);
69+
70+
NuGetPush(
71+
"./releaseArtifacts/" + fileLookup["nuget"],
72+
new NuGetPushSettings {
73+
ApiKey = EnvironmentVariable("NuGetApiKey"),
74+
Source = "https://www.nuget.org/api/v2/package"
75+
});
76+
});
77+
78+
Task("Deploy")
79+
.IsDependentOn("DeployNuget");
80+
81+
Task("Default")
82+
.IsDependentOn("Deploy");
83+
84+
Task("Verify")
85+
.Does(() => {
86+
// Nothing, used to make sure the script compiles
87+
});
88+
89+
RunTarget(target);

0 commit comments

Comments
 (0)