-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Publish-PSResource: Pack and Push Feature #1682
Publish-PSResource: Pack and Push Feature #1682
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good, just made some small suggestions here and there.
src/code/PSResourceHelper.cs
Outdated
} | ||
finally | ||
{ | ||
if(_callerCmdlet == CallerCmdlet.CompressPSResource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we always want to delete outputDir
when we're done with it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CompressPSResource path deletes it here. But the PublishPSResource path still needs it for push to preserve the previous functionality. The PushResource method finally block handles that.
src/code/PSResourceHelper.cs
Outdated
{ | ||
if(_isNupkgPathSpecified) | ||
{ | ||
outputNupkgDir = pathToNupkgToPublish; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also consider having ouputNupkgDir
as a parameter that's passed in to PushResource()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passing outputNupkgDir makes it difficult to maintain old PublishResource Behavior. All the outputNupkgDir logic needs to be done in Publish and not in helper and that means in Compress as well.
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
Closing and re-opening to re-trigger CI |
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
Fixed a test that was strangely passing on local machine but failing on git. The problem was with
|
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
@@ -567,6 +567,8 @@ Describe "Test Publish-PSResource" -tags 'CI' { | |||
|
|||
$expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$scriptName.$scriptVersion.nupkg" | |||
(Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath | |||
|
|||
Remove-Item -Path $scriptPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be moved into the "After All" or "After Each" (whichever is appropriate), just to isolate the test functionality itself and have clean up done outside of test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't delete the test.ps1 file it creates. It only happen for this test.
Maybe it can be like the first test where it removes it in the test?
It "Publish module with required module not installed on the local machine using -SkipModuleManifestValidate" {
# Skip the module manifest validation test, which fails from the missing manifest required module.
$testModulePath = Join-Path -Path $TestDrive -ChildPath ModuleWithMissingRequiredModule
Publish-PSResource -Path $testModulePath -Repository $testRepository2 -Confirm:$false -SkipDependenciesCheck -SkipModuleManifestValidate
$expectedPath = Join-Path -Path $script:repositoryPath2 -ChildPath 'ModuleWithMissingRequiredModule.1.0.0.nupkg'
$publishedModuleFound = Test-Path -Path $expectedPath
$publishedModuleFound | Should -BeTrue
if ($publishedModuleFound) {
Remove-Item $expectedPath -Force -ErrorAction SilentlyContinue
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry I was just looking at the line kind of out of context. Really the entire line should be removed because $scriptPath
will be deleted during clean up in the "After Each" block already:
$pkgsToDelete = Join-Path -Path "$script:repositoryPath" -ChildPath "*" |
src/code/PublishHelper.cs
Outdated
|
||
private bool PackNupkg(string outputDir, string outputNupkgDir, string nuspecFile, out ErrorRecord error) | ||
{ | ||
_cmdlet.WriteDebug($"In {_callerCmdlet}::PackNupkg()"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These debug messages should specify "PublishHelper" instead of "_callerCmdlet" to stay consistent with how we're using the debug/verbose messages elsewhere in the repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. Should I also change the errors as well like...
_cmdlet.WriteError(new ErrorRecord(
new ArgumentException($"The resource repository '{Repository}' is not a registered. Please run 'Register-PSResourceRepository' in order to publish to this repository."),
"RepositoryNotFound",
ErrorCategory.ObjectNotFound,
this._cmdlet));
return;
should this._cmdlet be instead this? that refers to the PublishHelper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just leave it as this
without the .cmdlet
(eg:
PSResourceGet/src/code/FindHelper.cs
Line 110 in e79f6a2
_cmdletPassedIn.WriteError(new ErrorRecord( |
_cmdlet
to _cmdletPassedIn
? Staying consistent with the naming convention just helps us in the future if there's changes we need to make to the entire code base. It's easier to search and replace one term instead of looking up the different permutations
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
225603b
to
2bebc4f
Compare
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com>
Changed debug messages in PublishHelper
changed this._cmdlet -> _cmdletPassedIn
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
d76c50b
to
a537e23
Compare
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run PowerShell.PSResourceGet |
Azure Pipelines successfully started running 1 pipeline(s). |
PR Summary
Fixes: #1635
Decomposed Publish-PSResource to Pack and Push model with an addition of Compress-PSResource command.
Compress-PSResource requires a path to a PS module/script and a destination path to save the resulting nupkg.
Added -Nupkg parameter to Publish-PSResource that pushes the .nupkg file to a specified repository.
Publish-PSResource retains old functionality
PR Context
This change is to meet an SFI2 requirement to ensure signed packages. This PR enables publishing signed packages through Publish-PSResource by first packing (Compress-PSResource) then signing (User's Choice) then pushing(Publish-PSResource -Nupkg .
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.