add path parameter
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
OCram85 2022-07-27 13:02:19 +02:00
parent f5494e9eb2
commit c0a8334d46
2 changed files with 22 additions and 26 deletions

View File

@ -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'

View File

@ -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