name: Test # Every branch push, and no pull_request trigger: branches are pushed # directly, so each commit runs once. Tag pushes are left to release.yml. on: push: branches: ['**'] jobs: check: name: Lint, test and build runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: go.mod # setup-go@v5 installs the release named by go.mod's go line; the go # command then switches to its toolchain line. Fail if it did not. - name: Check the Go toolchain run: | want="$(sed -n 's/^toolchain //p' go.mod)" have="$(go env GOVERSION)" echo "go.mod toolchain: ${want:-none}; running: $have" [ "$have" = "$want" ] # The gofmt on PATH is setup-go's; the one under GOROOT belongs to the # toolchain the go command switched to. - name: gofmt run: | unformatted="$("$(go env GOROOT)/bin/gofmt" -l .)" if [ -n "$unformatted" ]; then echo "These files need gofmt:"; echo "$unformatted"; exit 1 fi - name: goimports run: | unformatted="$(go tool goimports -l .)" if [ -n "$unformatted" ]; then echo "These files need goimports:"; echo "$unformatted"; exit 1 fi # Prints the change and fails, without writing, if go.mod or go.sum # is not tidy. - name: go mod tidy run: go mod tidy -diff - name: go vet run: go vet ./... - name: staticcheck run: go tool staticcheck ./... # The limit is per package: a hung test fails with every goroutine's # stack instead of being killed by the runner. - name: Test (race detector) run: go test -race -timeout 5m ./... # The release build without publishing: runs the before hooks, # cross-compiles every shipped target and packs the archives, so a # config error or a missing archive file fails here, not on a tag. # Same pin as release.yml. - name: Release snapshot uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser version: '2.20.3' args: release --snapshot --clean