fix(update-versions.sh): handle markdown/tf block nesting when updating version (#356)
This commit is contained in:
committed by
GitHub
parent
b345e62ac1
commit
bf697e1fa4
@@ -21,14 +21,39 @@ for dir in "${changed_dirs[@]}"; do
|
|||||||
if [[ -f "$dir/README.md" ]]; then
|
if [[ -f "$dir/README.md" ]]; then
|
||||||
file="$dir/README.md"
|
file="$dir/README.md"
|
||||||
tmpfile=$(mktemp /tmp/tempfile.XXXXXX)
|
tmpfile=$(mktemp /tmp/tempfile.XXXXXX)
|
||||||
awk -v tag="$LATEST_TAG" '{
|
awk -v tag="$LATEST_TAG" '
|
||||||
if ($1 == "version" && $2 == "=") {
|
BEGIN { in_code_block = 0; in_nested_block = 0 }
|
||||||
sub(/"[^"]*"/, "\"" tag "\"")
|
{
|
||||||
print
|
# Detect the start and end of Markdown code blocks.
|
||||||
} else {
|
if ($0 ~ /^```/) {
|
||||||
|
in_code_block = !in_code_block
|
||||||
|
# Reset nested block tracking when exiting a code block.
|
||||||
|
if (!in_code_block) {
|
||||||
|
in_nested_block = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Handle nested blocks within a code block.
|
||||||
|
if (in_code_block) {
|
||||||
|
# Detect the start of a nested block (skipping "module" blocks).
|
||||||
|
if ($0 ~ /{/ && !($1 == "module" || $1 ~ /^[a-zA-Z0-9_]+$/)) {
|
||||||
|
in_nested_block++
|
||||||
|
}
|
||||||
|
|
||||||
|
# Detect the end of a nested block.
|
||||||
|
if ($0 ~ /}/ && in_nested_block > 0) {
|
||||||
|
in_nested_block--
|
||||||
|
}
|
||||||
|
|
||||||
|
# Update "version" only if not in a nested block.
|
||||||
|
if (!in_nested_block && $1 == "version" && $2 == "=") {
|
||||||
|
sub(/"[^"]*"/, "\"" tag "\"")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
print
|
print
|
||||||
}
|
}
|
||||||
}' "$file" > "$tmpfile" && mv "$tmpfile" "$file"
|
' "$file" > "$tmpfile" && mv "$tmpfile" "$file"
|
||||||
|
|
||||||
# Check if the README.md file has changed
|
# Check if the README.md file has changed
|
||||||
if ! git diff --quiet -- "$dir/README.md"; then
|
if ! git diff --quiet -- "$dir/README.md"; then
|
||||||
|
|||||||
Reference in New Issue
Block a user