Add CI workflow for linting, tests, and coverage #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.23" | |
| - uses: golangci/golangci-lint-action@v6 | |
| with: | |
| version: latest | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.23" | |
| - name: Run library tests with coverage | |
| run: go test -race -coverprofile=coverage.out -covermode=atomic ./... | |
| - name: Report coverage | |
| run: | | |
| go tool cover -func=coverage.out | |
| COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | tr -d '%') | |
| echo "Total coverage: ${COVERAGE}%" | |
| if [ "$(echo "$COVERAGE < 40" | bc)" -eq 1 ]; then | |
| echo "::error::Coverage ${COVERAGE}% is below 40% threshold" | |
| exit 1 | |
| fi |