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,9 +233,11 @@ function Start-PSPackage {
}
foreach ($Distro in $Script:DebianDistributions) {
$Arguments["Distribution"] = $Distro
if ($PSCmdlet.ShouldProcess("Create DEB Package for $Distro")) {
New-UnixPackage @Arguments
}
}
}
default {
$Arguments = @{
Type = $_
@ -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,7 +11,9 @@ param (
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+\.\d+)?$")]
[ValidateNotNullOrEmpty()]
[string]$ReleaseTag,
[switch]$AppImage
[ValidateSet("AppImage", "tar")]
[string[]]$ExtraPackage
)
$releaseTagParam = @{}
@ -30,9 +32,10 @@ try {
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
$linuxPackages = Get-ChildItem "$location/powershell*" -Include *.deb,*.rpm,*.AppImage,*.tar.gz
foreach ($linuxPackage in $linuxPackages)
{
Copy-Item -Path $linuxPackage.FullName -Destination $destination -force
}
if($AppImage.IsPresent)
{
$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",
@ -54,7 +54,7 @@
{
"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"