mach-composer-cli
mach-composer-cli copied to clipboard
mach-composer fmt
Is your proposal related to a problem?
We have several MACH configs in different repos, sometimes I want to compare versions or variable settings. I've found comparing them is easier if everything in the yml is sorted consistently
Describe the solution you'd like
Add mach-composer fmt to format a MACH config yaml file in a strict-defined order:
- site component variables and secrets sorted alphabetically
- component version section sorted alphabetically based on component name
- (Nice to have): sort every other section alphabetically, f.e. mach-plugin section on name as well
Describe alternatives you've considered
Precommit hook yaml sorting kinda works; https://github.com/leehambley/pre-commit-sort-yaml-keys
Perhaps interesting: https://github.com/editorconfig/editorconfig-core-go/tree/master
Based on Frasers project:
- yq -i '.mach_composer.plugins |= sort_keys(..)' {{ .target }}-config-{{ .environment }}.yaml
- yq -i '.global.terraform_config.providers |= sort_keys(..)' {{ .target }}-config-{{ .environment }}.yaml
- yq -i '.sites.[].components |= sort_by(.name)' {{ .target }}-config-{{ .environment }}.yaml
- yq -i '.sites.[].components.[].variables |= sort_keys(..)' {{ .target }}-config-{{ .environment }}.yaml
- yq -i '.sites.[].components.[].secrets |= sort_keys(..)' {{ .target }}-config-{{ .environment }}.yaml
- yq -i 'del(.. | select(. == null))' {{ .target }}-config-{{ .environment }}.yaml