Skip to content

Commit 0527a88

Browse files
authored
ci: fix powershell publishing job (#1426)
Create a tarball archive instead of a zip archive for the PowerShell module. - It’s unclear to me why, but the PowerShell module we sign and re-archive in the package workflow is corrupted when we try to decompress it in the release workflow. - This is something I could verify locally using the `7z` command. The `Publish-Module` cmdlet was also failing with a cryptic error: > Write-Error: Cannot retrieve the dynamic parameters for the cmdlet. > Loading repository store failed: Could not find a part of the path > '/home/runner/.local/share/PSResourceGet/PSResourceRepository.xml'. I walked around that by switching to the newer `Publish-PSResource` cmdlet, which is a more modern rewrite of `Publish-Module`.
1 parent 9224589 commit 0527a88

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,14 +467,22 @@ jobs:
467467
- name: Build module
468468
shell: pwsh
469469
run: |
470+
$PSModuleVersion = "${{ needs.preflight.outputs.version }}"
471+
470472
./powershell/build.ps1
473+
471474
$PSModuleName = "DevolutionsGateway"
472-
$PSModuleVersion = "${{ needs.preflight.outputs.version }}"
473-
$PSModuleOutputPath = Join-Path "powershell" "package" $PSModuleName
475+
$PSModuleParentPath = Join-Path "powershell" "package"
476+
Write-Host "PSModuleOutputPath = $PSModuleParentPath"
477+
474478
$PSStagingPath = Join-Path "powershell-staging" "PowerShell"
479+
Write-Host "PSStagingPath = $PSStagingPath"
475480
New-Item -Path $PSStagingPath -ItemType Directory | Out-Null
476-
$PSModuleZipFilePath = Join-Path $PSStagingPath "$PSModuleName-ps-$PSModuleVersion.zip"
477-
Compress-Archive -Path $PSModuleOutputPath -Destination $PSModuleZipFilePath
481+
482+
$PSModuleTarFilePath = Join-Path $PSStagingPath "$PSModuleName-ps-$PSModuleVersion.tar"
483+
Write-Host "PSModuleTarFilePath = $PSModuleTarFilePath"
484+
485+
tar -cvf "$PSModuleTarFilePath" -C "$PSModuleParentPath" "$PSModuleName"
478486
479487
- name: Pester tests
480488
shell: pwsh
@@ -630,14 +638,19 @@ jobs:
630638
TARGET_OUTPUT_PATH: ${{ steps.load-variables.outputs.target-output-path }}
631639
DGATEWAY_EXECUTABLE: ${{ steps.load-variables.outputs.dgateway-executable }}
632640
run: |
641+
Set-PSDebug -Trace 1
642+
633643
if ($Env:RUNNER_OS -eq "Windows") {
634644
$Env:DGATEWAY_PACKAGE = "${{ steps.load-variables.outputs.dgateway-package }}"
635645
$Env:DGATEWAY_LIB_XMF_PATH = Join-Path "native-libs" "xmf.dll" | Resolve-Path
636646
637647
$PSStagingPath = Join-Path (Get-Location) "powershell-staging"
648+
Write-Host "PSStagingPath = $PSStagingPath"
638649
$PSModuleOutputPath = Join-Path $PSStagingPath "DevolutionsGateway"
639-
$PSModuleZipFilePath = Get-ChildItem -Path "$PSStagingPath/PowerShell" "*-ps-*.zip" | Select-Object -First 1
640-
Expand-Archive -Path $PSModuleZipFilePath -Destination $PSStagingPath
650+
$PSModuleTarFilePath = Get-ChildItem -Path "$PSStagingPath/PowerShell" "*-ps-*.tar" | Select-Object -First 1
651+
tar -xvf "$PSModuleTarFilePath" -C "$PSStagingPath"
652+
Get-ChildItem -Path "$PSStagingPath" -Recurse
653+
641654
$Env:DGATEWAY_PSMODULE_PATH = $PSModuleOutputPath
642655
} else {
643656
$Env:DGATEWAY_LIB_XMF_PATH = Join-Path "native-libs" "libxmf.so" | Resolve-Path

.github/workflows/package.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ jobs:
231231
232232
. .\ci\PSModuleHelpers.ps1
233233
$PSModuleOutputPath = Join-Path ${{ runner.temp }} ${{ matrix.project }} "PowerShell"
234-
$PSModuleZipFilePath = Get-ChildItem -Path $PSModuleOutputPath "DevolutionsGateway-ps-*.zip" | Select-Object -First 1
235-
Expand-Archive -Path $PSModuleZipFilePath -Destination $PSModuleOutputPath
234+
$PSModuleTarFilePath = Get-ChildItem -Path $PSModuleOutputPath "DevolutionsGateway-ps-*.tar" | Select-Object -First 1
235+
tar -xvf "$PSModuleTarFilePath" -C "$PSModuleOutputPath"
236236
$DGatewayPSModulePath = Join-Path $PSModuleOutputPath DevolutionsGateway
237237
238238
$IncludePattern = @('*.ps1', '*.psd1', '*.psm1', 'DevolutionsGateway.dll')
@@ -248,11 +248,21 @@ jobs:
248248
AzureSignTool @Params $_.FullName
249249
}
250250
251-
Remove-Item $PSModuleZipFilePath -ErrorAction SilentlyContinue | Out-Null
252-
Compress-Archive -Path $DGatewayPSModulePath -Destination $PSModuleZipFilePath -CompressionLevel Optimal
251+
Remove-Item $PSModuleTarFilePath -ErrorAction SilentlyContinue | Out-Null
253252
254253
$PSModuleParentPath = Split-Path $DGatewayPSModulePath -Parent
255254
255+
# For some reason, when using Compress-Archive we end up with a corrupted archive once in the release.yml workflow.
256+
# Maybe because of the double compression via the upload-artifact action?
257+
# With a tarball archive, there is no problem.
258+
Write-Host "Recreate archive at $PSModuleTarFilePath"
259+
tar -cvf "$PSModuleTarFilePath" -C "$PSModuleParentPath" DevolutionsGateway
260+
261+
# Verify the archive.
262+
Write-Host "Verify archive at $PSModuleTarFilePath"
263+
tar -t "$PSModuleTarFilePath"
264+
265+
Set-PSDebug -Off # Too many traces are logged when running New-ModulePackage.
256266
New-ModulePackage $DGatewayPSModulePath $PSModuleParentPath
257267
258268
- name: Sign executables

.github/workflows/release.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ jobs:
170170
New-Item -ItemType Directory -Path $TargetPath
171171
tar -xvzf $WebAppArchive.FullName -C $TargetPath --strip-components=1
172172
173-
$PowerShellArchive = Get-ChildItem -Recurse -Filter "DevolutionsGateway-ps-*.zip" | Select-Object -First 1
174-
Expand-Archive -Path $PowerShellArchive -DestinationPath "$PkgDir"
173+
$PowerShellArchive = Get-ChildItem -Recurse -Filter "DevolutionsGateway-ps-*.tar" | Select-Object -First 1
174+
tar -xvf "$PowerShellArchive" -C "$PkgDir"
175175
176176
- name: Build container
177177
id: build-container
@@ -277,27 +277,32 @@ jobs:
277277
shell: pwsh
278278
run: Remove-Item -Path (Join-Path PowerShell DevolutionsGateway) -Recurse -ErrorAction Ignore
279279

280+
- name: Install PSResourceGet
281+
shell: pwsh
282+
run: |
283+
Install-PSResource Microsoft.PowerShell.PSResourceGet -Scope CurrentUser -TrustRepository
284+
280285
- name: Publish PowerShell module
281286
shell: pwsh
282287
run: |
283-
Set-PSDebug -Trace 1
288+
$Archive = Get-ChildItem -Recurse -Filter "*-ps-*.tar" -File
289+
Write-Host "Archive = $Archive"
284290
285-
$Archive = Get-ChildItem -Recurse -Filter "*-ps-*.zip" -File
286-
Expand-Archive -Path $Archive -DestinationPath 'PowerShell'
291+
tar -xvf "$Archive" -C './PowerShell'
292+
Get-ChildItem -Path "./PowerShell" -Recurse
287293
288-
$PublishCmd = @('Publish-Module', '-Force', '-Path', (Join-Path PowerShell DevolutionsGateway), '-NugetApiKey', '${{ secrets.PS_GALLERY_NUGET_API_KEY }}')
294+
$PublishCmd = @('Publish-PSResource', '-Repository', 'PSGallery', '-Path', (Join-Path PowerShell DevolutionsGateway), '-ApiKey', '${{ secrets.PS_GALLERY_NUGET_API_KEY }}')
289295
290296
$DryRun = [System.Convert]::ToBoolean('${{ inputs.dry-run }}')
291297
if ($DryRun) {
292298
$PublishCmd += '-WhatIf'
293299
}
294300
$PublishCmd = $PublishCmd -Join ' '
295-
Write-Host $PublishCmd
301+
Write-Host "PublishCmd = $PublishCmd"
296302
297303
try {
298304
Invoke-Expression $PublishCmd
299-
}
300-
catch {
305+
} catch {
301306
if ($_.Exception.Message -ilike "*cannot be published as the current version*is already available in the repository*") {
302307
echo "::warning::PowerShell module not published; this version is already listed on PSGallery"
303308
} else {

0 commit comments

Comments
 (0)