Skip to content

Commit

Permalink
go fmt readme snippets and shellcheck check script
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Jun 24, 2024
1 parent 0e55e09 commit f4d10c2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/shell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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
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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 9 additions & 5 deletions scripts/compile_readme_snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f4d10c2

Please sign in to comment.