2018-02-13 18:23:53 +01:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the MIT License.
|
2017-11-13 19:10:51 +01:00
|
|
|
[cmdletbinding(DefaultParameterSetName='Build')]
|
2017-09-26 23:02:55 +02:00
|
|
|
param(
|
2017-11-13 19:10:51 +01:00
|
|
|
[Parameter(ParameterSetName='packageSigned')]
|
2017-09-26 23:02:55 +02:00
|
|
|
[Parameter(ParameterSetName='Build')]
|
2017-11-16 01:55:13 +01:00
|
|
|
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+(\.\d+)?)?$")]
|
2017-11-13 19:10:51 +01:00
|
|
|
[string]$ReleaseTag,
|
|
|
|
|
|
|
|
# full paths to files to add to container to run the build
|
|
|
|
[Parameter(Mandatory,ParameterSetName='packageSigned')]
|
|
|
|
[string]
|
|
|
|
$BuildPath,
|
|
|
|
|
|
|
|
[Parameter(Mandatory,ParameterSetName='packageSigned')]
|
|
|
|
[string]
|
|
|
|
$SignedFilesPath
|
2017-09-26 23:02:55 +02:00
|
|
|
)
|
|
|
|
|
2017-11-11 00:28:38 +01:00
|
|
|
DynamicParam {
|
|
|
|
# Add a dynamic parameter '-Name' which specifies the name of the build to run
|
|
|
|
|
|
|
|
# Get the names of the builds.
|
|
|
|
$buildJsonPath = (Join-Path -path $PSScriptRoot -ChildPath 'build.json')
|
|
|
|
$build = Get-Content -Path $buildJsonPath | ConvertFrom-Json
|
|
|
|
$names = @($build.Windows.Name)
|
|
|
|
foreach($name in $build.Linux.Name)
|
|
|
|
{
|
|
|
|
$names += $name
|
|
|
|
}
|
2017-09-26 23:02:55 +02:00
|
|
|
|
2017-11-11 00:28:38 +01:00
|
|
|
# Create the parameter attributs
|
|
|
|
$ParameterAttr = New-Object "System.Management.Automation.ParameterAttribute"
|
|
|
|
$ValidateSetAttr = New-Object "System.Management.Automation.ValidateSetAttribute" -ArgumentList $names
|
|
|
|
$Attributes = New-Object "System.Collections.ObjectModel.Collection``1[System.Attribute]"
|
|
|
|
$Attributes.Add($ParameterAttr) > $null
|
|
|
|
$Attributes.Add($ValidateSetAttr) > $null
|
2017-11-16 01:55:13 +01:00
|
|
|
|
2017-11-11 00:28:38 +01:00
|
|
|
# Create the parameter
|
|
|
|
$Parameter = New-Object "System.Management.Automation.RuntimeDefinedParameter" -ArgumentList ("Name", [string], $Attributes)
|
|
|
|
$Dict = New-Object "System.Management.Automation.RuntimeDefinedParameterDictionary"
|
|
|
|
$Dict.Add("Name", $Parameter) > $null
|
|
|
|
return $Dict
|
2017-09-26 23:02:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-11 00:28:38 +01:00
|
|
|
Begin {
|
|
|
|
$Name = $PSBoundParameters['Name']
|
2017-09-26 23:02:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-11 00:28:38 +01:00
|
|
|
End {
|
|
|
|
$ErrorActionPreference = 'Stop'
|
2017-09-26 23:02:55 +02:00
|
|
|
|
2017-11-13 19:10:51 +01:00
|
|
|
$additionalFiles = @()
|
|
|
|
$buildPackageName = $null
|
|
|
|
# If specified, Add package file to container
|
|
|
|
if ($BuildPath)
|
|
|
|
{
|
|
|
|
Import-Module (Join-Path -path $PSScriptRoot -childpath '..\..\build.psm1')
|
|
|
|
Import-Module (Join-Path -path $PSScriptRoot -childpath '..\packaging')
|
|
|
|
|
|
|
|
# Use temp as destination if not running in VSTS
|
2017-11-16 01:55:13 +01:00
|
|
|
$destFolder = $env:temp
|
2017-12-07 00:51:33 +01:00
|
|
|
if($env:BUILD_STAGINGDIRECTORY)
|
2017-11-13 19:10:51 +01:00
|
|
|
{
|
|
|
|
# Use artifact staging if running in VSTS
|
2017-12-07 00:51:33 +01:00
|
|
|
$destFolder = $env:BUILD_STAGINGDIRECTORY
|
2017-11-13 19:10:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$BuildPackagePath = New-PSSignedBuildZip -BuildPath $BuildPath -SignedFilesPath $SignedFilesPath -DestinationFolder $destFolder
|
2019-03-21 18:24:49 +01:00
|
|
|
Write-Verbose -Verbose "New-PSSignedBuildZip returned `$BuildPackagePath as: $BuildPackagePath"
|
|
|
|
Write-Host "##vso[artifact.upload containerfolder=results;artifactname=results]$BuildPackagePath"
|
2017-11-13 19:10:51 +01:00
|
|
|
$buildPackageName = Split-Path -Path $BuildPackagePath -Leaf
|
|
|
|
$additionalFiles += $BuildPackagePath
|
|
|
|
}
|
|
|
|
|
2017-11-11 00:28:38 +01:00
|
|
|
$psReleaseBranch = 'master'
|
|
|
|
$psReleaseFork = 'PowerShell'
|
|
|
|
$location = Join-Path -Path $PSScriptRoot -ChildPath 'PSRelease'
|
|
|
|
if(Test-Path $location)
|
|
|
|
{
|
|
|
|
Remove-Item -Path $location -Recurse -Force
|
|
|
|
}
|
2017-09-26 23:02:55 +02:00
|
|
|
|
2017-11-11 00:28:38 +01:00
|
|
|
$gitBinFullPath = (Get-Command -Name git).Source
|
|
|
|
if (-not $gitBinFullPath)
|
|
|
|
{
|
|
|
|
throw "Git is required to proceed. Install from 'https://git-scm.com/download/win'"
|
|
|
|
}
|
2017-09-26 23:02:55 +02:00
|
|
|
|
2017-11-11 00:28:38 +01:00
|
|
|
Write-Verbose "cloning -b $psReleaseBranch --quiet https://github.com/$psReleaseFork/PSRelease.git" -verbose
|
|
|
|
& $gitBinFullPath clone -b $psReleaseBranch --quiet https://github.com/$psReleaseFork/PSRelease.git $location
|
2017-09-26 23:02:55 +02:00
|
|
|
|
2017-11-11 00:28:38 +01:00
|
|
|
Push-Location -Path $PWD.Path
|
|
|
|
|
|
|
|
$unresolvedRepoRoot = Join-Path -Path $PSScriptRoot '../..'
|
|
|
|
$resolvedRepoRoot = (Resolve-Path -Path $unresolvedRepoRoot).ProviderPath
|
|
|
|
|
2017-11-16 01:55:13 +01:00
|
|
|
try
|
2017-11-11 00:28:38 +01:00
|
|
|
{
|
|
|
|
Write-Verbose "Starting build at $resolvedRepoRoot ..." -Verbose
|
|
|
|
Import-Module "$location/vstsBuild" -Force
|
|
|
|
Import-Module "$location/dockerBasedBuild" -Force
|
|
|
|
Clear-VstsTaskState
|
|
|
|
|
2017-11-13 19:10:51 +01:00
|
|
|
$buildParameters = @{
|
|
|
|
ReleaseTag = $ReleaseTag
|
|
|
|
BuildPackageName = $buildPackageName
|
|
|
|
}
|
|
|
|
|
2017-12-07 00:51:33 +01:00
|
|
|
Invoke-Build -RepoPath $resolvedRepoRoot -BuildJsonPath './tools/releaseBuild/build.json' -Name $Name -Parameters $buildParameters -AdditionalFiles $AdditionalFiles
|
2017-11-11 00:28:38 +01:00
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
Write-VstsError -Error $_
|
|
|
|
}
|
|
|
|
finally{
|
|
|
|
Write-VstsTaskState
|
|
|
|
exit 0
|
|
|
|
}
|
2017-09-26 23:02:55 +02:00
|
|
|
}
|