From 5e1bb01cb341215d6f70b391f65ee0b981786ea4 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 19 Mar 2018 15:56:43 -0700 Subject: [PATCH] migrate the mac offical binary build to VSTS mac hosted preview (#6363) create a PowerShellPackage...ps1 that works with these VMs (vs our custom VM) create a script to create the \powershell folder with correct permissions a YML VSTS build definition --- .../macOS/PowerShellPackageVsts.ps1 | 96 +++++++++++++++++++ .../macOS/PowerShellPackageVsts.sh | 1 + tools/releaseBuild/macOS/createPowerShell.sh | 8 ++ tools/releaseBuild/macOS/vsts.yml | 30 ++++++ 4 files changed, 135 insertions(+) create mode 100644 tools/releaseBuild/macOS/PowerShellPackageVsts.ps1 create mode 100644 tools/releaseBuild/macOS/PowerShellPackageVsts.sh create mode 100644 tools/releaseBuild/macOS/createPowerShell.sh create mode 100644 tools/releaseBuild/macOS/vsts.yml diff --git a/tools/releaseBuild/macOS/PowerShellPackageVsts.ps1 b/tools/releaseBuild/macOS/PowerShellPackageVsts.ps1 new file mode 100644 index 0000000000..43acf60461 --- /dev/null +++ b/tools/releaseBuild/macOS/PowerShellPackageVsts.ps1 @@ -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" + Import-Module "$repoRoot/tools/packaging" + 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 + } +} diff --git a/tools/releaseBuild/macOS/PowerShellPackageVsts.sh b/tools/releaseBuild/macOS/PowerShellPackageVsts.sh new file mode 100644 index 0000000000..b7bfa7315d --- /dev/null +++ b/tools/releaseBuild/macOS/PowerShellPackageVsts.sh @@ -0,0 +1 @@ +pwsh -command ".\PowerShellPackageVsts.ps1 $*" diff --git a/tools/releaseBuild/macOS/createPowerShell.sh b/tools/releaseBuild/macOS/createPowerShell.sh new file mode 100644 index 0000000000..5b0b681716 --- /dev/null +++ b/tools/releaseBuild/macOS/createPowerShell.sh @@ -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 diff --git a/tools/releaseBuild/macOS/vsts.yml b/tools/releaseBuild/macOS/vsts.yml new file mode 100644 index 0000000000..26da4047e0 --- /dev/null +++ b/tools/releaseBuild/macOS/vsts.yml @@ -0,0 +1,30 @@ +steps: +#- task: @ +# inputs: +# +# displayName: '' +- 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'