natescherer / publish-powershell-action

A GitHub Action to publish a PowerShell module or script to GitHub Packages, a NuGet repository, or the PowerShell Gallery.
MIT License
11 stars 4 forks source link

Handle same name registration in PSResourceRepository #24

Open cbdog94 opened 12 months ago

cbdog94 commented 12 months ago

It happened for self hosted runner sometimes, that "Nuget" already registered in PSResourceRepository when trying to publish.

I want to contribute following code and seems I don't have permission to push a new branch.

if ($null -ne (Get-PSResourceRepository -Name "NuGet" -ErrorAction SilentlyContinue)) {
    Write-Host "Unregistering existing NuGet repository..."
    Unregister-PSResourceRepository -Name "NuGet"
} 

Write-Host "Registering NuGet repository..."
Register-PSResourceRepository -Name "NuGet" -Uri $env:INPUT_NUGETURL -Trusted
natescherer commented 10 months ago

Thanks for reaching out! You can't directly add a branch to this project because that's not how workflows on GitHub generally happen. If you want to make a code contribution to someone else's project, that needs to be done via Pull Request. If you'd like to learn how, here's a good guide to get started: https://makeapullrequest.com/

However, I think the best thing to do here to account for all situations is to generate a random name at the start of the process and then unregister it at the end, rather than potentially breaking some other process on the runner that depends on the existing repo. I'll include a fix in the next version.

brandonmcclure commented 6 months ago

I have run into this error when I use this action multiple time in one workflow. The subsequent calls fail because the "nuget" repository is already registered. I used New-GUID to ensure we get a unique name each time the action is run.