Skip to content

Commit

Permalink
Fix issues in mustache script
Browse files Browse the repository at this point in the history
  • Loading branch information
JimMadge committed Jan 8, 2025
1 parent 8cfc0b6 commit 92c0cad
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions .github/scripts/expand_mustache.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#!/usr/bin/env bash
echo '{"array": ["dummy"], "variable": "dummy"}' > .mustache_config.json
for yamlfile in $(find . -name "*.yml" -o -name "*.yaml"); do

while read -r -d '' yamlfile; do

filename=$(basename -- "$yamlfile")
extension="${filename##*.}"
filename="${filename%.*}"
test_config=".github/resources/$filename.config.json"

if [ -e "$test_config" ]; then
mustache $test_config $yamlfile > $yamlfile
mustache "$test_config" "$yamlfile" | sponge "$yamlfile"
else
sed "s|{{\([/#]\)[^}]*}}|{{\1array}}|g" $yamlfile > expanded.tmp # replace mustache arrays
sed -i "s|{{[^#/].\{1,\}}}|{{variable}}|g" expanded.tmp # replace mustache variables
mustache .mustache_config.json expanded.tmp > $yamlfile # perform mustache expansion overwriting original file
# replace mustache arrays
sed "s|{{\([/#]\)[^}]*}}|{{\1array}}|g" "$yamlfile" > expanded.tmp
# replace mustache variables
sed -i "s|{{[^#/].\{1,\}}}|{{variable}}|g" expanded.tmp
# perform mustache expansion overwriting original file
mustache .mustache_config.json expanded.tmp > "$yamlfile"
fi

done
done < <(find . -name "*.yml" -o -name "*.yaml")

rm expanded.tmp

0 comments on commit 92c0cad

Please sign in to comment.