Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mach-composer fmt #236

Open
davidweterings opened this issue Jun 13, 2023 · 2 comments
Open

mach-composer fmt #236

davidweterings opened this issue Jun 13, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@davidweterings
Copy link
Contributor

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

@demeyerthom demeyerthom added the enhancement New feature or request label Aug 7, 2023
@mvantellingen
Copy link
Contributor

@demeyerthom
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants