File size: 783 Bytes
f61bac1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2026, The OpenROAD Authors
#
# Auto-format YAML files in-place using yamlfix.
set -euo pipefail
TOOL="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
GIT="$(realpath "$2")"
cd "${BUILD_WORKSPACE_DIRECTORY:-$PWD}"

is_blacklisted() {
    local target="$1"
    if [ -f "yamlfix.ignore" ]; then
        grep -qxF "$target" "yamlfix.ignore" 2>/dev/null && return 0
    fi
    return 1
}

OPTIONS=()
if [ -f "yamlfix.toml" ]; then
    OPTIONS+=("-c" "yamlfix.toml")
fi

FILES=()
while IFS= read -r -d '' file; do
    if ! is_blacklisted "$file"; then
        FILES+=("$file")
    fi
done < <("${GIT}" ls-files '*.yaml' '*.yml' -z)

if [ "${#FILES[@]}" -gt 0 ]; then
    "$TOOL" "${OPTIONS[@]}" "${FILES[@]}"
fi