go-teeworlds-protocol/scripts/compile_readme_snippets.sh

23 lines
512 B
Bash
Raw Normal View History

2024-06-24 04:26:43 +00:00
#!/bin/bash
mkdir -p tmp
awk '/^```go$/ {p=1}; p; /^```$/ {p=0;print"--- --- ---"}' README.md |
grep -vE '^```(go)?$' |
csplit \
-z -s - '/--- --- ---/' \
2024-06-24 04:26:43 +00:00
'{*}' \
--suppress-matched \
-f tmp/readme_snippet_ -b '%02d.go'
for snippet in ./tmp/readme_snippet_*.go; do
2024-06-24 04:26:43 +00:00
echo "building $snippet ..."
go build -v -o tmp/tmp "$snippet" || exit 1
2024-06-24 04:26:43 +00:00
done
for snippet in ./tmp/readme_snippet_*.go; do
echo "checking format $snippet ..."
if ! diff -u <(echo -n) <(gofmt -d "$snippet"); then
exit 1
fi
done