369 строки
12 KiB
C#
369 строки
12 KiB
C#
///////////////////////////////////////////////////////////////////////////////
|
|
// ADDINS
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#addin "nuget:?package=Polly&version=5.3.1"
|
|
#addin "nuget:?package=NuGet.Core&version=2.14.0"
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// TOOLS
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#tool "nuget:?package=NuGet.CommandLine&version=4.3.0"
|
|
#tool "nuget:?package=xunit.runner.console&version=2.3.1"
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// USINGS
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Polly;
|
|
using NuGet;
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// ARGUMENTS
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
var target = Argument("target", "Default");
|
|
var platform = Argument("platform", "Any CPU");
|
|
var configuration = Argument("configuration", "Release");
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// CONFIGURATION
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
var MainRepo = "wieslawsoltes/SimpleWavSplitter";
|
|
var MasterBranch = "master";
|
|
var AssemblyInfoPath = File("./src/Shared/SharedAssemblyInfo.cs");
|
|
var ReleasePlatform = "Any CPU";
|
|
var ReleaseConfiguration = "Release";
|
|
var MSBuildSolution = "./SimpleWavSplitter.sln";
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// PARAMETERS
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
var isPlatformAnyCPU = StringComparer.OrdinalIgnoreCase.Equals(platform, "Any CPU");
|
|
var isPlatformX86 = StringComparer.OrdinalIgnoreCase.Equals(platform, "x86");
|
|
var isPlatformX64 = StringComparer.OrdinalIgnoreCase.Equals(platform, "x64");
|
|
var isLocalBuild = BuildSystem.IsLocalBuild;
|
|
var isRunningOnUnix = IsRunningOnUnix();
|
|
var isRunningOnWindows = IsRunningOnWindows();
|
|
var isRunningOnAppVeyor = BuildSystem.AppVeyor.IsRunningOnAppVeyor;
|
|
var isPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest;
|
|
var isMainRepo = StringComparer.OrdinalIgnoreCase.Equals(MainRepo, BuildSystem.AppVeyor.Environment.Repository.Name);
|
|
var isMasterBranch = StringComparer.OrdinalIgnoreCase.Equals(MasterBranch, BuildSystem.AppVeyor.Environment.Repository.Branch);
|
|
var isTagged = BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag
|
|
&& !string.IsNullOrWhiteSpace(BuildSystem.AppVeyor.Environment.Repository.Tag.Name);
|
|
var isReleasable = StringComparer.OrdinalIgnoreCase.Equals(ReleasePlatform, platform)
|
|
&& StringComparer.OrdinalIgnoreCase.Equals(ReleaseConfiguration, configuration);
|
|
var isMyGetRelease = !isTagged && isReleasable;
|
|
var isNuGetRelease = isTagged && isReleasable;
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// VERSION
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
var version = ParseAssemblyInfo(AssemblyInfoPath).AssemblyVersion;
|
|
|
|
if (isRunningOnAppVeyor)
|
|
{
|
|
if (isTagged)
|
|
{
|
|
// Use Tag Name as version
|
|
version = BuildSystem.AppVeyor.Environment.Repository.Tag.Name;
|
|
}
|
|
else
|
|
{
|
|
// Use AssemblyVersion with Build as version
|
|
version += "-build" + EnvironmentVariable("APPVEYOR_BUILD_NUMBER") + "-alpha";
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// DIRECTORIES
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
var artifactsDir = (DirectoryPath)Directory("./artifacts");
|
|
var testResultsDir = artifactsDir.Combine("test-results");
|
|
var nugetRoot = artifactsDir.Combine("nuget");
|
|
var dirSuffix = isPlatformAnyCPU ? configuration : platform + "/" + configuration;
|
|
var buildDirs =
|
|
GetDirectories("./src/**/bin/**") +
|
|
GetDirectories("./src/**/obj/**") +
|
|
GetDirectories("./samples/**/bin/**") +
|
|
GetDirectories("./samples/**/obj/**") +
|
|
GetDirectories("./tests/**/bin/**") +
|
|
GetDirectories("./tests/**/obj/**");
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// NUGET NUSPECS
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
var nuspecNuGetWavFile = new NuGetPackSettings()
|
|
{
|
|
Id = "WavFile",
|
|
Version = version,
|
|
Authors = new [] { "wieslawsoltes" },
|
|
Owners = new [] { "wieslawsoltes" },
|
|
LicenseUrl = new Uri("http://opensource.org/licenses/MIT"),
|
|
ProjectUrl = new Uri("https://github.com/wieslawsoltes/SimpleWavSplitter/"),
|
|
RequireLicenseAcceptance = false,
|
|
Symbols = false,
|
|
NoPackageAnalysis = true,
|
|
Description = "Split multi-channel WAV files into single channel WAV files.",
|
|
Copyright = "Copyright 2016",
|
|
Tags = new [] { "Wav", "Audio", "Splitter", "Multi-channel", "Managed", "C#" },
|
|
Dependencies = new []
|
|
{
|
|
// netstandard1.3
|
|
new NuSpecDependency { Id = "System.IO.FileSystem", TargetFramework = "netstandard1.3", Version = "4.3.0" }
|
|
},
|
|
Files = new []
|
|
{
|
|
// netstandard1.3
|
|
new NuSpecContent { Source = "src/WavFile/bin/" + dirSuffix + "/netstandard1.3/" + "WavFile.dll", Target = "lib/netstandard1.3" },
|
|
new NuSpecContent { Source = "src/WavFile/bin/" + dirSuffix + "/netstandard1.3/" + "WavFile.xml", Target = "lib/netstandard1.3" },
|
|
// net45
|
|
new NuSpecContent { Source = "src/WavFile/bin/" + dirSuffix + "/net45/" + "WavFile.dll", Target = "lib/net45" },
|
|
new NuSpecContent { Source = "src/WavFile/bin/" + dirSuffix + "/net45/" + "WavFile.xml", Target = "lib/net45" }
|
|
},
|
|
BasePath = Directory("./"),
|
|
OutputDirectory = nugetRoot
|
|
};
|
|
|
|
var nuspecNuGetSettings = new List<NuGetPackSettings>();
|
|
|
|
nuspecNuGetSettings.Add(nuspecNuGetWavFile);
|
|
|
|
var nugetPackages = nuspecNuGetSettings.Select(nuspec => {
|
|
return nuspec.OutputDirectory.CombineWithFilePath(string.Concat(nuspec.Id, ".", nuspec.Version, ".nupkg"));
|
|
}).ToArray();
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// INFORMATION
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
Information("Building version {0} of SimpleWavSplitter ({1}, {2}, {3}) using version {4} of Cake.",
|
|
version,
|
|
platform,
|
|
configuration,
|
|
target,
|
|
typeof(ICakeContext).Assembly.GetName().Version.ToString());
|
|
|
|
if (isRunningOnAppVeyor)
|
|
{
|
|
Information("Repository Name: " + BuildSystem.AppVeyor.Environment.Repository.Name);
|
|
Information("Repository Branch: " + BuildSystem.AppVeyor.Environment.Repository.Branch);
|
|
}
|
|
|
|
Information("Target: " + target);
|
|
Information("Platform: " + platform);
|
|
Information("Configuration: " + configuration);
|
|
Information("IsLocalBuild: " + isLocalBuild);
|
|
Information("IsRunningOnUnix: " + isRunningOnUnix);
|
|
Information("IsRunningOnWindows: " + isRunningOnWindows);
|
|
Information("IsRunningOnAppVeyor: " + isRunningOnAppVeyor);
|
|
Information("IsPullRequest: " + isPullRequest);
|
|
Information("IsMainRepo: " + isMainRepo);
|
|
Information("IsMasterBranch: " + isMasterBranch);
|
|
Information("IsTagged: " + isTagged);
|
|
Information("IsReleasable: " + isReleasable);
|
|
Information("IsMyGetRelease: " + isMyGetRelease);
|
|
Information("IsNuGetRelease: " + isNuGetRelease);
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// TASKS: VISUAL STUDIO
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
Task("Clean")
|
|
.Does(() =>
|
|
{
|
|
CleanDirectories(buildDirs);
|
|
CleanDirectory(artifactsDir);
|
|
CleanDirectory(testResultsDir);
|
|
CleanDirectory(nugetRoot);
|
|
});
|
|
|
|
Task("Restore-NuGet-Packages")
|
|
.IsDependentOn("Clean")
|
|
.Does(() =>
|
|
{
|
|
var maxRetryCount = 5;
|
|
var toolTimeout = 1d;
|
|
Policy
|
|
.Handle<Exception>()
|
|
.Retry(maxRetryCount, (exception, retryCount, context) => {
|
|
if (retryCount == maxRetryCount)
|
|
{
|
|
throw exception;
|
|
}
|
|
else
|
|
{
|
|
Verbose("{0}", exception);
|
|
toolTimeout+=0.5;
|
|
}})
|
|
.Execute(()=> {
|
|
NuGetRestore(MSBuildSolution, new NuGetRestoreSettings {
|
|
ToolTimeout = TimeSpan.FromMinutes(toolTimeout)
|
|
});
|
|
});
|
|
});
|
|
|
|
Task("Build")
|
|
.IsDependentOn("Restore-NuGet-Packages")
|
|
.Does(() =>
|
|
{
|
|
MSBuild(MSBuildSolution, settings => {
|
|
settings.SetConfiguration(configuration);
|
|
settings.WithProperty("Platform", "\"" + platform + "\"");
|
|
settings.SetVerbosity(Verbosity.Minimal);
|
|
});
|
|
});
|
|
|
|
Task("Run-Unit-Tests")
|
|
.IsDependentOn("Build")
|
|
.Does(() =>
|
|
{
|
|
string pattern = "./tests/**/bin/" + dirSuffix + "/*.UnitTests.dll";
|
|
XUnit2(pattern, new XUnit2Settings {
|
|
ToolPath = (isPlatformAnyCPU || isPlatformX86) ?
|
|
Context.Tools.Resolve("xunit.console.x86.exe") :
|
|
Context.Tools.Resolve("xunit.console.exe"),
|
|
OutputDirectory = testResultsDir,
|
|
XmlReportV1 = true,
|
|
NoAppDomain = true
|
|
});
|
|
});
|
|
|
|
Task("Create-NuGet-Packages")
|
|
.IsDependentOn("Run-Unit-Tests")
|
|
.Does(() =>
|
|
{
|
|
foreach(var nuspec in nuspecNuGetSettings)
|
|
{
|
|
NuGetPack(nuspec);
|
|
}
|
|
});
|
|
|
|
Task("Publish-MyGet")
|
|
.IsDependentOn("Create-NuGet-Packages")
|
|
.WithCriteria(() => !isLocalBuild)
|
|
.WithCriteria(() => !isPullRequest)
|
|
.WithCriteria(() => isMainRepo)
|
|
.WithCriteria(() => isMasterBranch)
|
|
.WithCriteria(() => isMyGetRelease)
|
|
.Does(() =>
|
|
{
|
|
var apiKey = EnvironmentVariable("MYGET_API_KEY");
|
|
if(string.IsNullOrEmpty(apiKey))
|
|
{
|
|
throw new InvalidOperationException("Could not resolve MyGet API key.");
|
|
}
|
|
|
|
var apiUrl = EnvironmentVariable("MYGET_API_URL");
|
|
if(string.IsNullOrEmpty(apiUrl))
|
|
{
|
|
throw new InvalidOperationException("Could not resolve MyGet API url.");
|
|
}
|
|
|
|
foreach(var nupkg in nugetPackages)
|
|
{
|
|
NuGetPush(nupkg, new NuGetPushSettings {
|
|
Source = apiUrl,
|
|
ApiKey = apiKey
|
|
});
|
|
}
|
|
})
|
|
.OnError(exception =>
|
|
{
|
|
Information("Publish-MyGet Task failed, but continuing with next Task...");
|
|
});
|
|
|
|
Task("Publish-NuGet")
|
|
.IsDependentOn("Create-NuGet-Packages")
|
|
.WithCriteria(() => !isLocalBuild)
|
|
.WithCriteria(() => !isPullRequest)
|
|
.WithCriteria(() => isMainRepo)
|
|
.WithCriteria(() => isMasterBranch)
|
|
.WithCriteria(() => isNuGetRelease)
|
|
.Does(() =>
|
|
{
|
|
var apiKey = EnvironmentVariable("NUGET_API_KEY");
|
|
if(string.IsNullOrEmpty(apiKey))
|
|
{
|
|
throw new InvalidOperationException("Could not resolve NuGet API key.");
|
|
}
|
|
|
|
var apiUrl = EnvironmentVariable("NUGET_API_URL");
|
|
if(string.IsNullOrEmpty(apiUrl))
|
|
{
|
|
throw new InvalidOperationException("Could not resolve NuGet API url.");
|
|
}
|
|
|
|
foreach(var nupkg in nugetPackages)
|
|
{
|
|
NuGetPush(nupkg, new NuGetPushSettings {
|
|
ApiKey = apiKey,
|
|
Source = apiUrl
|
|
});
|
|
}
|
|
})
|
|
.OnError(exception =>
|
|
{
|
|
Information("Publish-NuGet Task failed, but continuing with next Task...");
|
|
});
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// TASKS: .NET Core
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
Task("Restore-NetCore")
|
|
.IsDependentOn("Clean")
|
|
.Does(() =>
|
|
{
|
|
// TODO:
|
|
});
|
|
|
|
Task("Run-Unit-Tests-NetCore")
|
|
.IsDependentOn("Clean")
|
|
.Does(() =>
|
|
{
|
|
// TODO:
|
|
});
|
|
|
|
Task("Build-NetCore")
|
|
.IsDependentOn("Restore-NetCore")
|
|
.Does(() =>
|
|
{
|
|
// TODO:
|
|
});
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// TARGETS
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
Task("Package")
|
|
.IsDependentOn("Create-NuGet-Packages");
|
|
|
|
Task("Default")
|
|
.IsDependentOn("Package");
|
|
|
|
Task("AppVeyor")
|
|
.IsDependentOn("Run-Unit-Tests-NetCore")
|
|
.IsDependentOn("Build-NetCore")
|
|
.IsDependentOn("Publish-MyGet")
|
|
.IsDependentOn("Publish-NuGet");
|
|
|
|
Task("Travis")
|
|
.IsDependentOn("Run-Unit-Tests-NetCore")
|
|
.IsDependentOn("Build-NetCore");
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// EXECUTE
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
RunTarget(target);
|