function Update-ModuleMeta { <# .SYNOPSIS Updates the module manifest file fields to prepare the new build. .DESCRIPTION Replaces the version fields in the manifest file. Uses Drone env vars populated by pushed tags. .INPUTS [None] No pipeline input. .OUTPUTS [None] No pipeline output. .EXAMPLE Import-Module -Name DroneHelper; Update-ModuleMeta #> [CmdletBinding()] [OutputType()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseConsistentWhitespace', '', Justification = 'Hashtable bug in ScriptAnalyzer 1.19.1' )] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseShouldProcessForStateChangingFunctions', '', Justification = 'system state does not change permanent in temp build clients.' )] param ( [Parameter(Mandatory = $false)] [ValidateScript( { if (Test-Path -Path $_) { return $true } else { throw 'Could not find file: {0}' -f $_ } } )] [ValidateNotNullOrEmpty()] [string]$Path ) process { 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 if ($null -ne $Env:DRONE_SEMVER_PRERELEASE) { $nPreRelease = $Env:DRONE_SEMVER_PRERELEASE } $DataParams = @{ Path = $ManifestFilePath 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) { $ModManifestData.PrivateData.PSData.Prerelease = $nPreRelease } $ManifestData = Test-ModuleManifest -Path $ManifestFilePath if ( ($nVersion -ne $ManifestData.Version) -or ($nPreRelease -ne $ManifestData.PrivateData.PSData.Prerelease) ) { $OutputFileParams = @{ Path = $ManifestFilePath #PassThru = $true Encoding = 'utf8NoBom' Force = $true Verbose = $VerbosePreference } 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-Warning -Message 'Identical version given. Skipping update.' } } else { Write-Warning -Message 'Could not read the new Tag / Semver!' } } else { Write-Warning -Message 'This pipeline was not triggered by a tag.' } } else { Write-Warning -Message 'Running outside of drone.io pipeline. Skipping module update!' } } }