Files
PowerShell-PSDesiredStateCo…/build.ps1
T
2019-09-06 12:34:02 -07:00

123 lines
3.3 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# Do NOT edit this file. Edit dobuild.ps1
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
param (
[Parameter(ParameterSetName="build")]
[switch]
$Clean,
[Parameter(ParameterSetName="build")]
[switch]
$Build,
[Parameter(ParameterSetName="publish")]
[switch]
$Publish,
[Parameter(ParameterSetName="publish")]
[switch]
$Signed,
[Parameter(ParameterSetName="build")]
[switch]
$Test,
[Parameter(ParameterSetName="build")]
[string[]]
[ValidateSet("Functional","StaticAnalysis")]
$TestType = @("Functional"),
[Parameter(ParameterSetName="help")]
[switch]
$UpdateHelp,
[Parameter(ParameterSetName="build")]
[switch]
$TestInvokeDscResource
)
$config = Get-PSPackageProjectConfiguration -ConfigPath $PSScriptRoot
$script:ModuleName = $config.ModuleName
$script:SrcPath = $config.SourcePath
$script:OutDirectory = $config.BuildOutputPath
$script:SignedDirectory = $config.SignedOutputPath
$script:TestPath = $config.TestPath
$script:ModuleRoot = $PSScriptRoot
$script:Culture = $config.Culture
$script:HelpPath = $config.HelpPath
if ($env:TF_BUILD) {
$vstsCommandString = "vso[task.setvariable variable=BUILD_OUTPUT_PATH]$OutDirectory"
Write-Host ("sending " + $vstsCommandString)
Write-Host "##$vstsCommandString"
$vstsCommandString = "vso[task.setvariable variable=SIGNED_OUTPUT_PATH]$SignedDirectory"
Write-Host ("sending " + $vstsCommandString)
Write-Host "##$vstsCommandString"
}
. $PSScriptRoot\dobuild.ps1
if ( ! ( Get-Module -ErrorAction SilentlyContinue PSPackageProject) ) {
Install-Module PSPackageProject
}
if ($Clean -and (Test-Path $OutDirectory))
{
Remove-Item -Force -Recurse $OutDirectory -ErrorAction Stop -Verbose
}
if (-not (Test-Path $OutDirectory))
{
$script:OutModule = New-Item -ItemType Directory -Path (Join-Path $OutDirectory $ModuleName)
}
else
{
$script:OutModule = Join-Path $OutDirectory $ModuleName
}
if ($Build.IsPresent)
{
$sb = (Get-Item Function:DoBuild).ScriptBlock
Invoke-PSPackageProjectBuild -BuildScript $sb -SkipPublish
}
if ($Publish.IsPresent)
{
Invoke-PSPackageProjectPublish -Signed:$Signed.IsPresent
}
if ( $TestInvokeDscResource.IsPresent ) {
$backupName = $null
try {
$configFolder = split-path $PROFILE
$configPath = Join-Path $configFolder -ChildPath powershell.config.json
if(Test-Path ~/.config/powershell/powershell.config.json)
{
$backupName = Join-Path $configFolder -ChildPath "powershell.config-((Get-Date).ToString('yyyyMMddHHmm')).json"
Copy-Item $configPath $backupName -force
}
copy-Item $PSScriptRoot/assets/powershell.config.json $configPath
Invoke-PSPackageProjectTest -Type $TestType
}
finally {
remove-item $configPath
if($backupName)
{
Copy-Item $backupName $configPath -force
}
}
}
if ( $Test.IsPresent ) {
Invoke-PSPackageProjectTest -Type $TestType
}
if ($UpdateHelp.IsPresent) {
Add-PSPackageProjectCmdletHelp -ProjectRoot $ModuleRoot -ModuleName $ModuleName -Culture $Culture
}