Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dotnet-uninstall-debian-packages.sh

# Ignore packages
*.deb
*.tar.gz
*.zip
*.rpm
*.pkg
Expand Down
104 changes: 90 additions & 14 deletions tools/packaging/packaging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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"
}

Expand All @@ -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'"
}

Expand All @@ -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'
Expand All @@ -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 {
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

I guess we can remove -Verbose

Copy link
Member Author

Choose a reason for hiding this comment

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

Here I put -Verbose explicitly to notify that the existing package is going to be removed.

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(
Expand Down
31 changes: 13 additions & 18 deletions tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand All @@ -25,33 +27,26 @@ 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
{
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
Copy link
Member

Choose a reason for hiding this comment

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

In the previous commit, *.deb and .rpm packages are found under $location/powershell while *.AppImage and *.tar.gz are found under $location. With this change *.AppImage and *.tar.gz package won't be found.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not under $location/powershell, but $location/powershell* (there is a wildcard * here). All packages start with powershell.

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
}
8 changes: 4 additions & 4 deletions tools/releaseBuild/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -43,18 +43,18 @@
"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_",
"AdditionalContextFiles" :[ "./tools/releaseBuild/Images/GenericLinuxFiles/PowerShellPackage.ps1"],
"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"
Expand Down