mach-composer-cli icon indicating copy to clipboard operation
mach-composer-cli copied to clipboard

mach-composer fmt

Open davidweterings opened this issue 1 year ago • 2 comments

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

davidweterings avatar Jun 13 '23 09:06 davidweterings

Perhaps interesting: https://github.com/editorconfig/editorconfig-core-go/tree/master

mvantellingen avatar Aug 17 '23 07:08 mvantellingen

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

demeyerthom avatar Sep 28 '23 07:09 demeyerthom