This repository has been archived by the owner on Jul 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMSOnlineExt.build.ps1
82 lines (81 loc) · 3.61 KB
/
MSOnlineExt.build.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
78
79
80
81
82
task Deploy UpdateManifest, UnloadModule, LoadModule, Test, UnloadModule, StageModule, {
if($env:APPVEYOR)
{
$deploy_path = "$PSScriptRoot\src\Deploy"
if($env:APPVEYOR_REPO_BRANCH -eq 'Master')
{
Invoke-PSDeploy -Path $deploy_path -Force -Tags 'Test'
Publish-Module -Name 'MSOnlineExt' -NuGetApiKey $env:NugetApiKey -Force
}
else
{
Invoke-PSDeploy -Path $deploy_path -Force -Tags 'Test'
}
}
else
{
Write-Warning -Message 'The command "Invoke-Build -Task Deploy" should only be used on the CI server.'
}
}
task StageModule {
Copy-Item -Path "$PSScriptRoot\src\MSOnlineExt\" -Recurse -Destination 'C:\module\MSOnlineExt\'
$env:PSModulePath += ';C:\module'
Import-Module -Name 'MSOnlineExt'
}
task Test {
$test_path = Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath 'src' ) -ChildPath 'Test'
if ($env:APPVEYOR)
{
$test_file = 'TestResults_{0}_{1}.xml' -f $PSVersionTable.PSVersion.ToString(), (Get-Date -UFormat '%Y%m%d-%H%M%S')
$out_file = Join-Path -Path $test_path -ChildPath $test_file
Invoke-Pester -Path $test_path -OutputFormat 'NUnitXml' -OutputFile $out_file
$wc = [System.Net.WebClient]::new()
$upload_uri = 'https://ci.appveyor.com/api/testresults/nunit/{0}' -f $env:APPVEYOR_JOB_ID
$wc.UploadFile($upload_uri,$out_file)
}
else
{
# Any tests not run from Appveyor
Invoke-Pester -Path $test_path
}
}
task LoadModule {
$manifest_path = Join-Path -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath 'src' ) -ChildPath 'MSOnlineExt' ) -ChildPath 'MSOnlineExt.psd1'
if(-not ([appdomain]::CurrentDomain.GetAssemblies().FullName -match 'Microsoft.ApplicationInsights') -and -not $env:APPVEYOR)
{
$dll = Join-Path -Path ( Join-Path -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath 'src' ) -ChildPath 'MSOnlineExt' ) -ChildPath 'Assembly' ) -ChildPath 'Microsoft.ApplicationInsights.dll'
Add-Type -Path $dll
}
if (-not (Get-Module -Name 'MSOnlineExt'))
{
# Disable telmetry prompt on module import during tests
$global:WarningPreference = 'SilentlyContinue'
Import-Module $manifest_path
$global:WarningPreference = 'Continue'
}
}
task UnloadModule {
if (Get-Module -Name 'MSOnlineExt'){ Remove-Module -Name 'MSOnlineExt' }
}
task UpdateManifest {
$functions_path = Join-Path -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath 'src' ) -ChildPath 'MSOnlineExt' ) -ChildPath 'Public'
$manifest_path = Join-Path -Path ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath 'src' ) -ChildPath 'MSOnlineExt' ) -ChildPath 'MSOnlineExt.psd1'
$module_root = Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath 'src' ) -ChildPath 'MSOnlineExt'
Push-Location
Set-Location -Path $module_root
$dll = Get-ChildItem -File -Recurse -Filter '*.dll' | Resolve-Path -Relative
$file_list = Get-ChildItem -File -Recurse | Resolve-Path -Relative | ForEach-Object { $PSItem.Substring(2) }
Pop-Location
$functions = Get-ChildItem -Path $functions_path -Filter '*.ps1'
$manifest_params = @{
CompanyName = 'Dakota Clark'
Path = $manifest_path
Copyright = 'Copyright © {0} Dakota Clark. All rights reserved.' -f (Get-Date).Year
FunctionsToExport = $functions.BaseName
ModuleVersion = $env:APPVEYOR_BUILD_VERSION
RequiredAssemblies = $dll
FileList = $file_list
}
Update-ModuleManifest @manifest_params
}
task . UnloadModule, LoadModule, Test