From 6b4d4036f984e838264f28e668fcae88a052ed56 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 11 Oct 2017 10:35:02 -0700 Subject: [PATCH 1/2] Support creating tarball package for Linux and macOS --- .gitignore | 1 + tools/packaging/packaging.psm1 | 104 +++++++++++++++--- .../GenericLinuxFiles/PowerShellPackage.ps1 | 34 +++--- tools/releaseBuild/build.json | 8 +- 4 files changed, 115 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 06a7882365a..089babc3522 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ dotnet-uninstall-debian-packages.sh # Ignore packages *.deb +*.tar.gz *.zip *.rpm *.pkg diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 2ec8d5b3726..bb587e9a12b 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -20,7 +20,7 @@ function Start-PSPackage { [string]$Name = "powershell", # Ubuntu, CentOS, Fedora, macOS, and Windows packages are supported - [ValidateSet("deb", "osxpkg", "rpm", "msi", "zip", "AppImage", "nupkg", "deb-arm")] + [ValidateSet("deb", "osxpkg", "rpm", "msi", "zip", "AppImage", "nupkg", "tar")] [string[]]$Type, # Generate windows downlevel package @@ -35,6 +35,10 @@ function Start-PSPackage { [Switch] $SkipReleaseChecks ) + # The package type 'deb-arm' is current disabled for '-Type' parameter because 'New-UnixPackage' doesn't support + # creating package for 'deb-arm'. It should be added back to the ValidateSet of '-Type' once the implementation + # of creating 'deb-arm' package is done. + # Runtime and Configuration settings required by the package ($Runtime, $Configuration) = if ($WindowsRuntime) { $WindowsRuntime, "Release" @@ -151,15 +155,13 @@ function Start-PSPackage { Force = $Force } - if($pscmdlet.ShouldProcess("Create Zip Package")) - { + if ($PSCmdlet.ShouldProcess("Create Zip Package")) { New-ZipPackage @Arguments } } "msi" { $TargetArchitecture = "x64" - if ($Runtime -match "-x86") - { + if ($Runtime -match "-x86") { $TargetArchitecture = "x86" } @@ -175,14 +177,12 @@ function Start-PSPackage { Force = $Force } - if($pscmdlet.ShouldProcess("Create MSI Package")) - { + if ($PSCmdlet.ShouldProcess("Create MSI Package")) { New-MSIPackage @Arguments } } "AppImage" { - if($IncludeSymbols.IsPresent) - { + if ($IncludeSymbols.IsPresent) { throw "AppImage does not support packaging '-IncludeSymbols'" } @@ -207,11 +207,22 @@ function Start-PSPackage { Force = $Force } - if($pscmdlet.ShouldProcess("Create NuPkg Package")) - { + if ($PSCmdlet.ShouldProcess("Create NuPkg Package")) { New-NugetPackage @Arguments } } + 'tar' { + $Arguments = @{ + PackageSourcePath = $Source + Name = $Name + Version = $Version + Force = $Force + } + + if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) { + New-TarballPackage @Arguments + } + } 'deb' { $Arguments = @{ Type = 'deb' @@ -222,7 +233,9 @@ function Start-PSPackage { } foreach ($Distro in $Script:DebianDistributions) { $Arguments["Distribution"] = $Distro - New-UnixPackage @Arguments + if ($PSCmdlet.ShouldProcess("Create DEB Package for $Distro")) { + New-UnixPackage @Arguments + } } } default { @@ -234,14 +247,77 @@ function Start-PSPackage { Force = $Force } - if($pscmdlet.ShouldProcess("Create $_ Package")) - { + if ($PSCmdlet.ShouldProcess("Create $_ Package")) { New-UnixPackage @Arguments } } } } +function New-TarballPackage { + [CmdletBinding(SupportsShouldProcess=$true)] + param ( + [Parameter(Mandatory)] + [string] $PackageSourcePath, + + # Must start with 'powershell' but may have any suffix + [Parameter(Mandatory)] + [ValidatePattern("^powershell")] + [string]$Name, + + [Parameter(Mandatory)] + [string]$Version, + + [switch] $Force + ) + + $packageName = "$Name-$Version-{0}-x64.tar.gz" + if ($Environment.IsWindows) { + throw "Must be on Linux or macOS to build 'tar.gz' packages!" + } elseif ($Environment.IsLinux) { + $packageName = $packageName -f "linux" + } elseif ($Environment.IsMacOS) { + $packageName = $packageName -f "osx" + } + + $packagePath = Join-Path -Path $PWD -ChildPath $packageName + Write-Verbose "Create package $packageName" + Write-Verbose "Package destination path: $packagePath" + + if (Test-Path -Path $packagePath) { + if ($Force -or $PSCmdlet.ShouldProcess("Overwrite existing package file")) { + Write-Verbose "Overwrite existing package file at $packagePath" -Verbose + Remove-Item -Path $packagePath -Force -ErrorAction Stop -Confirm:$false + } + } + + if (Get-Command -Name tar -CommandType Application -ErrorAction Ignore) { + if ($Force -or $PSCmdlet.ShouldProcess("Create tarball package")) { + $options = "-czf" + if ($PSBoundParameters.ContainsKey('Verbose') -and $PSBoundParameters['Verbose'].IsPresent) { + # Use the verbose mode '-v' if '-Verbose' is specified + $options = "-czvf" + } + + try { + Push-Location -Path $PackageSourcePath + tar $options $packagePath . + } finally { + Pop-Location + } + + if (Test-Path -Path $packagePath) { + log "You can find the tarball package at $packagePath" + return $packagePath + } else { + throw "Failed to create $packageName" + } + } + } else { + throw "Failed to create the package because the application 'tar' cannot be found" + } +} + function New-UnixPackage { [CmdletBinding(SupportsShouldProcess=$true)] param( diff --git a/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 b/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 index 21b19a8c57c..fae166a2eec 100644 --- a/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 +++ b/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 @@ -11,11 +11,13 @@ param ( [ValidatePattern("^v\d+\.\d+\.\d+(-\w+\.\d+)?$")] [ValidateNotNullOrEmpty()] [string]$ReleaseTag, - [switch]$AppImage + + [ValidateSet("AppImage", "tar")] + [string[]]$ExtraPackage ) $releaseTagParam = @{} -if($ReleaseTag) +if ($ReleaseTag) { $releaseTagParam = @{ 'ReleaseTag' = $ReleaseTag } } @@ -25,14 +27,15 @@ try { Set-Location $location Import-Module "$location/build.psm1" Import-Module "$location/tools/packaging" - + Start-PSBootstrap -Package -NoSudo Start-PSBuild -Crossgen -PSModuleRestore @releaseTagParam Start-PSPackage @releaseTagParam - if($AppImage.IsPresent) + switch ($ExtraPackage) { - Start-PSPackage -Type AppImage @releaseTagParam + "AppImage" { Start-PSPackage -Type AppImage @releaseTagParam } + "tar" { Start-PSPackage -Type tar @releaseTagParam } } } finally @@ -41,17 +44,20 @@ finally } $linuxPackages = Get-ChildItem "$location/powershell*" -Include *.deb,*.rpm - -foreach($linuxPackage in $linuxPackages) -{ + +foreach ($linuxPackage in $linuxPackages) +{ Copy-Item -Path $linuxPackage.FullName -Destination $destination -force } -if($AppImage.IsPresent) +$extraPackages = @() +switch ($ExtraPackage) { - $appImages = Get-ChildItem -Path $location -Filter '*.AppImage' - foreach($appImageFile in $appImages) - { - Copy-Item -Path $appImageFile.FullName -Destination $destination -force - } + "AppImage" { $extraPackages += @(Get-ChildItem -Path $location -Filter '*.AppImage') } + "tar" { $extraPackages += @(Get-ChildItem -Path $location -Filter '*.tar.gz') } +} + +foreach ($extraPkgFile in $extraPackages) +{ + Copy-Item -Path $extraPkgFile.FullName -Destination $destination -force } diff --git a/tools/releaseBuild/build.json b/tools/releaseBuild/build.json index 82565c9a147..1b309bc3dd8 100644 --- a/tools/releaseBuild/build.json +++ b/tools/releaseBuild/build.json @@ -29,7 +29,7 @@ { "Name": "ubuntu.14.04", "RepoDestinationPath": "/PowerShell", - "BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_ -AppImage", + "BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_ -ExtraPackage AppImage", "BuildDockerOptions": [ "--cap-add", "SYS_ADMIN", @@ -43,7 +43,7 @@ "AdditionalContextFiles" :[ "./tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1"], "DockerImageName": "ps-ubunutu-14-04" }, - { + { "Name": "ubuntu.16.04", "RepoDestinationPath": "/PowerShell", "BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_", @@ -51,10 +51,10 @@ "DockerFile": "./tools/releaseBuild/Images/microsoft_powershell_ubuntu16.04/Dockerfile", "DockerImageName": "ps-ubunutu-16-04" }, - { + { "Name": "centos.7", "RepoDestinationPath": "/PowerShell", - "BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_", + "BuildCommand": "/PowerShellPackage.ps1 -location _RepoDestinationPath_ -destination _DockerVolume_ -ReleaseTag _ReleaseTag_ -ExtraPackage tar", "AdditionalContextFiles" :[ "./tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1"], "DockerFile": "./tools/releaseBuild/Images/microsoft_powershell_centos7/Dockerfile", "DockerImageName": "ps-centos-7" From 9ac0739d942cad615a15fdb7bc7fc0fdfcce8a00 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 11 Oct 2017 16:52:12 -0700 Subject: [PATCH 2/2] Address comments --- .../GenericLinuxFiles/PowerShellPackage.ps1 | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 b/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 index fae166a2eec..e38c22800e1 100644 --- a/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 +++ b/tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1 @@ -43,21 +43,10 @@ finally Pop-Location } -$linuxPackages = Get-ChildItem "$location/powershell*" -Include *.deb,*.rpm - +$linuxPackages = Get-ChildItem "$location/powershell*" -Include *.deb,*.rpm,*.AppImage,*.tar.gz foreach ($linuxPackage in $linuxPackages) { - Copy-Item -Path $linuxPackage.FullName -Destination $destination -force -} - -$extraPackages = @() -switch ($ExtraPackage) -{ - "AppImage" { $extraPackages += @(Get-ChildItem -Path $location -Filter '*.AppImage') } - "tar" { $extraPackages += @(Get-ChildItem -Path $location -Filter '*.tar.gz') } -} - -foreach ($extraPkgFile in $extraPackages) -{ - Copy-Item -Path $extraPkgFile.FullName -Destination $destination -force + $filePath = $linuxPackage.FullName + Write-Verbose "Copying $filePath to $destination" -Verbose + Copy-Item -Path $filePath -Destination $destination -force }