2018-03-19 23:56:43 +01:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
|
|
|
# PowerShell Script to build and package PowerShell from specified form and branch
|
|
|
|
# Script is intented to use in Docker containers
|
|
|
|
# Ensure PowerShell is available in the provided image
|
|
|
|
|
|
|
|
param (
|
|
|
|
# Set default location to where VSTS cloned the repository locally.
|
|
|
|
[string] $location = $env:BUILD_REPOSITORY_LOCALPATH,
|
|
|
|
|
|
|
|
# Destination location of the package on docker host
|
|
|
|
[Parameter(Mandatory, ParameterSetName = 'Build')]
|
|
|
|
[string] $destination = '/mnt',
|
|
|
|
|
|
|
|
[Parameter(Mandatory, ParameterSetName = 'Build')]
|
|
|
|
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+(\.\d+)?)?$")]
|
|
|
|
[ValidateNotNullOrEmpty()]
|
|
|
|
[string]$ReleaseTag,
|
|
|
|
|
|
|
|
[Parameter(ParameterSetName = 'Build')]
|
|
|
|
[ValidateSet("zip", "tar")]
|
|
|
|
[string[]]$ExtraPackage,
|
|
|
|
|
|
|
|
[Parameter(Mandatory, ParameterSetName = 'Bootstrap')]
|
|
|
|
[switch] $BootStrap,
|
|
|
|
|
|
|
|
[Parameter(Mandatory, ParameterSetName = 'Build')]
|
|
|
|
[switch] $Build
|
|
|
|
)
|
|
|
|
|
2018-11-14 02:04:39 +01:00
|
|
|
$repoRoot = $location
|
2018-03-19 23:56:43 +01:00
|
|
|
|
|
|
|
if ($Build.IsPresent) {
|
2020-02-05 01:21:59 +01:00
|
|
|
$releaseTagParam = @{ }
|
2018-03-19 23:56:43 +01:00
|
|
|
if ($ReleaseTag) {
|
|
|
|
$releaseTagParam = @{ 'ReleaseTag' = $ReleaseTag }
|
2020-02-05 01:21:59 +01:00
|
|
|
|
|
|
|
#Remove the initial 'v' from the ReleaseTag
|
|
|
|
$version = $ReleaseTag -replace '^v'
|
|
|
|
$semVersion = [System.Management.Automation.SemanticVersion] $version
|
|
|
|
|
|
|
|
## All even minor versions are LTS
|
|
|
|
$LTS = if ( $semVersion.PreReleaseLabel -eq $null -and $semVersion.Minor % 2 -eq 0) {
|
|
|
|
$true
|
|
|
|
} else {
|
|
|
|
$false
|
|
|
|
}
|
2018-03-19 23:56:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Push-Location
|
|
|
|
try {
|
|
|
|
Write-Verbose -Message "Init..." -Verbose
|
|
|
|
Set-Location $repoRoot
|
|
|
|
Import-Module "$repoRoot/build.psm1"
|
|
|
|
Import-Module "$repoRoot/tools/packaging"
|
|
|
|
Sync-PSTags -AddRemoteIfMissing
|
|
|
|
|
|
|
|
if ($BootStrap.IsPresent) {
|
|
|
|
Start-PSBootstrap -Package
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($Build.IsPresent) {
|
2018-05-15 00:01:44 +02:00
|
|
|
Start-PSBuild -Configuration 'Release' -Crossgen -PSModuleRestore @releaseTagParam
|
2018-03-19 23:56:43 +01:00
|
|
|
|
|
|
|
Start-PSPackage @releaseTagParam
|
|
|
|
switch ($ExtraPackage) {
|
|
|
|
"tar" { Start-PSPackage -Type tar @releaseTagParam }
|
|
|
|
}
|
2020-02-05 01:21:59 +01:00
|
|
|
|
|
|
|
if ($LTS) {
|
|
|
|
Start-PSPackage @releaseTagParam -LTS
|
|
|
|
switch ($ExtraPackage) {
|
|
|
|
"tar" { Start-PSPackage -Type tar @releaseTagParam -LTS }
|
|
|
|
}
|
|
|
|
}
|
2018-03-19 23:56:43 +01:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
Pop-Location
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($Build.IsPresent) {
|
|
|
|
$macPackages = Get-ChildItem "$repoRoot/powershell*" -Include *.pkg, *.tar.gz
|
|
|
|
foreach ($macPackage in $macPackages) {
|
|
|
|
$filePath = $macPackage.FullName
|
|
|
|
$name = split-path -Leaf -Path $filePath
|
|
|
|
$extension = (Split-Path -Extension -Path $filePath).Replace('.', '')
|
|
|
|
Write-Verbose "Copying $filePath to $destination" -Verbose
|
2019-03-21 18:24:49 +01:00
|
|
|
Write-Host "##vso[artifact.upload containerfolder=results;artifactname=results]$filePath"
|
2018-03-19 23:56:43 +01:00
|
|
|
Write-Host "##vso[task.setvariable variable=Package-$extension]$filePath"
|
|
|
|
Copy-Item -Path $filePath -Destination $destination -force
|
|
|
|
}
|
|
|
|
}
|