-
Notifications
You must be signed in to change notification settings - Fork 22
/
Nake.csx
92 lines (73 loc) · 2.85 KB
/
Nake.csx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#r "System.Net.WebClient"
#r "nuget: Nake.Meta, 3.0.0"
#r "nuget: Nake.Utility, 3.0.0"
using System.IO;
using System.Text;
using System.Net;
using System.Linq;
using System.Diagnostics;
using Nake;
using static Nake.FS;
using static Nake.Log;
using static Nake.Env;
var RootPath = "%NakeScriptDirectory%";
var ArtifactsPath = $"{RootPath}/Artifacts";
var ReleasePackagesPath = $"{ArtifactsPath}/Release";
var AppVeyorJobId = Var["APPVEYOR_JOB_ID"];
var TargetFramework = "net8";
var Version = "3.0.0-dev";
// global init
MakeDir(ArtifactsPath);
/// Restores packages and builds sources in Debug mode
[Nake] async Task Default() => await Build();
/// Builds sources using specified configuration
[Nake] async Task Build(string config = "Debug", bool verbose = false) => await
$@"dotnet build {RootPath}/Nake.sln \
/p:Configuration={config} {(verbose ? "/v:d" : "")}";
/// Runs unit tests
[Nake] async Task Test(bool slow = false)
{
await Build("Debug");
var tests = new FileSet{$"{RootPath}/**/bin/Debug/{TargetFramework}/*.Tests.dll"}.ToString(" ");
var results = $@"{ArtifactsPath}/nunit-test-results.xml";
try
{
await $@"dotnet vstest {tests} --logger:trx;LogFileName={results} \
{(AppVeyorJobId != null||slow ? "" : "--TestCaseFilter:TestCategory!=Slow")}";
}
finally
{
if (AppVeyorJobId != null)
{
var workerApi = $"https://ci.appveyor.com/api/testresults/mstest/{AppVeyorJobId}";
Info($"Uploading {results} to {workerApi} using job id {AppVeyorJobId} ...");
var response = new WebClient().UploadFile(workerApi, results);
var result = Encoding.UTF8.GetString(response);
Info($"Appveyor response is: {result}");
}
}
}
/// Builds official NuGet packages
[Nake] async Task Pack(bool skipFullCheck = false)
{
await Test(!skipFullCheck);
var versionFile = $"{RootPath}/Source/AssemblyVersion.cs";
await File.WriteAllTextAsync(versionFile,
$@"[assembly:System.Reflection.AssemblyInformationalVersion(""{Version}"")]");
await $"dotnet pack -c Release -p:PackageVersion={Version} Nake.sln";
await $"git checkout {versionFile}";
}
/// Publishes package to NuGet gallery
[Nake] async Task Publish() => await
$@"dotnet nuget push {ReleasePackagesPath}/**/*.{Version}.nupkg \
-k %NuGetApiKey% -s https://nuget.org/ --skip-duplicate";
/// Unlists nake packages from Nuget.org
[Nake] async Task Unlist()
{
await Delete("Nake");
await Delete("Nake.Utility");
await Delete("Nake.Meta");
async Task Delete(string package) => await
$@"dotnet nuget delete {package} {Version} \
-k %NuGetApiKey% -s https://nuget.org/ --non-interactive";
}