You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DateKeys/scripts/check.sh

59 lines
1.6 KiB

#!/usr/bin/env bash
# Local gate: the same checks as .gitea/workflows/ci.yml, for any machine and
# for forges without runners. Run it before every push.
#
# scripts/check.sh # format, modules, vet, race tests, coverage,
# # govulncheck, vectors and fixtures
# scripts/check.sh 20s # additionally fuzz every parser for 20 s
set -euo pipefail
cd "$(dirname "$0")/.."
fuzz="${1:-}"
echo "== gofmt"
bad=$(gofmt -l .)
if [ -n "$bad" ]; then
echo "not formatted:"; echo "$bad"; exit 1
fi
echo "== go mod verify"
go mod verify
echo "== go mod tidy leaves go.mod and go.sum unchanged"
tmp=$(mktemp -d)
cp go.mod go.sum "$tmp"/
go mod tidy
if ! cmp -s go.mod "$tmp/go.mod" || ! cmp -s go.sum "$tmp/go.sum"; then
cp "$tmp"/go.mod "$tmp"/go.sum .
rm -rf "$tmp"
echo "go mod tidy would change go.mod or go.sum"; exit 1
fi
rm -rf "$tmp"
echo "== go vet"
go vet ./...
echo "== go test -race"
go test -race -count=1 ./...
echo "== coverage: at least 90 % in codec, capsule, accesskey, datekey and agewrap"
for pkg in codec capsule accesskey datekey agewrap; do
pct=$(go test -count=1 -cover "./$pkg" | sed -n 's/.*coverage: \([0-9.]*\)% of statements.*/\1/p')
echo "$pkg: $pct%"
awk -v p="$pct" 'BEGIN { exit !(p >= 90) }'
done
echo "== govulncheck"
go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 ./...
echo "== vectors reproduce and fixtures are frozen"
go run ./internal/testkit/genfixtures -out testdata
git diff --exit-code -- testdata
if [ -n "$fuzz" ]; then
echo "== fuzz every parser for $fuzz"
./scripts/fuzz.sh "$fuzz"
fi
echo "all checks passed"

Powered by TurnKey Linux.