fix: support mixed hook formats in UnmarshalYAML#7618
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the HooksConfig YAML unmarshalling logic in cli/azd/pkg/ext to allow hooks: blocks in azure.yaml to mix single-hook (map) and multi-hook (list) formats within the same block, fixing a parsing failure when both formats are present.
Changes:
- Reworked
HooksConfig.UnmarshalYAMLto unmarshal intoyaml.Nodeper hook key and decode based on node kind (mapping vs sequence). - Added unit tests covering mixed hook formats, empty hook blocks, and invalid hook entries.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cli/azd/pkg/ext/hooks_config.go | Switches unmarshalling to per-entry yaml.Node kind inspection to support mixed formats. |
| cli/azd/pkg/ext/hooks_config_test.go | Adds regression coverage for mixed formats and a few additional edge cases. |
jongio
left a comment
There was a problem hiding this comment.
Clean fix. The yaml.Node approach is the right call here - per-key type inspection is exactly how yaml.v3 is designed to handle polymorphic structures. Implementation is correct, tests cover the reported scenario well.
Two optional nits below.
2a77265 to
20a9441
Compare
jongio
left a comment
There was a problem hiding this comment.
Looks good. The per-key type inspection handles mixed formats correctly and test coverage is solid.
Replace the two-pass unmarshaling approach in HooksConfig.UnmarshalYAML with per-key type inspection. Each hook entry is now independently parsed as either a single HookConfig (map) or a list of HookConfigs (sequence), allowing mixed formats within the same hooks: block. Fixes Azure#7615 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
20a9441 to
18b860d
Compare
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
jongio
left a comment
There was a problem hiding this comment.
The map[string]any type-switch approach is the right call here - the old-style UnmarshalYAML callback can't target yaml.Node directly, so this is the cleanest way to handle per-key polymorphism. Round-trip tests confirm marshal/unmarshal stability, edge cases (null, empty, scalar error) are covered, and backward compat with legacy single-hook format is preserved.
All previous feedback addressed. Ship it.
What Changed
Azure.yaml
hooks:blocks can now mix single-hook (map) and multi-hook (list) formats freely. Previously, if one hook used map format (e.g., withwindows:/posix:platform overrides) and another used list format (multiple hooks), parsing would fail withcannot unmarshal !!map into []*ext.HookConfig.Before: Users had to convert ALL hooks to list format as a workaround.
After: Both formats coexist naturally —
predeployas a map with platform overrides alongsidepreprovisionas a list of multiple hooks.How It Works
Replaced the two-pass unmarshaling in
HooksConfig.UnmarshalYAMLwith per-key type inspection usingyaml.Node. Each hook entry is independently examined: mapping nodes unmarshal as a single*HookConfig(wrapped into a 1-element slice), sequence nodes unmarshal as[]*HookConfig. This handles any combination without special-casing.Issue References
Fixes #7615
Relates to #7435