Created
October 2, 2019 21:14
-
-
Save Badgerati/ecec3629cdc4c326ac3c8ba0fb99fe5a to your computer and use it in GitHub Desktop.
Example script for publishing a PowerShell module to the NuGet GitHub Package Registry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# -- | |
Register the GitHub Package Registry | |
-- #> | |
$username = '<github-username>' | |
$token = '<github-personal-token>' | |
$sourceName = 'GitHub' | |
$source = "https://nuget.pkg.github.com/$username/index.json" | |
# add the github package registry as a nuget source | |
nuget sources Add -Name $sourceName -Source $source -UserName $username -Password $token | |
# register the github package registry as a powershell repository | |
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList $username, (ConvertTo-SecureString -AsPlainText $token -Force) | |
Register-PSRepository -Name $sourceName -SourceLocation $source -PublishLocation $source -Credential $creds | |
<# -- | |
Publish PowerShell module | |
-- #> | |
$module = '<module-name>' | |
$version = '<module-version>' | |
$apiKey = 'n/a' # keep this as n/a! | |
Publish-Module -Name $module -Repository $sourceName -RequiredVersion $version -Credential $creds -Force -NuGetApiKey $apiKey |
From what I remember, the source index.json was a list of all repos, and NuGet was clever enough to work out where to push to based on that and the module's name - so long as your repo/module had the same name.
ok, so module name must match.
unfortunately I couldn't make your sample work
first I got packaging errors and after updating the powershellget module I get an authentication error
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As far as i know, github packages will put packages within their respective repositories
How does it know the repository, when the source location only contains the username?
Is the "$module / <module-name>" used for this?