-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.build.ps1
More file actions
121 lines (98 loc) · 3.95 KB
/
.build.ps1
File metadata and controls
121 lines (98 loc) · 3.95 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
#requires -module PowerShellGet
Param (
[Parameter(Position = 0)]
$Tasks,
[Parameter()]
$ProjectPath = "$PSScriptRoot\website",
[Parameter()]
[String]
$BuildOutput = "BuildOutput",
[Parameter()]
[switch]
$ResolveDependency
)
begin {
Import-Module Microsoft.PowerShell.Utility, Microsoft.PowerShell.Security -ErrorAction SilentlyContinue
Get-PackageProvider | Out-Null
$oldpaths = $env:PSModulePath
$env:PSModulePath = @(
(Join-Path $PSScriptRoot "Dependencies")
) -join ';'
$dependencyPaths = (Join-Path $PSScriptRoot "Dependencies")
foreach ($dependencyPath in $dependencyPaths) {
if (-not (Test-Path $dependencyPath -PathType Container)) {
New-Item $dependencyPath -Force -ItemType Directory | Out-Null
}
}
if (![io.path]::IsPathRooted($BuildOutput)) {
$BuildOutput = Join-Path -Path $PSScriptRoot -ChildPath $BuildOutput
}
function Resolve-Dependency {
[CmdletBinding()]
param()
Install-Module PowerShellGet -Scope CurrentUser -Force
if (!(Get-Module -Listavailable InvokeBuild)) {
Write-Verbose "BootStrapping InvokeBuild"
"Parameter $BuildOutput" | Write-Verbose
$saveInvokeBuildParams = @{
Name = 'InvokeBuild', 'Pester'
Path = "$PSScriptRoot\Dependencies"
}
if ($PSBoundParameters.ContainsKey('verbose')) { $saveInvokeBuildParams.add('verbose', $verbose) }
Save-Module @saveInvokeBuildParams
}
Write-Verbose "Project Bootstrapped, returning to Invoke-Build"
}
if ($ResolveDependency) {
Write-Host "Resolving Dependencies... [this can take a moment]"
$params = @{ }
if ($PSboundParameters.ContainsKey('verbose')) {
$params.Add('verbose', $verbose)
}
Resolve-Dependency @Params
}
}
process {
if ($MyInvocation.ScriptName -notlike '*Invoke-Build.ps1') {
$PSBoundParameters.Remove("ResolveDependency") | Out-Null
Invoke-Build $Tasks $MyInvocation.MyCommand.Path @PSBoundParameters -ProjectPath $ProjectPath
return
}
task ResolveDependencies {
Write-Host "Resolving Dependencies... [this can take a moment]"
$params = @{ }
if ($PSboundParameters.ContainsKey('Verbose')) {
$params.Add('Verbose', $Verbose)
}
Resolve-Dependency @params
}
task BuildWebsite -before test {
$null = New-Item -ItemType Directory -Path $PSScriptRoot\BuildOutput\ -Force
Copy-Item $PSScriptRoot\website\* $PSScriptRoot\BuildOutput\ -Force -Recurse
$html = Get-Content $PSScriptRoot\website\index.html -Raw
$NewHtml = $html -replace '{{ version }}', $env:GITVERSION_SEMVER
Set-Content $PSScriptRoot\BuildOutput\index.html -Value $NewHtml -Force
}
task test {
$pesterArgs = @{
PassThru = $true
}
[void] $pesterArgs.Add('OutputFormat', 'NUnitXml')
[void] $pesterArgs.Add('OutputFile', "$PSScriptRoot\TEST-Results.xml")
$result = Invoke-Pester @pesterArgs
if ($result.FailedCount -gt 0) {
Write-Error -Message 'One or more tests failed!'
}
}
task GitVersion -before BuildWebsite -If ((get-command gitversion -ErrorAction SilentlyContinue) -and -not $env:SYSTEM_ACCESSTOKEN) {
$gitVersionInfo = GitVersion | ConvertFrom-Json
$env:GITVERSION_SemVer = $gitVersionInfo.SemVer
}
task FakeGitVersion -before BuildWebsite -If (-not (get-command gitversion -ErrorAction SilentlyContinue) -and -not $env:SYSTEM_ACCESSTOKEN) {
Write-Warning 'gitversion was not found. The supplied version is a default and not necessarily useful'
$env:GITVERSION_SemVer = "1.0.0"
}
}
end {
$env:PSModulePath = $oldpaths
}