Support creating tarball package for Linux and macOS (#5085)

* Support creating tarball package for Linux and macOS

* Address comments
This commit is contained in:
Dongbo Wang 2017-10-12 13:36:46 -07:00 committed by Aditya Patwardhan
parent 94a71b05d4
commit a391998a25
4 changed files with 108 additions and 36 deletions

1
.gitignore vendored
View file

@ -38,6 +38,7 @@ dotnet-uninstall-debian-packages.sh
# Ignore packages
*.deb
*.tar.gz
*.zip
*.rpm
*.pkg

View file

@ -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(

View file

@ -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
@ -40,18 +43,10 @@ finally
Pop-Location
}
$linuxPackages = Get-ChildItem "$location/powershell*" -Include *.deb,*.rpm
foreach($linuxPackage in $linuxPackages)
{
Copy-Item -Path $linuxPackage.FullName -Destination $destination -force
}
if($AppImage.IsPresent)
$linuxPackages = Get-ChildItem "$location/powershell*" -Include *.deb,*.rpm,*.AppImage,*.tar.gz
foreach ($linuxPackage in $linuxPackages)
{
$appImages = Get-ChildItem -Path $location -Filter '*.AppImage'
foreach($appImageFile in $appImages)
{
Copy-Item -Path $appImageFile.FullName -Destination $destination -force
}
$filePath = $linuxPackage.FullName
Write-Verbose "Copying $filePath to $destination" -Verbose
Copy-Item -Path $filePath -Destination $destination -force
}

View file

@ -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"