|
| 1 | +#tool "nuget:?package=xunit.runner.console&version=2.3.0-beta5-build3769" |
| 2 | + |
| 3 | +#addin "nuget:?package=NuGet.Core" |
| 4 | +#addin "nuget:?package=Cake.ExtendedNuGet" |
| 5 | + |
| 6 | +////////////////////////////////////////////////////////////////////// |
| 7 | +// ARGUMENTS |
| 8 | +////////////////////////////////////////////////////////////////////// |
| 9 | + |
| 10 | +var projectName = "Abp"; |
| 11 | +var solution = "./" + projectName + ".sln"; |
| 12 | + |
| 13 | +var target = Argument("target", "Default"); |
| 14 | +var configuration = Argument("configuration", "Release"); |
| 15 | +var toolpath = Argument("toolpath", @"tools"); |
| 16 | +var branch = Argument("branch", EnvironmentVariable("APPVEYOR_REPO_BRANCH")); |
| 17 | +var nugetApiKey = EnvironmentVariable("nugetApiKey"); |
| 18 | + |
| 19 | +var testProjects = new List<Tuple<string, string[]>> |
| 20 | + { |
| 21 | + new Tuple<string, string[]>("Abp.AspNetCore.Tests", new[] { "net461", "netcoreapp2.0" }), |
| 22 | + new Tuple<string, string[]>("Abp.AutoMapper.Tests", new[] { "net461", "netcoreapp2.0" }), |
| 23 | + new Tuple<string, string[]>("Abp.Castle.Log4Net.Tests", new[] { "net461", "netcoreapp2.0" }), |
| 24 | + new Tuple<string, string[]>("Abp.Dapper.NHibernate.Tests", new[] { "net461"}), |
| 25 | + new Tuple<string, string[]>("Abp.Dapper.Tests", new[] { "net461" }), |
| 26 | + new Tuple<string, string[]>("Abp.EntityFramework.GraphDiff.Tests", new[] { "net461" }), |
| 27 | + new Tuple<string, string[]>("Abp.EntityFramework.Tests", new[] { "net461" }), |
| 28 | + new Tuple<string, string[]>("Abp.EntityFrameworkCore.Dapper.Tests", new[] { "netcoreapp2.0" }), |
| 29 | + new Tuple<string, string[]>("Abp.EntityFrameworkCore.Tests", new[] { "net461", "netcoreapp2.0" }), |
| 30 | + new Tuple<string, string[]>("Abp.MailKit.Tests", new[] { "net461", "netcoreapp2.0" }), |
| 31 | + new Tuple<string, string[]>("Abp.MemoryDb.Tests", new[] { "net461", "netcoreapp2.0" }), |
| 32 | + new Tuple<string, string[]>("Abp.NHibernate.Tests", new[] { "net461" }), |
| 33 | + new Tuple<string, string[]>("Abp.Quartz.Tests", new[] { "net461" }), |
| 34 | + new Tuple<string, string[]>("Abp.RedisCache.Tests", new[] { "net461", "netcoreapp2.0" }), |
| 35 | + new Tuple<string, string[]>("Abp.TestBase.SampleApplication.Tests", new[] { "net461" }), |
| 36 | + new Tuple<string, string[]>("Abp.Tests", new[] { "net461", "netcoreapp2.0" }), |
| 37 | + new Tuple<string, string[]>("Abp.Web.Api.Tests", new[] { "net461" }), |
| 38 | + new Tuple<string, string[]>("Abp.Web.Common.Tests", new[] { "net461", "netcoreapp2.0" }), |
| 39 | + new Tuple<string, string[]>("Abp.Web.Mvc.Tests", new[] { "net461" }), |
| 40 | + new Tuple<string, string[]>("Abp.Web.Tests", new[] { "net461" }), |
| 41 | + new Tuple<string, string[]>("Abp.Zero.SampleApp.NHibernateTests", new[] { "net461" }), |
| 42 | + new Tuple<string, string[]>("Abp.Zero.SampleApp.Tests", new[] { "net461" }), |
| 43 | + new Tuple<string, string[]>("Abp.ZeroCore.Tests", new[] { "netcoreapp2.0" }), |
| 44 | + new Tuple<string, string[]>("Abp.ZeroCore.IdentityServer4.Tests", new[] { "netcoreapp2.0" }) |
| 45 | + }; |
| 46 | + |
| 47 | + |
| 48 | +var nupkgPath = "nupkg"; |
| 49 | +var nupkgRegex = $"**/{projectName}*.nupkg"; |
| 50 | +var nugetPath = toolpath + "/nuget.exe"; |
| 51 | +var nugetQueryUrl = "https://www.nuget.org/api/v2/"; |
| 52 | +var nugetPushUrl = "https://www.nuget.org/api/v2/package"; |
| 53 | +var NUGET_PUSH_SETTINGS = new NuGetPushSettings |
| 54 | + { |
| 55 | + ToolPath = File(nugetPath), |
| 56 | + Source = nugetPushUrl, |
| 57 | + ApiKey = nugetApiKey |
| 58 | + }; |
| 59 | + |
| 60 | +////////////////////////////////////////////////////////////////////// |
| 61 | +// TASKS |
| 62 | +////////////////////////////////////////////////////////////////////// |
| 63 | + |
| 64 | +Task("Clean") |
| 65 | + .Does(() => |
| 66 | + { |
| 67 | + Information("Current Branch is:" + EnvironmentVariable("APPVEYOR_REPO_BRANCH")); |
| 68 | + CleanDirectories("./src/**/bin"); |
| 69 | + CleanDirectories("./src/**/obj"); |
| 70 | + CleanDirectories("./test/**/bin"); |
| 71 | + CleanDirectories("./test/**/obj"); |
| 72 | + CleanDirectory(nupkgPath); |
| 73 | + }); |
| 74 | + |
| 75 | +Task("Restore-NuGet-Packages") |
| 76 | + .IsDependentOn("Clean") |
| 77 | + .Does(() => |
| 78 | + { |
| 79 | + DotNetCoreRestore(solution); |
| 80 | + }); |
| 81 | + |
| 82 | +Task("Build") |
| 83 | + .IsDependentOn("Restore-NuGet-Packages") |
| 84 | + .Does(() => |
| 85 | + { |
| 86 | + MSBuild(solution, new MSBuildSettings(){Configuration = configuration} |
| 87 | + .WithProperty("SourceLinkCreate","true")); |
| 88 | + }); |
| 89 | + |
| 90 | +Task("Run-Unit-Tests") |
| 91 | + .IsDependentOn("Build") |
| 92 | + .Does(() => |
| 93 | + { |
| 94 | + foreach (Tuple<string, string[]> testProject in testProjects) |
| 95 | + { |
| 96 | + foreach (string targetFramework in testProject.Item2) |
| 97 | + { |
| 98 | + Information($"Test execution started for target frameowork: {targetFramework}..."); |
| 99 | + var testProj = GetFiles($"./test/**/*{testProject.Item1}.csproj").First(); |
| 100 | + DotNetCoreTest(testProj.FullPath, new DotNetCoreTestSettings { Configuration = "Release", Framework = targetFramework }); |
| 101 | + } |
| 102 | + } |
| 103 | + }); |
| 104 | + |
| 105 | +Task("Pack") |
| 106 | + .IsDependentOn("Run-Unit-Tests") |
| 107 | + .Does(() => |
| 108 | + { |
| 109 | + var nupkgFiles = GetFiles(nupkgRegex); |
| 110 | + MoveFiles(nupkgFiles, nupkgPath); |
| 111 | + }); |
| 112 | + |
| 113 | +Task("NugetPublish") |
| 114 | + .IsDependentOn("Pack") |
| 115 | + .WithCriteria(() => branch == "master") |
| 116 | + .Does(()=> |
| 117 | + { |
| 118 | + foreach(var nupkgFile in GetFiles(nupkgRegex)) |
| 119 | + { |
| 120 | + if(!IsNuGetPublished(nupkgFile, nugetQueryUrl)) |
| 121 | + { |
| 122 | + Information("Publishing... " + nupkgFile); |
| 123 | + NuGetPush(nupkgFile, NUGET_PUSH_SETTINGS); |
| 124 | + } |
| 125 | + else |
| 126 | + { |
| 127 | + Information("Already published, skipping... " + nupkgFile); |
| 128 | + } |
| 129 | + } |
| 130 | + }); |
| 131 | + |
| 132 | +////////////////////////////////////////////////////////////////////// |
| 133 | +// TASK TARGETS |
| 134 | +////////////////////////////////////////////////////////////////////// |
| 135 | + |
| 136 | +Task("Default") |
| 137 | + .IsDependentOn("Build") |
| 138 | + .IsDependentOn("Run-Unit-Tests") |
| 139 | + .IsDependentOn("Pack") |
| 140 | + .IsDependentOn("NugetPublish"); |
| 141 | + |
| 142 | +////////////////////////////////////////////////////////////////////// |
| 143 | +// EXECUTION |
| 144 | +////////////////////////////////////////////////////////////////////// |
| 145 | + |
| 146 | +RunTarget(target); |
0 commit comments