Skip to content

Commit

Permalink
(#32) Publish Chocolatey Package to nuget feed
Browse files Browse the repository at this point in the history
  • Loading branch information
corbob committed Mar 7, 2024
1 parent 5e0fe74 commit bde86c1
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions Chocolatey-AU.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ param(
$PublishUrl = $env:POWERSHELLPUSH_SOURCE,


[string]
$ChocolateyNugetApiKey = $env:CHOCOOPSPUSH_API_KEY,


[string]
$ChocolateyPublishUrl = $env:CHOCOOPSPUSH_SOURCE,


[string]
$ModuleName = 'Chocolatey-AU',

Expand Down Expand Up @@ -240,8 +248,9 @@ task CreateChocolateyPackage -After Sign {
$chocolateyPackage.Save($nuspecPath)
Copy-Item $script:ModuleOutputDir $ChocolateyPackageDir/tools -Recurse -Force
choco pack $nuspecPath --outputdirectory $OutputDirectory --version $script:BuildVersion
$script:ChocolateyPackagePath = Get-ChildItem $OutputDirectory -Filter *.nupkg | Select-Object -ExpandProperty FullName

if ($LASTEXITCODE -ne 0) {
if (-not (Test-Path $script:ChocolateyPackagePath)) {
throw 'Chocolatey Package failed to pack.'
}
}
Expand Down Expand Up @@ -336,8 +345,8 @@ task Publish -If ($script:ReleaseBuild -or $PublishUrl) Build, {
throw 'Build the module with `Invoke-Build` or `build.ps1` before attempting to publish the module'
}

if (-not $NugetApiKey) {
throw 'Please pass the API key for publishing to the `-NugetApiKey` parameter or set $env:NugetApiKey before publishing'
if (-not $NugetApiKey -or -not $ChocolateyNugetApiKey) {
throw 'Please pass the API key for publishing to both the `-NugetApiKey` and `-ChocolateyNugetApiKey` parameter or set $env:POWERSHELLPUSH_API_KEY and $env:CHOCOOPSPUSH_API_KEY before publishing'
}

$psdFile = Resolve-Path $script:ModuleOutputDir
Expand Down Expand Up @@ -366,6 +375,15 @@ task Publish -If ($script:ReleaseBuild -or $PublishUrl) Build, {
Publish-Module @publishParams
}

if ($ChocolateyPublishUrl) {
Write-Verbose "Publishing to '$ChocolateyPublishUrl'"
choco push $script:ChocolateyPackagePath --source $ChocolateyPublishUrl --key $ChocolateyNugetApiKey

if ($LASTEXITCODE -ne 0) {
throw "Chocolatey push to $ChocolateyPublishUrl failed."
}
}

if ($script:ReleaseBuild) {
Write-Verbose "Publishing to PSGallery"
$publishParams.NugetApiKey = $env:POWERSHELLGALLERY_API_KEY
Expand Down

0 comments on commit bde86c1

Please sign in to comment.