forked from ChilliCream/graphql-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.cs
140 lines (121 loc) · 4.17 KB
/
Build.cs
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AzurePipelines;
using Nuke.Common.Execution;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Helpers;
using Newtonsoft.Json;
using Nuke.Common.ProjectModel;
using System.Linq;
using System;
using System.IO;
using Serilog;
[UnsetVisualStudioEnvironmentVariables]
partial class Build : NukeBuild
{
public static int Main() => Execute<Build>(x => x.Compile);
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly string Configuration = IsLocalBuild ? Debug : Release;
[CI] readonly AzurePipelines DevOpsPipeLine;
Target Clean => _ => _
.Before(Restore)
.Executes(() =>
{
});
Target Restore => _ => _
.Executes(() =>
{
DotNetBuildSonarSolution(AllSolutionFile);
DotNetRestore(c => c.SetProjectFile(AllSolutionFile));
});
Target Compile => _ => _
.DependsOn(Restore)
.Executes(() =>
{
if (!InvokedTargets.Contains(Restore))
{
DotNetBuildSonarSolution(AllSolutionFile);
}
DotNetBuild(c => c
.SetProjectFile(AllSolutionFile)
.SetNoRestore(InvokedTargets.Contains(Restore))
.SetConfiguration(Configuration)
.SetInformationalVersion(SemVersion)
.SetFileVersion(Version)
.SetAssemblyVersion(Version)
.SetVersion(SemVersion));
});
Target Reset => _ => _
.Executes(() =>
{
TryDelete(AllSolutionFile);
TryDelete(TestSolutionFile);
TryDelete(PackSolutionFile);
DotNetBuildSonarSolution(AllSolutionFile);
DotNetRestore(c => c.SetProjectFile(AllSolutionFile));
});
Target CreateAllSln => _ => _
.Executes(() =>
{
DotNetBuildSonarSolution(AllSolutionFile);
});
Target GenerateMatrix => _ => _
.Executes(() =>
{
DotNetBuildSonarSolution(AllSolutionFile);
var all = ProjectModelTasks.ParseSolution(AllSolutionFile);
var testProjects = all.GetProjects("*.Tests")
.Select(p => new TestProject
{
Name = Path.GetFileNameWithoutExtension(p.Path),
Path = Path.GetRelativePath(RootDirectory, p.Path)
})
.OrderBy(p => p.Name)
.ToList();
var matrix = new
{
include = testProjects.Select(p => new
{
name = p.Name,
path = p.Path,
directoryPath = Path.GetDirectoryName(p.Path)
}).ToArray()
};
File.WriteAllText(
RootDirectory / "matrix.json",
JsonConvert.SerializeObject(matrix));
});
Target Accept => _ => _
.Executes(() =>
{
foreach (var mismatchDir in Directory.GetDirectories(
RootDirectory, "__mismatch__", SearchOption.AllDirectories))
{
Log.Information("Analyzing {0} ...", mismatchDir);
var snapshotDir = Directory.GetParent(mismatchDir)!.FullName;
foreach (var mismatch in Directory.GetFiles(
mismatchDir, "*.*", SearchOption.TopDirectoryOnly))
{
var snapshot = Path.Combine(snapshotDir, Path.GetFileName(mismatch));
if (File.Exists(snapshot))
{
File.Delete(snapshot);
File.Move(mismatch, snapshot);
}
}
foreach (var mismatch in Directory.GetFiles(
mismatchDir, "*.*", SearchOption.AllDirectories))
{
File.Delete(mismatch);
}
Directory.Delete(mismatchDir, true);
}
});
}
[Serializable]
public class TestProject
{
public string Name { get; set; }
public string Path { get; set; }
}