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

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