diff --git a/.yamlfmt b/.yamlfmt new file mode 100644 index 0000000..7f2250d --- /dev/null +++ b/.yamlfmt @@ -0,0 +1,4 @@ +formatter: + type: basic + indent: 2 + retain_line_breaks: true diff --git a/.yamlfmt.manifests b/.yamlfmt.manifests new file mode 100644 index 0000000..0c3b230 --- /dev/null +++ b/.yamlfmt.manifests @@ -0,0 +1,4 @@ +formatter: + type: basic + indent: 4 + retain_line_breaks: true diff --git a/justfile b/justfile index 740083a..c948742 100644 --- a/justfile +++ b/justfile @@ -6,6 +6,9 @@ TEMPLATES_REPO := "git@github.com:ethereum-optimism/devnet-templates.git" TEMPLATES_BRANCH := "main" +# Devnet folders whose YAML files are formatted (indent config lives in .yamlfmt) +YAML_DIRS := "dev stg prod" + # Default: show help default: @just --list @@ -106,3 +109,28 @@ create-devnet net_type name preset: echo "Next steps:" echo " 1. Edit $TARGET_DIR/manifest.yaml to configure your devnet" echo " 2. Edit $TARGET_DIR/inventory.yaml to configure nodes and services" + +# Fix YAML indentation/formatting in place across dev/stg/prod devnet folders. +# manifest.yaml uses 4-space, all other YAML uses 2-space, matching netchef output. +fmt-yaml: + #!/usr/bin/env bash + set -euo pipefail + dirs=() + for d in {{YAML_DIRS}}; do [ -d "$d" ] && dirs+=("$d"); done + [ ${#dirs[@]} -eq 0 ] && exit 0 + manifests=(); while IFS= read -r f; do manifests+=("$f"); done < <(find "${dirs[@]}" -name manifest.yaml) + others=(); while IFS= read -r f; do others+=("$f"); done < <(find "${dirs[@]}" -name '*.yaml' ! -name manifest.yaml) + if [ ${#manifests[@]} -gt 0 ]; then mise exec -- yamlfmt -conf .yamlfmt.manifests "${manifests[@]}"; fi + if [ ${#others[@]} -gt 0 ]; then mise exec -- yamlfmt "${others[@]}"; fi + +# Check YAML formatting without writing changes (fails if any file needs formatting) +lint-yaml: + #!/usr/bin/env bash + set -euo pipefail + dirs=() + for d in {{YAML_DIRS}}; do [ -d "$d" ] && dirs+=("$d"); done + [ ${#dirs[@]} -eq 0 ] && exit 0 + manifests=(); while IFS= read -r f; do manifests+=("$f"); done < <(find "${dirs[@]}" -name manifest.yaml) + others=(); while IFS= read -r f; do others+=("$f"); done < <(find "${dirs[@]}" -name '*.yaml' ! -name manifest.yaml) + if [ ${#manifests[@]} -gt 0 ]; then mise exec -- yamlfmt -lint -conf .yamlfmt.manifests "${manifests[@]}"; fi + if [ ${#others[@]} -gt 0 ]; then mise exec -- yamlfmt -lint "${others[@]}"; fi diff --git a/mise.toml b/mise.toml index 4cea2a5..a538dd7 100644 --- a/mise.toml +++ b/mise.toml @@ -1,4 +1,5 @@ [tools] mdbook = "v0.4.43" uv = "0.9.5" -"pipx:cookiecutter" = "2.6.0" \ No newline at end of file +"pipx:cookiecutter" = "2.6.0" +yamlfmt = "0.21.0"