forked from adamhathcock/sharpcompress
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First pass of Cake build * Update Cake but still need cake itself to run on full CLR * Test out appveyor * 3.5 build fix * Build master and PRs differently. Still scared to auto publish to nuget.
- Loading branch information
1 parent
06e3486
commit 899d7d6
Showing
4 changed files
with
397 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# configuration for "master" branch | ||
- | ||
version: '0.13.{build}' | ||
|
||
init: | ||
- git config --global core.autocrlf true | ||
|
||
branches: | ||
only: | ||
- master | ||
|
||
build_script: | ||
- ps: .\build.ps1 | ||
|
||
test: off | ||
|
||
cache: | ||
- tools -> build.cake | ||
- tools -> build.ps1 | ||
|
||
# configuration for "default" branch | ||
- | ||
init: | ||
- git config --global core.autocrlf true | ||
|
||
build_script: | ||
- ps: .\build.ps1 | ||
|
||
test: off | ||
|
||
cache: | ||
- tools -> build.cake | ||
- tools -> build.ps1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
#addin "Cake.Json" | ||
|
||
#addin "nuget:?package=NuGet.Core" | ||
|
||
using NuGet; | ||
|
||
|
||
////////////////////////////////////////////////////////////////////// | ||
// ARGUMENTS | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
var target = Argument("target", "Default"); | ||
var apiKey = Argument("apiKey", ""); | ||
var repo = Argument("repo", ""); | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// PREPARATION | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
var sources = new [] { "https://api.nuget.org/v3/index.json" }; | ||
var publishTarget = ""; | ||
|
||
Warning("============="); | ||
var globalPath = MakeFullPath("global.json"); | ||
var nupkgs = MakeFullPath("nupkgs"); | ||
Warning("Operating on global.json: " + globalPath); | ||
Warning("============="); | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// FUNCTIONS | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
string MakeFullPath(string relativePath) | ||
{ | ||
if (string.IsNullOrEmpty(repo)) | ||
{ | ||
return MakeAbsolute(new DirectoryPath(relativePath)).ToString(); | ||
} | ||
if (!System.IO.Path.IsPathRooted(repo)) | ||
{ | ||
return MakeAbsolute(new DirectoryPath(System.IO.Path.Combine(repo,relativePath))).ToString(); | ||
} | ||
return System.IO.Path.Combine(repo, relativePath); | ||
} | ||
|
||
IEnumerable<string> GetAllProjects() | ||
{ | ||
var global = DeserializeJsonFromFile<JObject>(globalPath); | ||
var projs = global["projects"].Select(x => x.ToString()); | ||
foreach(var y in projs) | ||
{ | ||
yield return MakeFullPath(y); | ||
} | ||
} | ||
|
||
IEnumerable<string> GetSourceProjects() | ||
{ | ||
return GetAllProjects().Where(x => x.EndsWith("src")); | ||
} | ||
|
||
IEnumerable<string> GetTestProjects() | ||
{ | ||
return GetAllProjects().Where(x => x.EndsWith("test")); | ||
} | ||
|
||
IEnumerable<string> GetFrameworks(string path) | ||
{ | ||
var projectJObject = DeserializeJsonFromFile<JObject>(path); | ||
foreach(var prop in ((JObject)projectJObject["frameworks"]).Properties()) | ||
{ | ||
yield return prop.Name; | ||
} | ||
} | ||
|
||
string GetVersion(string path) | ||
{ | ||
var projectJObject = DeserializeJsonFromFile<JObject>(path); | ||
return ((JToken)projectJObject["version"]).ToString(); | ||
} | ||
|
||
IEnumerable<string> GetProjectJsons(IEnumerable<string> projects) | ||
{ | ||
foreach(var proj in projects) | ||
{ | ||
foreach(var projectJson in GetFiles(proj + "/**/project.json")) | ||
{ | ||
yield return MakeFullPath(projectJson.ToString()); | ||
} | ||
} | ||
} | ||
|
||
bool IsNuGetPublished (FilePath file, string nugetSource) | ||
{ | ||
var pkg = new ZipPackage(file.ToString()); | ||
|
||
var repo = PackageRepositoryFactory.Default.CreateRepository(nugetSource); | ||
|
||
var packages = repo.FindPackagesById(pkg.Id); | ||
|
||
var version = SemanticVersion.Parse(pkg.Version.ToString()); | ||
|
||
//Filter the list of packages that are not Release (Stable) versions | ||
var exists = packages.Any (p => p.Version == version); | ||
|
||
return exists; | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// TASKS | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
Task("Restore") | ||
.Does(() => | ||
{ | ||
var settings = new DotNetCoreRestoreSettings | ||
{ | ||
Sources = sources, | ||
NoCache = true | ||
}; | ||
|
||
foreach(var project in GetProjectJsons(GetSourceProjects().Concat(GetTestProjects()))) | ||
{ | ||
DotNetCoreRestore(project, settings); | ||
} | ||
}); | ||
|
||
Task("Build") | ||
.Does(() => | ||
{ | ||
var settings = new DotNetCoreBuildSettings | ||
{ | ||
Configuration = "Release" | ||
}; | ||
|
||
foreach(var project in GetProjectJsons(GetSourceProjects().Concat(GetTestProjects()))) | ||
{ | ||
foreach(var framework in GetFrameworks(project)) | ||
{ | ||
Information("Building: {0} on Framework: {1}", project, framework); | ||
Information("========"); | ||
settings.Framework = framework; | ||
DotNetCoreBuild(project, settings); | ||
} | ||
} | ||
}); | ||
|
||
Task("Test") | ||
.Does(() => | ||
{ | ||
var settings = new DotNetCoreTestSettings | ||
{ | ||
Configuration = "Release", | ||
Verbose = true | ||
}; | ||
|
||
foreach(var project in GetProjectJsons(GetTestProjects())) | ||
{ | ||
settings.Framework = GetFrameworks(project).First(); | ||
DotNetCoreTest(project.ToString(), settings); | ||
} | ||
|
||
}).ReportError(exception => | ||
{ | ||
Error(exception.ToString()); | ||
}); | ||
|
||
Task("Pack") | ||
.Does(() => | ||
{ | ||
if (DirectoryExists(nupkgs)) | ||
{ | ||
DeleteDirectory(nupkgs, true); | ||
} | ||
CreateDirectory(nupkgs); | ||
|
||
var settings = new DotNetCorePackSettings | ||
{ | ||
Configuration = "Release", | ||
OutputDirectory = nupkgs | ||
}; | ||
|
||
foreach(var project in GetProjectJsons(GetSourceProjects())) | ||
{ | ||
DotNetCorePack(project, settings); | ||
} | ||
}); | ||
|
||
Task("Publish") | ||
.Does(() => | ||
{ | ||
var packages = GetFiles(nupkgs + "/*.nupkg"); | ||
foreach(var package in packages) | ||
{ | ||
if (package.ToString().Contains("symbols")) | ||
{ | ||
Warning("Skipping Symbols package " + package); | ||
continue; | ||
} | ||
if (IsNuGetPublished(package, sources[1])) | ||
{ | ||
throw new InvalidOperationException(package + " is already published."); | ||
} | ||
NuGetPush(package, new NuGetPushSettings{ | ||
ApiKey = apiKey, | ||
Verbosity = NuGetVerbosity.Detailed, | ||
Source = publishTarget | ||
}); | ||
} | ||
}); | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// TASK TARGETS | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
Task("PRBuild") | ||
.IsDependentOn("Restore") | ||
.IsDependentOn("Build") | ||
.IsDependentOn("Test"); | ||
|
||
Task("MasterBuild") | ||
.IsDependentOn("Restore") | ||
.IsDependentOn("Build") | ||
.IsDependentOn("Test") | ||
.IsDependentOn("Pack"); | ||
|
||
Task("Default") | ||
.IsDependentOn("PRBuild"); | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// EXECUTION | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
RunTarget(target); |
Oops, something went wrong.