go fmt readme snippets and shellcheck check script

This commit is contained in:
ChillerDragon 2024-06-24 12:35:09 +08:00
parent 0e55e09207
commit 098341aad5
3 changed files with 37 additions and 6 deletions

27
.github/workflows/shell.yml vendored Normal file
View file

@ -0,0 +1,27 @@
name: Shell
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
bash:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare
run: |
sudo apt-get update -y
sudo apt-get install shellcheck
mkdir -p ~/.local/bin/
wget -O ~/.local/bin/shfmt https://github.com/mvdan/sh/releases/download/v3.8.0/shfmt_v3.8.0_linux_amd64
chmod +x ~/.local/bin/shfmt
- name: Shellcheck
run: find . -type f -name '*.sh' -print0 | xargs -0 shellcheck
- name: Shell format (shfmt)
run: find . -type f -name '*.sh' -print0 | xargs -0 shfmt -d

View file

@ -18,7 +18,7 @@ import (
func main() {
client := teeworlds7.Client{Name: "nameless tee"}
// Register your callback for incoming chat messages
// For a full list of all callbacks see: https://github.com/teeworlds-go/go-teeworlds-protocol/tree/master/teeworlds7/user_hooks.go
client.OnChat(func(msg *messages7.SvChat, defaultAction teeworlds7.DefaultAction) {

View file

@ -4,15 +4,19 @@ mkdir -p tmp
awk '/^```go$/ {p=1}; p; /^```$/ {p=0;print"--- --- ---"}' README.md |
grep -vE '^```(go)?$' |
csplit \
-z -s -\
'/--- --- ---/' \
-z -s - '/--- --- ---/' \
'{*}' \
--suppress-matched \
-f tmp/readme_snippet_ -b '%02d.go'
for snippet in ./tmp/readme_snippet_*.go
do
for snippet in ./tmp/readme_snippet_*.go; do
echo "building $snippet ..."
go build -v "$snippet" || exit 1
go build -v -o tmp/tmp "$snippet" || exit 1
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