Compile readme examples in CI

This commit is contained in:
ChillerDragon 2024-06-24 12:26:43 +08:00
parent a0020d8eef
commit 0e55e09207
3 changed files with 33 additions and 0 deletions

View file

@ -20,6 +20,19 @@ jobs:
- name: Build
run: go build -v ./...
build-readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Build go snippets in readme
run: ./scripts/compile_readme_snippets.sh
test:
runs-on: ubuntu-latest
steps:

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
tmp/
teeworlds_client
teeworlds
go-teeworlds-protocol

View file

@ -0,0 +1,18 @@
#!/bin/bash
mkdir -p tmp
awk '/^```go$/ {p=1}; p; /^```$/ {p=0;print"--- --- ---"}' README.md |
grep -vE '^```(go)?$' |
csplit \
-z -s -\
'/--- --- ---/' \
'{*}' \
--suppress-matched \
-f tmp/readme_snippet_ -b '%02d.go'
for snippet in ./tmp/readme_snippet_*.go
do
echo "building $snippet ..."
go build -v "$snippet" || exit 1
done