Skip porter-state for modifies: false custom actions#3582
Draft
kichristensen wants to merge 4 commits intogetporter:mainfrom
Draft
Skip porter-state for modifies: false custom actions#3582kichristensen wants to merge 4 commits intogetporter:mainfrom
modifies: false custom actions#3582kichristensen wants to merge 4 commits intogetporter:mainfrom
Conversation
modifies: false custom actions
When a custom action has modifies: false, Finalize() now skips packStateBag(), preventing porter-state from being written back to the installation. Run records and user-defined outputs are still persisted as expected. Fixes getporter#3579 Signed-off-by: Kim Christensen <kimworking@gmail.com>
Add test case for stateful, modifies:false action with an applyTo output to document that recording runs/outputs is correct behavior per Porter docs. State isolation is enforced in Finalize(), not ShouldRecord(). Signed-off-by: Kim Christensen <kimworking@gmail.com>
Add test bundle and TestInvoke_ModifiesFalse_DoesNotPersistState to assert that invoking a modifies:false action leaves porter-state unchanged, while still recording the run and saving user outputs. Signed-off-by: Kim Christensen <kimworking@gmail.com>
The previous fix skipped packStateBag() inside the invocation image, but the CNAB driver requires all outputs with no default to be present — so it failed with "required output porter-state is missing and has no default". Move the guard to SaveOperationResult on the host side: when the action has modifies:false, skip persisting internal outputs (porter-state) to the installation's output record while still allowing packStateBag() to write the file for the driver. Signed-off-by: Kim Christensen <kimworking@gmail.com>
f537da9 to
06b0b84
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change
Custom actions declared with
modifies: false(e.g.dry-run) would silently overwrite the installation'sporter-statewhenever they produced outputs. This happened becauseFinalize()calledpackStateBag()unconditionally, regardless of the action'smodifiesflag.This change guards
packStateBag()inFinalize(): if the action is found in the bundle's custom actions map and hasModifies: false, state packing is skipped. For built-in actions (install,upgrade,uninstall) andmodifies: trueactions the existing behavior is preserved.Run records and user-defined outputs for
modifies: falseactions continue to be persisted — this is correct per the Porter docs, which state that outputs are recorded when they explicitly apply to an action viaapplyTo.What issue does it fix
Closes #3579
Notes for the reviewer
ShouldRecord()— itshasOutputOR-term is intentional. The Porter docs confirm that outputs are recorded when they explicitly apply to an action viaapplyTo. State isolation is a separate concern enforced inFinalize().ShouldRecord():if action, err := bundle.GetAction(action); err == nil— an error means a built-in action, which defaults to the safe path (pack state).Checklist