This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
77 lines (64 loc) · 2.31 KB
/
build.cake
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
#addin "nuget:?package=Cake.Git&version=3.0.0"
#addin "nuget:?package=Newtonsoft.Json&version=11.0.2"
using Cake.Git;
using Newtonsoft.Json;
using System;
using System.IO;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Test");
var solutionFolder = "./";
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Restore")
.Does(() => {
DotNetRestore();
});
Task("Build")
.IsDependentOn("Restore")
.Does(() => {
DotNetBuild(solutionFolder, new DotNetBuildSettings
{
NoRestore = true,
Configuration = configuration
});
});
Task("Generate Build Info")
.IsDependentOn("Build")
.Does((cakeContext) => {
var lastCommit = ((ICakeContext)cakeContext).GitLogTip("./");
var repoPath = DirectoryPath.FromString(".");
var currentBranch = ((ICakeContext)cakeContext).GitBranchCurrent(repoPath);
var timeZone = TimeZoneInfo.Local;
var gitHash = lastCommit.Sha?.Substring(0,7) ?? "";
var buildDate = DateTime.Now;
var buildName = $"{currentBranch.FriendlyName}:{gitHash}";
var data = new { buildInfo = new {
buildName,
hash = gitHash,
branch = currentBranch.FriendlyName,
buildDate = buildDate.ToString("yyy-MM-dd HH:mm") + timeZone.DisplayName
}};
var json = JsonConvert.SerializeObject(data);
var outputPath = "./ToffApi";
var fileName = "buildinfo.json";
var filePath = System.IO.Path.Combine(outputPath, fileName);
System.IO.File.WriteAllText(filePath, json);
});
Task("Test")
.IsDependentOn("Build")
.IsDependentOn("Generate Build Info")
.Does(() => {
DotNetTest(solutionFolder, new DotNetTestSettings{
NoRestore = true,
Configuration = configuration,
NoBuild = true
});
});
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);