forked from mefellows/DSC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.ps1
More file actions
123 lines (102 loc) · 3.33 KB
/
Copy pathdefault.ps1
File metadata and controls
123 lines (102 loc) · 3.33 KB
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
properties {
$testOutput = ".\Test.xml"
$outputDir = ".\Output"
$outputPackageDir = "${outputDir}\Packages"
$outputModuleManifestDir = "${outputDir}\ModuleManifests"
$modulesDir = ".\Modules\SEEK - Modules"
$dscResourcesRoot = Join-Path $env:ProgramFiles "WindowsPowerShell\Modules"
if ($env:VERSION) { $version = $env:VERSION } else { $version = "0.1.0-dev" }
}
task default -depends Clean, UnitTest
task Package -depends Clean {
if (-not (Test-Path $outputPackageDir)) {
New-Item -ItemType directory -Path $outputPackageDir | Out-Null
}
Get-ChildItem *.nuspec -Recurse | Foreach-Object {
Update-ModuleManifestVersion -Path $_.DirectoryName -Version $version -OutputDir $outputModuleManifestDir
# chocolatey.cmd does not support paths with spaces, using chocolatey.ps1 instead
# chocolatey pack expects a package name argument only, quotes are necessary to inject the additional OutputDir argument
exec { chocolatey.ps1 pack """$($_.FullName)"" -OutputDir $(Resolve-Path $outputPackageDir) -Version $version" }
}
}
task EnableDeveloperMode {
Get-ChildItem $modulesDir -attributes Directory | Foreach-Object {
$linkPath = "$dscResourcesRoot\$($_.Name)"
$targePath = $_.FullName
if (Test-Path $linkPath) {
cmd /c rmdir $linkPath
}
cmd /c mklink /j $linkPath $targePath
}
}
task DisableDeveloperMode {
Get-ChildItem $modulesDir -attributes Directory | Foreach-Object {
$linkPath = Resolve-Path "$dscResourcesRoot\$($_.Name)"
if (Test-Path $linkPath) {
cmd /c rmdir $linkPath
}
}
}
task Install -depends Package {
exec { chocolatey.cmd install seek-dsc -source $(Resolve-Path $outputPackageDir) }
}
task Reinstall {
exec { chocolatey.cmd install seek-dsc -source $(Resolve-Path $outputPackageDir) -force }
}
task Uninstall {
$packageNames = Get-ChildItem *.nuspec -Recurse | Foreach-Object { $_.Basename }
chocolatey.cmd uninstall @packageNames
}
task UnitTest {
Invoke-Tests -Path .\Tests\Unit
}
task IntegrationTest {
Invoke-Tests -Path .\Tests\Integration
}
task E2ETest -depends FlushCache {
Invoke-Tests -Path .\Tests\E2E
}
task Test {
Invoke-Tests -Path $testPath -TestName $testName
}
task FlushCache {
Restart-Service winmgmt -force
}
task Clean {
if (Test-Path $testOutput) {
Remove-Item $testOutput
}
if (Test-Path $outputDir) {
Remove-Item $outputDir -Recurse -Force
}
}
function Invoke-Tests {
param (
[parameter(Mandatory = $true)]
[string]$Path,
[string]$TestName
)
if ($TestName) {
exec { pester.bat -Path $Path -TestName $TestName }
}
else {
exec { pester.bat -Path $Path }
}
}
function Update-ModuleManifestVersion {
param (
[parameter(Mandatory = $true)]
[string]$Path,
[parameter(Mandatory = $true)]
[string]$OutputDir,
[parameter(Mandatory = $true)]
[string]$Version
)
if (-not (Test-Path $OutputDir)) {
New-Item -ItemType directory -Path $OutputDir | Out-Null
}
Get-ChildItem -Path $Path -Filter *.psd1 | Foreach-Object {
$updatedModuleManifestPath = "${OutputDir}\$($_.Name)"
(Get-Content($_.FullName)) | ForEach-Object {$_ -replace "ModuleVersion\s+=\s+'[\d\.]+'", "ModuleVersion = '$Version'"} | Set-Content($updatedModuleManifestPath)
}
}