Switch packages for Ubuntu & macOS to use tar.gz format instead of zip (#6)

Switch to using tar.gz format for Ubuntu and macOS systems because it is much more common on nix systems which is important in container scenarios
This commit was merged in pull request #6.
This commit is contained in:
Maxim Lobanov
2020-04-23 18:42:48 +03:00
committed by GitHub
parent e510e2cfd6
commit 9f83a0c6de
7 changed files with 65 additions and 22 deletions

View File

@@ -14,16 +14,8 @@ jobs:
filePath: './builders/build-node.ps1' filePath: './builders/build-node.ps1'
arguments: '-Version $(Version) -Platform $(Platform) -Architecture $(Architecture)' arguments: '-Version $(Version) -Platform $(Platform) -Architecture $(Architecture)'
- task: ArchiveFiles@2
displayName: 'Archive artifact'
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)'
archiveType: zip
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/node-$(Version)-$(Platform)-$(Architecture).zip'
- task: PublishPipelineArtifact@1 - task: PublishPipelineArtifact@1
displayName: 'Publish Artifact: Node.js $(Version)' displayName: 'Publish Artifact: Node.js $(Version)'
inputs: inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/node-$(Version)-$(Platform)-$(Architecture).zip' targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: 'node-$(Version)-$(Platform)-$(Architecture)' artifactName: 'node-$(Version)-$(Platform)-$(Architecture)'

View File

@@ -8,7 +8,7 @@ jobs:
submodules: true submodules: true
- task: PowerShell@2 - task: PowerShell@2
displayName: Fully cleanup the toolcache directory displayName: Fully cleanup the toolcache directory before testing
inputs: inputs:
TargetType: inline TargetType: inline
script: | script: |
@@ -25,7 +25,7 @@ jobs:
- task: ExtractFiles@1 - task: ExtractFiles@1
inputs: inputs:
archiveFilePatterns: '$(Build.ArtifactStagingDirectory)/node-$(Version)-$(Platform)-$(Architecture).zip' archiveFilePatterns: '$(Build.ArtifactStagingDirectory)/node-$(Version)-$(Platform)-$(Architecture).*'
destinationFolder: $(Build.BinariesDirectory) destinationFolder: $(Build.BinariesDirectory)
cleanDestinationFolder: false cleanDestinationFolder: false

View File

@@ -27,7 +27,7 @@ class NixNodeBuilder : NodeBuilder {
) : Base($version, $platform, $architecture) { ) : Base($version, $platform, $architecture) {
$this.InstallationTemplateName = "nix-setup-template.sh" $this.InstallationTemplateName = "nix-setup-template.sh"
$this.InstallationScriptName = "setup.sh" $this.InstallationScriptName = "setup.sh"
$this.OutputArtifactName = "tool.tar.gz" $this.OutputArtifactName = "node-$Version-$Platform-$Architecture.tar.gz"
} }
[uri] GetBinariesUri() { [uri] GetBinariesUri() {
@@ -41,7 +41,7 @@ class NixNodeBuilder : NodeBuilder {
} }
[void] ExtractBinaries($archivePath) { [void] ExtractBinaries($archivePath) {
Extract-TarArchive -ArchivePath $archivePath -OutputDirectory $this.ArtifactLocation Extract-TarArchive -ArchivePath $archivePath -OutputDirectory $this.WorkFolderLocation
} }
[void] CreateInstallationScript() { [void] CreateInstallationScript() {
@@ -50,7 +50,7 @@ class NixNodeBuilder : NodeBuilder {
Create Node.js artifact installation script based on template specified in InstallationTemplateName property. Create Node.js artifact installation script based on template specified in InstallationTemplateName property.
#> #>
$installationScriptLocation = New-Item -Path $this.ArtifactLocation -Name $this.InstallationScriptName -ItemType File $installationScriptLocation = New-Item -Path $this.WorkFolderLocation -Name $this.InstallationScriptName -ItemType File
$installationTemplateLocation = Join-Path -Path $this.InstallationTemplatesLocation -ChildPath $this.InstallationTemplateName $installationTemplateLocation = Join-Path -Path $this.InstallationTemplatesLocation -ChildPath $this.InstallationTemplateName
$installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw $installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw
@@ -59,4 +59,9 @@ class NixNodeBuilder : NodeBuilder {
Write-Debug "Done; Installation script location: $installationScriptLocation)" Write-Debug "Done; Installation script location: $installationScriptLocation)"
} }
[void] ArchiveArtifact() {
$OutputPath = Join-Path $this.ArtifactFolderLocation $this.OutputArtifactName
Create-TarArchive -SourceFolder $this.WorkFolderLocation -ArchivePath $OutputPath
}
} }

View File

@@ -30,7 +30,8 @@ class NodeBuilder {
[string] $Platform [string] $Platform
[string] $Architecture [string] $Architecture
[string] $TempFolderLocation [string] $TempFolderLocation
[string] $ArtifactLocation [string] $WorkFolderLocation
[string] $ArtifactFolderLocation
[string] $InstallationTemplatesLocation [string] $InstallationTemplatesLocation
NodeBuilder ([version] $version, [string] $platform, [string] $architecture) { NodeBuilder ([version] $version, [string] $platform, [string] $architecture) {
@@ -38,8 +39,10 @@ class NodeBuilder {
$this.Platform = $platform $this.Platform = $platform
$this.Architecture = $architecture $this.Architecture = $architecture
$this.ArtifactLocation = $env:BUILD_BINARIESDIRECTORY $this.TempFolderLocation = [IO.Path]::GetTempPath()
$this.TempFolderLocation = $env:BUILD_STAGINGDIRECTORY $this.WorkFolderLocation = $env:BUILD_BINARIESDIRECTORY
$this.ArtifactFolderLocation = $env:BUILD_STAGINGDIRECTORY
$this.InstallationTemplatesLocation = Join-Path -Path $PSScriptRoot -ChildPath "../installers" $this.InstallationTemplatesLocation = Join-Path -Path $PSScriptRoot -ChildPath "../installers"
} }
@@ -89,5 +92,8 @@ class NodeBuilder {
Write-Host "Create installation script..." Write-Host "Create installation script..."
$this.CreateInstallationScript() $this.CreateInstallationScript()
Write-Host "Archive artifact"
$this.ArchiveArtifact()
} }
} }

View File

@@ -27,7 +27,7 @@ class WinNodeBuilder : NodeBuilder {
) : Base($version, $platform, $architecture) { ) : Base($version, $platform, $architecture) {
$this.InstallationTemplateName = "win-setup-template.ps1" $this.InstallationTemplateName = "win-setup-template.ps1"
$this.InstallationScriptName = "setup.ps1" $this.InstallationScriptName = "setup.ps1"
$this.OutputArtifactName = "tool.7z" $this.OutputArtifactName = "node-$Version-$Platform-$Architecture.zip"
} }
[uri] GetBinariesUri() { [uri] GetBinariesUri() {
@@ -42,9 +42,9 @@ class WinNodeBuilder : NodeBuilder {
[void] ExtractBinaries($archivePath) { [void] ExtractBinaries($archivePath) {
$extractTargetDirectory = Join-Path $this.TempFolderLocation "tempExtract" $extractTargetDirectory = Join-Path $this.TempFolderLocation "tempExtract"
Extract-7ZipArchive -ArchivePath $archivePath -OutputDirectory $extractTargetDirectory Extract-SevenZipArchive -ArchivePath $archivePath -OutputDirectory $extractTargetDirectory
$nodeOutputPath = Get-Item $extractTargetDirectory\* | Select-Object -First 1 -ExpandProperty Fullname $nodeOutputPath = Get-Item $extractTargetDirectory\* | Select-Object -First 1 -ExpandProperty Fullname
Move-Item -Path $nodeOutputPath\* -Destination $this.ArtifactLocation Move-Item -Path $nodeOutputPath\* -Destination $this.WorkFolderLocation
} }
[void] CreateInstallationScript() { [void] CreateInstallationScript() {
@@ -53,7 +53,7 @@ class WinNodeBuilder : NodeBuilder {
Create Node.js artifact installation script based on specified template. Create Node.js artifact installation script based on specified template.
#> #>
$installationScriptLocation = New-Item -Path $this.ArtifactLocation -Name $this.InstallationScriptName -ItemType File $installationScriptLocation = New-Item -Path $this.WorkFolderLocation -Name $this.InstallationScriptName -ItemType File
$installationTemplateLocation = Join-Path -Path $this.InstallationTemplatesLocation -ChildPath $this.InstallationTemplateName $installationTemplateLocation = Join-Path -Path $this.InstallationTemplatesLocation -ChildPath $this.InstallationTemplateName
$installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw $installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw
@@ -66,4 +66,9 @@ class WinNodeBuilder : NodeBuilder {
$installationTemplateContent | Out-File -FilePath $installationScriptLocation $installationTemplateContent | Out-File -FilePath $installationScriptLocation
Write-Debug "Done; Installation script location: $installationScriptLocation)" Write-Debug "Done; Installation script location: $installationScriptLocation)"
} }
[void] ArchiveArtifact() {
$OutputPath = Join-Path $this.ArtifactFolderLocation $this.OutputArtifactName
Create-SevenZipArchive -SourceFolder $this.WorkFolderLocation -ArchivePath $OutputPath
}
} }

View File

@@ -12,5 +12,21 @@ function Extract-TarArchive {
Write-Debug "Extract $ArchivePath to $OutputDirectory" Write-Debug "Extract $ArchivePath to $OutputDirectory"
tar -C $OutputDirectory -xzf $ArchivePath --strip 1 tar -C $OutputDirectory -xzf $ArchivePath --strip 1
}
function Create-TarArchive {
param(
[Parameter(Mandatory=$true)]
[String]$SourceFolder,
[Parameter(Mandatory=$true)]
[String]$ArchivePath,
[string]$CompressionType = "gz"
)
$CompressionTypeArgument = If ([string]::IsNullOrWhiteSpace($CompressionType)) { "" } else { "--${CompressionType}" }
Push-Location $SourceFolder
Write-Debug "tar -c $CompressionTypeArgument -f $ArchivePath ."
tar -c $CompressionTypeArgument -f $ArchivePath .
Pop-Location
} }

View File

@@ -2,7 +2,7 @@
.SYNOPSIS .SYNOPSIS
Unpack *.7z file Unpack *.7z file
#> #>
function Extract-7ZipArchive { function Extract-SevenZipArchive {
param( param(
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[String]$ArchivePath, [String]$ArchivePath,
@@ -13,3 +13,22 @@ function Extract-7ZipArchive {
Write-Debug "Extract $ArchivePath to $OutputDirectory" Write-Debug "Extract $ArchivePath to $OutputDirectory"
7z x $ArchivePath -o"$OutputDirectory" -y | Out-Null 7z x $ArchivePath -o"$OutputDirectory" -y | Out-Null
} }
function Create-SevenZipArchive {
param(
[Parameter(Mandatory=$true)]
[String]$SourceFolder,
[Parameter(Mandatory=$true)]
[String]$ArchivePath,
[String]$ArchiveType = "zip",
[String]$CompressionLevel = 5
)
$ArchiveTypeArgument = "-t${ArchiveType}"
$CompressionLevelArgument = "-mx=${CompressionLevel}"
Push-Location $SourceFolder
Write-Debug "7z a $ArchiveTypeArgument $CompressionLevelArgument $ArchivePath @$SourceFolder"
7z a $ArchiveTypeArgument $CompressionLevelArgument $ArchivePath $SourceFolder\*
Pop-Location
}