fix module manifest update logic
This commit is contained in:
parent
6a314eeb48
commit
0784cddb6f
@ -18,4 +18,40 @@ Describe 'Update-ModuleMeta' {
|
||||
$foo.Description[0].Text.Length | Should -BeGreaterThan 5
|
||||
}
|
||||
}
|
||||
|
||||
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' {
|
||||
{ Update-ModuleMeta } | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Updated manifest is valid' {
|
||||
{ Test-ModuleManifest -Path './resources/MyModule.psd1' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'External dependencies prop is untouched' {
|
||||
$d = Test-ModuleManifest -Path './resources/MyModule.psd1'
|
||||
$d.PrivateData.PSData.ExternalModuleDependencies.Count | Should -Be '2'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,22 +39,53 @@ function Update-ModuleMeta {
|
||||
if ($null -ne $Env:DRONE_SEMVER_PRERELEASE) {
|
||||
$nPreRelease = $Env:DRONE_SEMVER_PRERELEASE
|
||||
}
|
||||
$ModManifestParams = @{
|
||||
Path = $Repo.Src.Manifest.Item.FullName
|
||||
ModuleVersion = $nVersion
|
||||
ErrorAction = 'Stop'
|
||||
$DataParams = @{
|
||||
Path = $Repo.Src.Manifest.Item.FullName
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
# Getting the module manifest as imported object
|
||||
try {
|
||||
$ModManifestData = Import-PowerShellDataFile @DataParams
|
||||
}
|
||||
catch {
|
||||
$_.Exception.Message | Write-Debug
|
||||
$ErrorParams = @{
|
||||
Message = "Could not import the module manifest file."
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
Write-Error @ErrorParams
|
||||
}
|
||||
# Updating the new module version
|
||||
$ModManifestData.ModuleVersion = $nVersion
|
||||
|
||||
# Updating the prerelease property if there is one
|
||||
if ($nPreRelease) {
|
||||
$ModManifestParams.PreRelease = $nPreRelease
|
||||
$ModManifestData.PrivateData.PSData.Prerelease = $nPreRelease
|
||||
}
|
||||
|
||||
$ManifestData = Test-ModuleManifest -Path $Repo.Src.Manifest.Item.FullName
|
||||
|
||||
if (
|
||||
($nVersion -ne $ManifestData.Version) -or
|
||||
($nVersion -ne $ManifestData.PrivateData.PSData.Prerelease)
|
||||
($nPreRelease -ne $ManifestData.PrivateData.PSData.Prerelease)
|
||||
) {
|
||||
Update-ModuleManifest @ModManifestParams
|
||||
$OutputFileParams = @{
|
||||
Path = $Repo.Src.Manifest.Item.FullName
|
||||
PassThru = $true
|
||||
Encoding = 'utf8NoBom'
|
||||
Force = $true
|
||||
}
|
||||
try {
|
||||
$ModManifestData | ConvertTo-Psd | Set-Content @OutputFileParams
|
||||
}
|
||||
catch {
|
||||
$_.Exception.Message | Write-Debug
|
||||
$ErrorParams = @{
|
||||
Message = "Failed to update the module manifest file"
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
Write-Error @ErrorParams
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Verbose -Message 'Identical version given. Skipping update.'
|
||||
|
Reference in New Issue
Block a user