forked from IntentArchitect/Intent.Modules.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-intent-testing.ps1
77 lines (69 loc) · 2.43 KB
/
prepare-intent-testing.ps1
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
$modulesFolderPath = "Intent.Modules"
$pathToModules = "Modules"
$solutionFile = "Tests/Intent.Modules.NET.Tests.isln"
$repoConfigContent =
"<?xml version=""1.0"" encoding=""utf-8""?>
<assetRepositories>
<entries>
<entry>
<name>CI Compiled Modules</name>
<address>../$($pathToModules)/$($modulesFolderPath)</address>
<isBuiltIn>false</isBuiltIn>
<order>3</order>
</entry>
</entries>
</assetRepositories>"
$moduleLookup = @{}
$moduleFileNames = Get-ChildItem "./$($pathToModules)/$($modulesFolderPath)/*.imod" | % {
$file = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
$dotNumber = 0
$dotIndex = -1
$dotIndexNo3 = -1
for ($i = $file.Length - 1; $i -gt 0; $i--) {
$cur = $file[$i]
if ($cur -eq '.') {
$dotNumber++
$dotIndex = $i
}
if (($dotNumber -eq 3) -and ([System.Char]::IsDigit($file[$i + 1]))) {
$dotIndexNo3 = $dotIndex
}
if ($dotNumber -eq 4) {
if ([System.Char]::IsDigit($file[$i + 1])) {
$dotIndex = $i
} else {
$dotIndex = $dotIndexNo3
}
break
}
}
if ($dotIndex -gt -1) {
$moduleLookup.Add($file.Substring(0, $dotIndex), $file.Substring($dotIndex + 1))
}
}
$curLocation = Get-Location;
Write-Host "`$curLocation = $curLocation"
$testSln = [xml] (Get-Content ./$solutionFile -Encoding UTF8)
$testSlnDir = [System.IO.Path]::GetDirectoryName($solutionFile)
Write-Host "`$testSlnDir = $testSlnDir"
$repoPath = [System.IO.Path]::Combine($curLocation, $testSlnDir, "intent.repositories.config")
Write-Host "`$repoPath = $repoPath"
$repoConfigContent | Set-Content $repoPath -Encoding UTF8
$testSln.solution.applications.application | % {
$appRelPath = [System.IO.Path]::Combine($curLocation, $testSlnDir, $_.relativePath)
$basePath = [System.IO.Path]::GetDirectoryName($appRelPath)
$modulesConfig = [System.IO.Path]::Combine($basePath, "modules.config")
$modulesConfigContent = [xml] (Get-Content $modulesConfig -Encoding UTF8)
$changed = $false
$modulesConfigContent.modules.module | % {
$module = $_
$moduleVersionFound = $moduleLookup[$module.moduleId]
if ($moduleVersionFound -ne $null) {
$module.version = $moduleVersionFound
$changed = $true
}
}
if ($changed) {
$modulesConfigContent.Save($modulesConfig)
}
}