Skip to content

Commit

Permalink
Zip PowerShell module + remove extracted files from GitHub releases (#…
Browse files Browse the repository at this point in the history
…148)

* devolutions-gateway: zip PowerShell module and remove extracted artifacts from GitHub releases

* devolutions-gateway: improve PowerShell module integration into build pipeline

* devolutions-gateway: fix PowerShell module detection in Windows PowerShell

* devolutions-gateway: add PowerShell module nupkg building

Co-authored-by: Marc-André Moreau <mamoreau@devolutions.net>
  • Loading branch information
awakecoding and Marc-André Moreau authored Mar 24, 2021
1 parent 048df20 commit 2f1db36
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 8 deletions.
1 change: 1 addition & 0 deletions ci/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ stages:
DGATEWAY_EXECUTABLE: "$(DGatewayExecutable)"
DGATEWAY_PACKAGE: "$(DGatewayPackage)"
DGATEWAY_PSMODULE_PATH: "$(DGatewayPSModulePath)"
DGATEWAY_PSMODULE_CLEAN: "1"
SIGNTOOL_NAME: "$(SignToolName)"
displayName: Packaging Devolutions Gateway

Expand Down
88 changes: 81 additions & 7 deletions ci/tlk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,64 @@ function Merge-Tokens
$OutputValue
}

function New-ModulePackage
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0)]
[string] $InputPath,
[Parameter(Mandatory=$true,Position=1)]
[string] $OutputPath,
[string] $TempPath
)

$UniqueId = New-Guid

if ([string]::IsNullOrEmpty($TempPath)) {
$TempPath = [System.IO.Path]::GetTempPath()
}

$PSRepoName = "psrepo-$UniqueId"
$PSRepoPath = Join-Path $TempPath $UniqueId

if (-Not (Test-Path -Path $InputPath -PathType 'Container')) {
throw "`"$InputPath`" does not exist"
}

$PSModulePath = $InputPath
$PSManifestFile = $(@(Get-ChildItem -Path $PSModulePath -Depth 1 -Filter "*.psd1")[0]).FullName
$PSManifest = Import-PowerShellDataFile -Path $PSManifestFile
$PSModuleName = $(Get-Item $PSManifestFile).BaseName
$PSModuleVersion = $PSManifest.ModuleVersion

New-Item -Path $PSRepoPath -ItemType Directory -ErrorAction SilentlyContinue | Out-Null

$Params = @{
Name = $PSRepoName;
SourceLocation = $PSRepoPath;
PublishLocation = $PSRepoPath;
InstallationPolicy = "Trusted";
}

Register-PSRepository @Params | Out-Null

$OutputFileName = "${PSModuleName}.${PSModuleVersion}.nupkg"
$PSModulePackage = Join-Path $PSRepoPath $OutputFileName
Remove-Item -Path $PSModulePackage -ErrorAction 'SilentlyContinue'
Publish-Module -Path $PSModulePath -Repository $PSRepoName

Unregister-PSRepository -Name $PSRepoName | Out-Null

New-Item -Path $OutputPath -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
$OutputFile = Join-Path $OutputPath $OutputFileName
Copy-Item $PSModulePackage $OutputFile

Remove-Item $PSmodulePackage
Remove-Item -Path $PSRepoPath

$OutputFile
}

function Get-TlkPlatform {
param(
[Parameter(Position=0)]
Expand Down Expand Up @@ -281,11 +339,9 @@ class TlkRecipe
}

[void] Package_Windows() {
$PackageVersion = $this.Version
$ShortVersion = $this.Version.Substring(2) # msi version
$TargetArch = $this.Target.WindowsArchitecture()

$ModuleName = "DevolutionsGateway"
$ModuleVersion = "2021.1.1" # both versions should match

Push-Location
Set-Location "$($this.SourcePath)/package/$($this.Target.Platform)"
Expand All @@ -295,15 +351,28 @@ class TlkRecipe
} else {
throw ("Specify DGATEWAY_EXECUTABLE environment variable")
}

if (Test-Path Env:DGATEWAY_PSMODULE_PATH) {
$DGatewayPSModulePath = $Env:DGATEWAY_PSMODULE_PATH
} else {
Save-Module -Name $ModuleName -Force -RequiredVersion $ModuleVersion -Repository 'PSGallery' -Path '.'
Remove-Item -Path "${ModuleName}/${ModuleVersion}/PSGetModuleInfo.xml" -ErrorAction 'SilentlyContinue'
$DGatewayPSModulePath = "${ModuleName}/${ModuleVersion}"
throw ("Specify DGATEWAY_PSMODULE_PATH environment variable")
}

$PSManifestFile = $(@(Get-ChildItem -Path $DGatewayPSModulePath -Depth 1 -Filter "*.psd1")[0]).FullName
$PSManifest = Import-PowerShellDataFile -Path $PSManifestFile
$PSModuleName = $(Get-Item $PSManifestFile).BaseName
$PSModuleVersion = $PSManifest.ModuleVersion

if ($PackageVersion -ne $PSModuleVersion) {
Write-Warning "PowerShell module version mismatch: $PSModuleVersion (expected: $PackageVersion)"
}

$PSModuleParentPath = Split-Path $DGatewayPSModulePath -Parent
$PSModuleZipFilePath = Join-Path $PSModuleParentPath "$PSModuleName-ps-$PSModuleVersion.zip"
Compress-Archive -Path $DGatewayPSModulePath -Destination $PSModuleZipFilePath

New-ModulePackage $DGatewayPSModulePath $PSModuleParentPath

$WixExtensions = @('WixUtilExtension', 'WixUIExtension', 'WixFirewallExtension')
$WixExtensions += $(Join-Path $(Get-Location) 'WixUserPrivilegesExtension.dll')

Expand Down Expand Up @@ -347,6 +416,11 @@ class TlkRecipe
& 'cscript.exe' "/nologo" "WiLangId.vbs" "$($this.PackageName).msi" "Package" "1033,1036"
}

if (Test-Path Env:DGATEWAY_PSMODULE_CLEAN) {
# clean up the extracted PowerShell module directory
Remove-Item -Path $DGatewayPSModulePath -Recurse
}

if (Test-Path Env:DGATEWAY_PACKAGE) {
$DGatewayPackage = $Env:DGATEWAY_PACKAGE
Copy-Item -Path "$($this.PackageName).msi" -Destination $DGatewayPackage
Expand Down
2 changes: 1 addition & 1 deletion powershell/DevolutionsGateway/DevolutionsGateway.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
RootModule = 'DevolutionsGateway.psm1'

# Version number of this module.
ModuleVersion = '2020.3.1'
ModuleVersion = '2021.1.1'

# Supported PSEditions
CompatiblePSEditions = 'Desktop', 'Core'
Expand Down

0 comments on commit 2f1db36

Please sign in to comment.