OCram85/DroneHelper
OCram85
/
DroneHelper
Archived
1
0
Fork 0
This repository has been archived on 2023-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
DroneHelper/src/Build/Update-ModuleMeta.ps1

76 lines
2.6 KiB
PowerShell

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 ()
process {
if ($Env:DRONE) {
$Repo = Get-RepoPath
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
}
$ModManifestParams = @{
Path = $Repo.Src.Manifest.Item.FullName
ModuleVersion = $nVersion
ErrorAction = 'Stop'
}
if ($nPreRelease) {
$ModManifestParams.PreRelease = $nPreRelease
}
$ManifestData = Test-ModuleManifest -Path $Repo.Src.Manifest.Item.FullName
if (
($nVersion -ne $ManifestData.Version) -or
($nVersion -ne $ManifestData.PrivateData.PSData.Prerelease)
) {
Update-ModuleManifest @ModManifestParams
}
else {
Write-Verbose -Message 'Identical version given. Skipping update.'
}
}
else {
Write-Verbose -Message 'Could not read the new Tag / Semver!'
}
}
else {
Write-Verbose -Message 'This pipeline was not triggered by a tag.'
}
}
else {
Write-Verbose -Message 'Running outside of drone.io pipeline. Skipping module update!'
}
}
}