Skip to content

Commit

Permalink
Merge pull request #452 from slang25/master
Browse files Browse the repository at this point in the history
Update cake build script for new tooling
  • Loading branch information
josephwoodward committed Aug 2, 2017
2 parents c487414 + 86d631c commit e0c2158
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ src/TestDiffTools/Main.approved.txt
tools/*
!tools/packages.config
artifacts/
src/*.Tests/report.xml
*.lock.json
*/.vscode
.vscode
Expand Down
2 changes: 1 addition & 1 deletion GitVersionConfig.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
next-version: 2.7.0
next-version: 3.0.0
67 changes: 43 additions & 24 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
#tool nuget:?package=GitVersion.CommandLine

var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var shouldlyProj = "./src/Shouldly/Shouldly.csproj";
var outputDir = "./artifacts/";
var isAppVeyor = BuildSystem.IsRunningOnAppVeyor;
var isWindows = IsRunningOnWindows();

Task("Clean")
.Does(() => {
Expand All @@ -15,67 +18,83 @@ Task("Clean")

Task("Restore")
.Does(() => {
NuGetRestore("./src/Shouldly.sln");
DotNetCoreRestore("./src/Shouldly.sln", new DotNetCoreRestoreSettings{
Verbosity = DotNetCoreVerbosity.Minimal,
});
});

GitVersion versionInfo = null;
DotNetCoreMSBuildSettings msBuildSettings = null;

Task("Version")
.Does(() => {
GitVersion(new GitVersionSettings{
UpdateAssemblyInfo = false,
OutputType = GitVersionOutput.BuildServer
});
versionInfo = GitVersion(new GitVersionSettings{ OutputType = GitVersionOutput.Json });
// Update project.json
var updatedProjectJson = System.IO.File.ReadAllText(shouldlyProj)
.Replace("1.0.0-*", versionInfo.NuGetVersion);
System.IO.File.WriteAllText(shouldlyProj, updatedProjectJson);
msBuildSettings = new DotNetCoreMSBuildSettings()
.WithProperty("Version", versionInfo.NuGetVersion)
.WithProperty("AssemblyVersion", versionInfo.AssemblySemVer)
.WithProperty("FileVersion", versionInfo.AssemblySemVer);
});

Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Version")
.IsDependentOn("Restore")
.Does(() => {
MSBuild("./src/Shouldly.sln");
DotNetCoreBuild("./src/Shouldly.sln", new DotNetCoreBuildSettings()
{
Configuration = configuration,
MSBuildSettings = msBuildSettings
});
});

Task("Test")
.IsDependentOn("Build")
.Does(() => {
DotNetCoreTest("./src/Shouldly.Tests/Shouldly.Tests.csproj");
DotNetCoreTool("./src/Shouldly.Tests/Shouldly.Tests.csproj", "xunit", "-configuration Debug");
});

Task("Package")
.IsDependentOn("Test")
.Does(() => {
DotNetCorePack(shouldlyProj, new DotNetCorePackSettings
{
Configuration = configuration,
OutputDirectory = outputDir,
MSBuildSettings = msBuildSettings
});
if (!isWindows) return;
// TODO not sure why this isn't working
// GitReleaseNotes("outputDir/releasenotes.md", new GitReleaseNotesSettings {
// WorkingDirectory = ".",
// AllTags = false
// });
// var releaseNotesExitCode = StartProcess(
// @"tools\GitReleaseNotes\tools\gitreleasenotes.exe",
// new ProcessSettings { Arguments = ". /o artifacts/releasenotes.md" });
// if (string.IsNullOrEmpty(System.IO.File.ReadAllText("./artifacts/releasenotes.md")))
// System.IO.File.WriteAllText("./artifacts/releasenotes.md", "No issues closed since last release");
var releaseNotesExitCode = StartProcess(
@"tools\GitReleaseNotes\tools\gitreleasenotes.exe",
new ProcessSettings { Arguments = ". /o artifacts/releasenotes.md" });
if (string.IsNullOrEmpty(System.IO.File.ReadAllText("./artifacts/releasenotes.md")))
System.IO.File.WriteAllText("./artifacts/releasenotes.md", "No issues closed since last release");
// if (releaseNotesExitCode != 0) throw new Exception("Failed to generate release notes");
if (releaseNotesExitCode != 0) throw new Exception("Failed to generate release notes");
// System.IO.File.WriteAllLines(outputDir + "artifacts", new[]{
// "nuget:Shouldly." + versionInfo.NuGetVersion + ".nupkg",
// "nugetSymbols:Shouldly." + versionInfo.NuGetVersion + ".symbols.nupkg",
// "releaseNotes:releasenotes.md"
// });
System.IO.File.WriteAllLines(outputDir + "artifacts", new[]{
"nuget:Shouldly." + versionInfo.NuGetVersion + ".nupkg",
"nugetSymbols:Shouldly." + versionInfo.NuGetVersion + ".symbols.nupkg",
"releaseNotes:releasenotes.md"
});
// if (AppVeyor.IsRunningOnAppVeyor)
// {
// foreach (var file in GetFiles(outputDir + "**/*"))
// AppVeyor.UploadArtifact(file.FullPath);
// }
if (isAppVeyor)
{
foreach (var file in GetFiles(outputDir + "**/*"))
AppVeyor.UploadArtifact(file.FullPath);
}
});

Task("Default")
Expand Down
54 changes: 49 additions & 5 deletions deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ http://cakebuild.net
Param(
[string]$Script = "deploy.cake",
[string]$Target = "Default",
[ValidateSet("Release", "Debug")]
[string]$Configuration = "Release",
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Verbose",
Expand All @@ -54,14 +55,43 @@ Param(
[string[]]$ScriptArgs
)

[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
function MD5HashFile([string] $filePath)
{
if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
{
return $null
}

[System.IO.Stream] $file = $null;
[System.Security.Cryptography.MD5] $md5 = $null;
try
{
$md5 = [System.Security.Cryptography.MD5]::Create()
$file = [System.IO.File]::OpenRead($filePath)
return [System.BitConverter]::ToString($md5.ComputeHash($file))
}
finally
{
if ($file -ne $null)
{
$file.Dispose()
}
}
}

Write-Host "Preparing to run build script..."

$PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition;
if(!$PSScriptRoot){
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}

$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
$NUGET_URL = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"

# Should we use mono?
$UseMono = "";
Expand Down Expand Up @@ -92,15 +122,15 @@ if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
# Make sure that packages.config exist.
if (!(Test-Path $PACKAGES_CONFIG)) {
Write-Verbose -Message "Downloading packages.config..."
try { Invoke-WebRequest -Uri http://cakebuild.net/download/bootstrapper/packages -OutFile $PACKAGES_CONFIG } catch {
try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
Throw "Could not download packages.config."
}
}

# Try find NuGet.exe in path if not exists
if (!(Test-Path $NUGET_EXE)) {
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) }
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) }
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
Expand All @@ -125,11 +155,25 @@ $ENV:NUGET_EXE = $NUGET_EXE
if(-Not $SkipToolPackageRestore.IsPresent) {
Push-Location
Set-Location $TOOLS_DIR

# Check for changes in packages.config and remove installed tools if true.
[string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
Write-Verbose -Message "Missing or changed package.config hash..."
Remove-Item * -Recurse -Exclude packages.config,nuget.exe
}

Write-Verbose -Message "Restoring tools from NuGet..."
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""

if ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring NuGet tools."
}
else
{
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
}
Write-Verbose -Message ($NuGetOutput | out-string)
Pop-Location
}
Expand All @@ -142,4 +186,4 @@ if (!(Test-Path $CAKE_EXE)) {
# Start Cake
Write-Host "Running build script..."
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
exit $LASTEXITCODE
exit $LASTEXITCODE
5 changes: 3 additions & 2 deletions src/Shouldly.Tests/Shouldly.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.3.0-beta3-build3705" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta3-build3705" />
<PackageReference Include="PublicApiGenerator" Version="4.0.1" />
<PackageReference Include="TestStack.ConventionTests" Version="3.0.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta3-build3705" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
Expand Down
16 changes: 11 additions & 5 deletions src/Shouldly/Shouldly.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Shouldly - Assertion framework for .NET. The way asserting *Should* be</Description>
<TargetFrameworks>net451;net40;netstandard1.3</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3</TargetFrameworks>
<AssemblyName>Shouldly</AssemblyName>
<PackageId>Shouldly</PackageId>
<PackageTags>test;unit;testing;TDD;AAA;should;testunit;rspec;assert;assertion;framework</PackageTags>
<PackageIconUrl>https://raw.github.com/shouldly/shouldly/master/Icons/package_icon.png</PackageIconUrl>
<PackageProjectUrl>http://shouldly.github.com</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/shouldly/shouldly/blob/master/LICENSE.txt</PackageLicenseUrl>
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<IncludeSymbols>True</IncludeSymbols>
<IncludeSource>True</IncludeSource>
<ComVisible>false</ComVisible>
<IncludeSymbols>true</IncludeSymbols>
<IncludeSource>true</IncludeSource>
<AssemblyOriginatorKeyFile>sn.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
Expand All @@ -26,17 +27,22 @@
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net40' ">
<DefineConstants>$(DefineConstants);ShouldMatchApproved;StackTrace;Serializable;CallerMemberNamePolyfill</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net451' ">
<DefineConstants>$(DefineConstants);ShouldMatchApproved;StackTrace;Serializable</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<DefineConstants>$(DefineConstants);NewReflection;ExpressionTrees</DefineConstants>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion tools/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.19.3" />
<package id="Cake" version="0.21.0" />
</packages>

0 comments on commit e0c2158

Please sign in to comment.