mach-composer / mach-composer-cli

MACH composer is an orchestration tool for modern MACH ecosystems, powered by Terraform infrastructure-as-code underneath.
https://docs.machcomposer.io
MIT License
48 stars 10 forks source link

mach-composer fmt #236

Open davidweterings opened 1 year ago

davidweterings commented 1 year ago

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:

Describe alternatives you've considered

Precommit hook yaml sorting kinda works; https://github.com/leehambley/pre-commit-sort-yaml-keys

mvantellingen commented 1 year ago

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

demeyerthom commented 11 months ago

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