From c0a8334d46502a04aeebdae4f73342dbbb552376 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 27 Jul 2022 13:02:19 +0200 Subject: [PATCH] add path parameter --- src/Build/Update-ModuleMeta.Tests.ps1 | 23 +---------------------- src/Build/Update-ModuleMeta.ps1 | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/Build/Update-ModuleMeta.Tests.ps1 b/src/Build/Update-ModuleMeta.Tests.ps1 index f402e3a..ad19e28 100644 --- a/src/Build/Update-ModuleMeta.Tests.ps1 +++ b/src/Build/Update-ModuleMeta.Tests.ps1 @@ -20,27 +20,6 @@ Describe 'Update-ModuleMeta' { } Context 'Unit Tests' -Tag 'Unit' { - BeforeAll { - # Mock Drone env if its not present - if (!$Env:DRONE) { - $Env:DRONE = $true - $Env:DRONE_BUILD_EVENT = 'tag' - $Env:DRONE_SEMVER = '9.9.9-dev9' - $Env:DRONE_SEMVER_SHORT = '9.9.9' - $Env:DRONE_SEMVER_PRERELEASE = 'dev9' - } - Mock 'Get-RepoPath' -ModuleName 'DroneHelper' { - return @{ - Src = @{ - Manifest = @{ - Item = @{ - FullName = './resources/MyModule.psd1' - } - } - } - } - } - } It 'Update test module manifest' { { $Env:DRONE = $true @@ -48,7 +27,7 @@ Describe 'Update-ModuleMeta' { $Env:DRONE_SEMVER = '9.9.9-dev9' $Env:DRONE_SEMVER_SHORT = '9.9.9' $Env:DRONE_SEMVER_PRERELEASE = 'dev9' - Update-ModuleMeta -Verbose + Update-ModuleMeta -Path './resources/MyModule.psd1' -Verbose } | Should -Not -Throw $data = Import-PowerShellDataFile -Path './resources/MyModule.psd1' $data.ModuleVersion | Should -Be '9.9.9' diff --git a/src/Build/Update-ModuleMeta.ps1 b/src/Build/Update-ModuleMeta.ps1 index 9431c77..69cbc89 100644 --- a/src/Build/Update-ModuleMeta.ps1 +++ b/src/Build/Update-ModuleMeta.ps1 @@ -27,11 +27,28 @@ function Update-ModuleMeta { '', Justification = 'system state does not change permanent in temp build clients.' )] - param () + param ( + [Parameter(Mandatory = $false)] + [ValidateScript( + { + if (!(Test-Path -Path $_)) { + throw 'Could not find file: {0}' -f $_ + } + } + )] + [ValidateNotNullOrEmpty()] + [string]$Path + ) process { - if ($Env:DRONE) { + if (!$Path) { $Repo = Get-RepoPath + $ManifestFilePath = $Repo.Src.Manifest.Item.FullName + } + else { + $ManifestFilePath = $Path + } + if ($Env:DRONE) { if ($Env:DRONE_BUILD_EVENT -eq 'tag') { if ($null -ne $Env:DRONE_SEMVER) { $nVersion = $Env:DRONE_SEMVER_SHORT @@ -40,7 +57,7 @@ function Update-ModuleMeta { $nPreRelease = $Env:DRONE_SEMVER_PRERELEASE } $DataParams = @{ - Path = $Repo.Src.Manifest.Item.FullName + Path = $ManifestFilePath ErrorAction = 'Stop' } # Getting the module manifest as imported object @@ -63,7 +80,7 @@ function Update-ModuleMeta { $ModManifestData.PrivateData.PSData.Prerelease = $nPreRelease } - $ManifestData = Test-ModuleManifest -Path $Repo.Src.Manifest.Item.FullName + $ManifestData = Test-ModuleManifest -Path $ManifestFilePath if ( ($nVersion -ne $ManifestData.Version) -or