From 098341aad5ada93e996ca3b2f19941a8b15a297c Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Mon, 24 Jun 2024 12:35:09 +0800 Subject: [PATCH] go fmt readme snippets and shellcheck check script --- .github/workflows/shell.yml | 27 +++++++++++++++++++++++++++ README.md | 2 +- scripts/compile_readme_snippets.sh | 14 +++++++++----- 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/shell.yml diff --git a/.github/workflows/shell.yml b/.github/workflows/shell.yml new file mode 100644 index 0000000..3ba74e2 --- /dev/null +++ b/.github/workflows/shell.yml @@ -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 + diff --git a/README.md b/README.md index 07c2757..adc1d16 100644 --- a/README.md +++ b/README.md @@ -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) { diff --git a/scripts/compile_readme_snippets.sh b/scripts/compile_readme_snippets.sh index 02f0e52..3a4046d 100755 --- a/scripts/compile_readme_snippets.sh +++ b/scripts/compile_readme_snippets.sh @@ -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