Skip to content
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

(#1092) Ensure chocolateyBeforeModify.ps1 is run for dependencies #3051

Merged
merged 3 commits into from
Mar 14, 2023

Conversation

vexx32
Copy link
Member

@vexx32 vexx32 commented Feb 28, 2023

Description Of Changes

  • Remove manual backup of package files and run of beforeModify script for the target package
  • Inject backup and beforeModify actions into the IPackageManager's Installing and Uninstalling actions to ensure that these happen for every package being changed, even for dependencies which are changing during a choco install operation.

Motivation and Context

This improves the overall soundness of our package operations, and fixes an issue where updating Chocolatey licensed packages can trip over the chocolatey-agent package if it ends up being updated during processing of dependencies (for instance, by updating one of its dependencies outside of its currently permitted version range, while a newer agent package is available that will work with the newer dependency version.

Testing

  1. Run the unit tests
  2. Test out the failing test case with chocolatey-agent upgrade from choco 1.x (this PR build) and current stable agent, licensed extension, GUI, and gui extension to choco v2.x alpha and alpha releases of licensed components and GUI by upgrading the chocolateygui.extension package. With this change, the upgrade should correctly run the chocolatey-agent beforeModify script and succeed smoothly.

There are a couple unit tests I'd still like to add, but the currently-added ones cover the main priority here at the moment.

Operating Systems Testing

Win10, Win11

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v2 compatibility checked?

Related Issue

Fixes #1092

@vexx32 vexx32 changed the base branch from develop to support/1.x February 28, 2023 19:32
@vexx32 vexx32 force-pushed the 1092-beforemodify branch 2 times, most recently from 9abae8a to 4c097f7 Compare March 1, 2023 22:02
This addition is necessary, as many occasions may arise where installing
one package involves updating an already-installed dependency. In these
cases we should still be running a beforeModify script if it's present,
and this facilitates that.
@vexx32 vexx32 force-pushed the 1092-beforemodify branch 3 times, most recently from 663211a to dde8edf Compare March 10, 2023 21:59
@vexx32 vexx32 marked this pull request as ready for review March 10, 2023 22:06
@vexx32 vexx32 requested review from gep13 and corbob March 10, 2023 22:06
@vexx32 vexx32 force-pushed the 1092-beforemodify branch from dde8edf to 4531342 Compare March 10, 2023 22:18
Copy link
Member

@corbob corbob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few questions, nothing that necessarily requires changes though.

@gep13
Copy link
Member

gep13 commented Mar 13, 2023

@vexx32 for the tests that you are going to add to this, do we need to add any additional tests for hook packages to ensure that they continue to work as expected, or do the current tests cover the changes that you are making in this PR?

@vexx32
Copy link
Member Author

vexx32 commented Mar 13, 2023

do we need to add any additional tests for hook packages to ensure that they continue to work as expected, or do the current tests cover the changes that you are making in this PR?

I'll double check the existing tests for that, but I suspect we'll want to add an extra test for that to make sure they work as expected.

EDIT: Yeah, I think we're mostly good, but I will add the hooks package into the test and add some checks for the pre-beforeModify hook to make sure it's running each time.

vexx32 added 2 commits March 13, 2023 12:08
Previously we only ran backups and beforeModify scripts on the target
package(s) and not their dependencies.

This change should ensure we are _always_ running backups on any
existing packages from a NuGet source before we try to modify them in
any way. Additionally, this should ensure we can run the beforeModify
scripts for ALL dependencies of the target package(s).
This test added ensures that when we are upgrading a package, both its
own and any dependencies' beforeModify are run so that we can properly
update dependencies which might need to shut down a long-running service
before being upgraded.
@vexx32 vexx32 force-pushed the 1092-beforemodify branch from 4531342 to 49cc8d7 Compare March 13, 2023 16:09
@vexx32
Copy link
Member Author

vexx32 commented Mar 13, 2023

@gep13 Alright, I think the tests I've added are up to scratch now, we should be good to review this as-is. 🙂

Copy link
Member

@gep13 gep13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@gep13
Copy link
Member

gep13 commented Mar 14, 2023

The failing Ubuntu build here is an issue with NuGet Restore, and nothing to do with the changes in this PR.

@gep13 gep13 merged commit b1c877b into chocolatey:support/1.x Mar 14, 2023
@gep13
Copy link
Member

gep13 commented Mar 14, 2023

@vexx32 thank you very much for getting this done!

@vexx32 vexx32 deleted the 1092-beforemodify branch March 14, 2023 14:56
vexx32 added a commit to vexx32/choco that referenced this pull request Oct 7, 2024
This migration path hasnt been supported or used since pre-1.0 versions
of Chocolatey and is dead code.

Removing this now to simplify the install process somewhat and get the
old code out of the way as it's not used at all.
vexx32 added a commit to vexx32/choco that referenced this pull request Oct 15, 2024
Rewrite of the Get-ChocolateyPath into C# cmdlet, and associated
changes to helper methods.
vexx32 added a commit to vexx32/choco that referenced this pull request Oct 15, 2024
Rewrite of the Get-ChocolateyPath into C# cmdlet, and associated
changes to helper methods.
vexx32 added a commit to vexx32/choco that referenced this pull request Oct 15, 2024
Rewrite of the Get-ChocolateyPath into C# cmdlet, and associated
changes to helper methods.
vexx32 added a commit to vexx32/choco that referenced this pull request Oct 15, 2024
To ensure behaviour works as expected
vexx32 added a commit to vexx32/choco that referenced this pull request Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chocolateyBeforeModify.ps1 does not get called for dependent packages
3 participants