Skip to content

Instantly share code, notes, and snippets.

@markwragg
Created January 19, 2017 15:44
Show Gist options
  • Save markwragg/4d243b4ff57e0092800df5e9f1d401ff to your computer and use it in GitHub Desktop.
Save markwragg/4d243b4ff57e0092800df5e9f1d401ff to your computer and use it in GitHub Desktop.
The start of a build script which publishes the module to PSGallery having incremented the version number
# Required module - BuildHelpers: https://github.com/RamblingCookieMonster/BuildHelpers
[cmdletbinding()]
Param(
[string]$PSGalleryKey = (Import-Clixml PSGalleryKey.xml), #So I don't put it on the internet.
[string]$Module,
[string]$Version,
[switch]$Publish
)
$ModuleData = (Get-Module $Module)
If (!$Version) {
Try {
$Version = (Get-NextPSGalleryVersion $Module)
} Catch {
Write-Error "No version specified and could not determine automatically." -Category ConnectionError
Break
}
}
If ($Version -and $Version -ne '0.0.1') {
Try {
Update-ModuleManifest -Path ($ModuleData.Path) -ModuleVersion $Version
Write-Verbose "Module manifest updated with -ModuleVersion $Version"
If ($Publish) {
Try {
Publish-Module -Name $Module -NuGetApiKey $PSGalleryKey
Write-Verbose "Published $Module to PSGallery"
} Catch {
Write-Error "Could not publish to PSGallery." -Category ConnectionError
}
}
} Catch {
Write-Error "Could not update module manifest." -Category ConnectionError
}
}Else{
Write-Error "No version specified." -Category InvalidArgument
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment