forked from akkadotnet/akka.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildIncremental.fsx
189 lines (158 loc) · 8.08 KB
/
buildIncremental.fsx
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#I @"tools/FAKE/tools"
#r "FakeLib.dll"
open System
open System.IO
open Fake
open Fake.Git
module IncrementalTests =
type Supports =
| Windows
| Linux
| All
let (|IsRunnable|_|) name platform (csproj:string) =
let isSupported =
match platform with
| Windows _ -> isWindows
| Linux _ -> isLinux
| All _ -> true
if (csproj.Contains(name) && isSupported) then Some(name)
else None
let getUnitTestProjects() =
let isRunnable testProject =
match testProject with
| IsRunnable "Akka.API.Tests.csproj" Linux proj -> false
| IsRunnable "Akka.MultiNodeTestRunner.Shared.Tests.csproj" All proj -> false
| _ -> true
let allTestProjects = !! "./**/core/**/*.Tests.csproj"
++ "./**/contrib/**/*.Tests.csproj"
-- "./**/serializers/**/*Wire*.csproj"
allTestProjects
|> Seq.filter isRunnable
let isBuildScript (file:string) =
match file with
| EndsWith "fsx" -> true
| EndsWith "ps1" -> true
| EndsWith "cmd" -> true
| EndsWith "sh" -> true
| _ -> false
let getUpdatedFiles() =
let srcDir = __SOURCE_DIRECTORY__
let localBranches = getLocalBranches srcDir
if not (localBranches |> Seq.exists (fun b -> b = "v1.3")) then
directRunGitCommandAndFail srcDir "fetch origin v1.3:v1.3"
let forkPoint = runSimpleGitCommand srcDir "merge-base --fork-point v1.3"
let currentHash = getCurrentHash()
getChangedFiles srcDir forkPoint currentHash
|> Seq.map (fun (_, fi) -> FullName fi)
// only consider files in ./src/ and build scripts
|> Seq.filter (fun fi -> (isInFolder (new DirectoryInfo("./src")) (new FileInfo(fi))) || (isBuildScript fi))
// Gather all of the folder paths that contain .csproj files
let getAllProjectFolders() =
!! "./src/**/*.csproj"
|> Seq.map (fun f -> DirectoryName (FullName f))
// Check if the altered file is inside of any of the folder paths that contain .csproj files
let isInProjectFolder projectFolder file =
isInFolder (new DirectoryInfo(projectFolder)) (new FileInfo(file))
type ProjectFileInclude = { projectFolder: string; file: string; contains: bool }
// Return a collection of all projectFolder, altered file, and true/false is contained within
let generateContainingProjFileCollection alteredFiles =
getAllProjectFolders()
|> Seq.map (fun p -> alteredFiles |> Seq.map (fun f -> { projectFolder = p; file = f; contains = isInProjectFolder p f }))
|> Seq.concat
// Find the .csproj file contained within a folder that contains an altered file
let findCsprojFilesForAlteredFiles fileProjectContainsSeq =
let findCsprojFileFor fileProjectContains =
//let projectFolder, file, contains = fileProjectContains
match fileProjectContains.contains with
| true -> Some(!! (fileProjectContains.projectFolder @@ "*.csproj") |> Seq.head)
| false -> None
fileProjectContainsSeq
|> Seq.map (fun x -> findCsprojFileFor x)
|> Seq.choose id
|> Seq.map (fun x -> filename x)
let getAssemblyForProject project =
try
!! ("src" @@ "**" @@ "bin" @@ "Release" @@ "net452" @@ fileNameWithoutExt project + ".dll") // TODO: rework for .NET Core
|> Seq.head
with
| :? System.ArgumentException as ex ->
logf "Could not find built assembly for %s. Make sure project is built in Release config." (fileNameWithoutExt project);
reraise()
//--------------------------------------------------------------------------------
// MultiNodeTestRunner incremental test selection
//--------------------------------------------------------------------------------
let getMntrProjects() =
!! "./src/**/*Tests.MultiNode.csproj"
|> Seq.map (fun x -> x.ToString())
let getAllMntrTestAssemblies() = // if we're not running incremental tests
getMntrProjects()
|> Seq.map (fun x -> getAssemblyForProject x)
//--------------------------------------------------------------------------------
// Performance tests incremental test selection
//--------------------------------------------------------------------------------
let getPerfTestProjects() =
!! "./src/**/*Tests.Performance.csproj"
|> Seq.map (fun x -> x.ToString())
let getAllPerfTestAssemblies() = //if we're not running incremental tests
getPerfTestProjects()
|> Seq.map (fun x -> getAssemblyForProject x)
//--------------------------------------------------------------------------------
// Recursive dependency search
//--------------------------------------------------------------------------------
type ProjectPath = { projectName: string; projectPath: string }
type ProjectDetails = { parentProject: ProjectPath; dependencies: ProjectPath seq; isTestProject: bool }
let getDependentProjects csprojFile =
XMLRead true csprojFile "" "" "//Project/ItemGroup/ProjectReference/@Include"
|> Seq.map (fun p -> { projectName = filename p; projectPath = FullName p })
type TestMode =
| Unit
| MNTR
| Perf
let isTestProject csproj testMode =
match testMode with
| Unit -> (filename csproj).Contains("Tests.csproj")
| MNTR -> (filename csproj).Contains("Tests.MultiNode.csproj")
| Perf -> (filename csproj).Contains("Tests.Performance.csproj")
let getAllProjectDependencies testMode =
!! "./src/**/*.csproj"
|> Seq.map (fun f -> { parentProject = { projectName = filename f; projectPath = f }; dependencies = getDependentProjects f; isTestProject = isTestProject f testMode })
let rec findTestProjectsThatHaveDependencyOn project testMode =
let allProjects = getAllProjectDependencies testMode
seq { for proj in allProjects do
for dep in proj.dependencies do
if (proj.parentProject.projectName = project && proj.isTestProject) then
// if the altered project is a test project (e.g. Akka.Tests)
yield proj;
if (dep.projectName = project && proj.isTestProject) then
// logfn "%s references %s and is a test project..." proj.parentProject.projectName project
yield proj
elif (dep.projectName = project && not proj.isTestProject) then
// logfn "%s references %s but is not a test project..." proj.parentProject.projectName project
yield! findTestProjectsThatHaveDependencyOn proj.parentProject.projectName testMode }
let getIncrementalTestProjects2 testMode =
logfn "Searching for incremental tests to run in %s test mode..." (testMode.ToString())
let updatedFiles = getUpdatedFiles()
log "The following files have been updated since forking from v1.3 branch..."
updatedFiles |> Seq.iter log
log "The following test projects will be run..."
if (updatedFiles |> Seq.exists (fun p -> isBuildScript p)) then
match testMode with
| Unit -> getUnitTestProjects()
| MNTR -> getMntrProjects()
| Perf -> getPerfTestProjects()
else
updatedFiles
|> generateContainingProjFileCollection
|> findCsprojFilesForAlteredFiles
|> Seq.map (fun p -> findTestProjectsThatHaveDependencyOn p testMode)
|> Seq.concat
|> Seq.map (fun p -> p.parentProject.projectPath)
|> Seq.distinct
let getIncrementalUnitTests() =
getIncrementalTestProjects2 Unit
let getIncrementalMNTRTests() =
getIncrementalTestProjects2 MNTR
|> Seq.map (fun p -> getAssemblyForProject p)
let getIncrementalPerfTests() =
getIncrementalTestProjects2 Perf
|> Seq.map (fun p -> getAssemblyForProject p)