diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..31755d9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,33 @@ +name: Build and Test +on: [push, pull_request] +permissions: + contents: read + +jobs: + build: + name: Go CI + runs-on: ubuntu-latest + strategy: + matrix: + go: ["1.22", "1.23"] + steps: + - name: Check out source + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2 + - name: Set up Go + uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 #v5.3.0 + with: + go-version: ${{ matrix.go }} + - name: Use lint cache + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2.0 + with: + path: | + ~/.cache/golangci-lint + key: go-lint-${{ matrix.go }}-${{ hashFiles('./go.sum') }} + restore-keys: go-lint-${{ matrix.go }} + - name: Install Linters + run: "go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2" + - name: Build + run: go build ./... + - name: Test + run: | + sh ./run_tests.sh diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..9961bec --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,29 @@ +version: "2" +run: + timeout: 10m +linters: + default: none + enable: + - asciicheck + - bidichk + - durationcheck + - copyloopvar + - govet + - grouper + - ineffassign + - makezero + - nosprintfhostport + - reassign + - rowserrcheck + - sqlclosecheck + - staticcheck + - tparallel + - unconvert + settings: + staticcheck: + checks: + - S1* +formatters: + enable: + - gofmt + - goimports diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 0000000..889b134 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -ex + +GV=$(go version | sed "s/^.*go\([0-9.]*\).*/\1/") +echo "Go version: $GV" + +# Run `go mod tidy` and fail if the git status of go.mod and/or +# go.sum changes. Only do this for the latest Go version. +if [[ "$GV" =~ ^1.23 ]]; then + MOD_STATUS=$(git status --porcelain go.mod go.sum) + go mod tidy + UPDATED_MOD_STATUS=$(git status --porcelain go.mod go.sum) + if [ "$UPDATED_MOD_STATUS" != "$MOD_STATUS" ]; then + echo "running 'go mod tidy' modified go.mod and/or go.sum" + git diff --unified=0 go.mod go.sum + exit 1 + fi +fi + +# run tests +env GORACE="halt_on_error=1" go test -race -short ./... + +# check linters +golangci-lint -c ./.golangci.yml run