Skip to content

feat: add more tests #4

feat: add more tests

feat: add more tests #4

Workflow file for this run

name: CI
on:
pull_request:
paths:
- '**.go'
- go.mod
- go.sum
- '.github/workflows/**'
push:
branches:
- main
tags:
- '*'
jobs:
lint-test:
name: Lint, Build and Test
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Go version
run: go version
- name: Verify formatting (gofmt -s)
run: |
fmt_out=$(gofmt -s -l .)
if [ -n "$fmt_out" ]; then
echo "The following files are not gofmt'ed:" >&2
echo "$fmt_out" >&2
exit 1
fi
- name: Vet
run: go vet ./...
env:
CGO_ENABLED: 0
- name: Build (ensure main builds)
run: go build -trimpath -v -o /tmp/app ./src
env:
CGO_ENABLED: 0
- name: Run tests with coverage
run: |
go test -coverprofile=coverage.out -covermode=atomic ./...
coverage_report=$(go tool cover -func=coverage.out)
echo "$coverage_report"
total_coverage=$(echo "$coverage_report" | awk '/^total:/ {print substr($3, 1, length($3)-1)}')
python - "$total_coverage" <<'PY'
import sys
coverage = float(sys.argv[1])
minimum = 60.0
if coverage < minimum:
print(f"Coverage {coverage:.2f}% is below required {minimum:.2f}%.", file=sys.stderr)
sys.exit(1)
PY
env:
CGO_ENABLED: 0
- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.out