Skip to content
96 changes: 96 additions & 0 deletions tools/releaseBuild/macOS/PowerShellPackageVsts.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# 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
)

# We must build in /PowerShell
$repoRoot = '/PowerShell'
if ($BootStrap.IsPresent) {
$repoRoot = $location
}

if ($Build.IsPresent) {
# cleanup the folder but don't delete it or the build agent will loose ownership of the folder
Write-Verbose -Message "cleaning /PowerShell" -Verbose
Get-ChildItem -Path /PowerShell/* -Attributes Hidden, Normal, Directory | Remove-Item -Recurse -Force

# clone the repository to the location we must build from
Write-Verbose -Message "cloning to /PowerShell" -Verbose
git clone $location /PowerShell
$releaseTagParam = @{}
if ($ReleaseTag) {
$releaseTagParam = @{ 'ReleaseTag' = $ReleaseTag }
}
}


Push-Location
try {
Write-Verbose -Message "Init..." -Verbose
Set-Location $repoRoot
git submodule update --init --recursive --quiet
Import-Module "$repoRoot/build.psm1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the VM is reused, we should use -Force

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VM is reused but not the process.

Import-Module "$repoRoot/tools/packaging"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the VM is reused, we should use -Force

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VM is reused but not the process.

Sync-PSTags -AddRemoteIfMissing

if ($BootStrap.IsPresent) {
Start-PSBootstrap -Package

# The gem install is run by bootstrap without sudo and fails on macOS.
# Run the commands with sudo, to resolve the issue
Write-Verbose -Message "Installing fpm..." -Verbose
Start-NativeExecution { sudo gem install fpm -v 1.8.1 }
Write-Verbose -Message "Installing ronn..." -Verbose
Start-NativeExecution { sudo gem install ronn }
}

if ($Build.IsPresent) {
Start-PSBuild -Crossgen -PSModuleRestore @releaseTagParam

Start-PSPackage @releaseTagParam
switch ($ExtraPackage) {
"tar" { Start-PSPackage -Type tar @releaseTagParam }
}
}
} 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
Write-Host "##vso[artifact.upload containerfolder=results;artifactname=$name]$filePath"
Write-Host "##vso[task.setvariable variable=Package-$extension]$filePath"
Copy-Item -Path $filePath -Destination $destination -force
}
}
1 change: 1 addition & 0 deletions tools/releaseBuild/macOS/PowerShellPackageVsts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pwsh -command ".\PowerShellPackageVsts.ps1 $*"
8 changes: 8 additions & 0 deletions tools/releaseBuild/macOS/createPowerShell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# print version for diags
sw_vers -productVersion

# create folder
sudo mkdir /PowerShell

# make the current user the owner
sudo chown $USER /PowerShell
30 changes: 30 additions & 0 deletions tools/releaseBuild/macOS/vsts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
steps:
#- task: <task type name>@<version>
# inputs:
# <task specific inputs>
# displayName: '<display name of task>'
- task: ShellScript@2
inputs:
scriptPath: 'tools/releaseBuild/setReleaseTag.sh'
args: '-ReleaseTag $(ReleaseTagVar) -Variable "ReleaseTagVar"'
displayName: 'Calculate Release Tag'
- task: ShellScript@2
inputs:
scriptPath: 'tools/installpsh-osx.sh'
displayName: 'Install pwsh'
- task: ShellScript@2
inputs:
scriptPath: 'tools/releaseBuild/macOS/createPowerShell.sh'
displayName: 'Create /PowerShell'
- task: ShellScript@2
inputs:
scriptPath: 'tools/releaseBuild/macOS/PowerShellPackageVsts.sh'
args: '-location $(Build.SourcesDirectory) -BootStrap'
displayName: 'Bootstrap VM'
- task: ShellScript@2
inputs:
scriptPath: 'tools/releaseBuild/macOS/PowerShellPackageVsts.sh'
args: '-ReleaseTag $(ReleaseTagVar) -Destination $(System.ArtifactsDirectory) -ExtraPackage "tar" -location $(Build.SourcesDirectory) -Build'
disableAutoCwd: true
cwd: 'tools/releaseBuild/macOS'
displayName: 'Build and Package'