Document record type dispatch pattern in README #6
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] | |
| permissions: | |
| contents: write | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| go-version: ['1.22', '1.23', '1.24', '1.25', '1.26'] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| - name: Build | |
| run: go build ./... | |
| - name: Test | |
| run: go test -v -race -count=1 ./... | |
| coverage: | |
| name: Coverage | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.26' | |
| - name: Test with coverage | |
| run: | | |
| go test -coverprofile=coverage.out -covermode=atomic ./... | |
| COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | tr -d '%') | |
| echo "COVERAGE=$COVERAGE" >> "$GITHUB_ENV" | |
| echo "Coverage: $COVERAGE%" | |
| - name: Generate coverage badge | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| run: | | |
| COV=${{ env.COVERAGE }} | |
| # Pick color based on coverage | |
| if (( $(echo "$COV >= 90" | bc -l) )); then | |
| COLOR="brightgreen" | |
| elif (( $(echo "$COV >= 80" | bc -l) )); then | |
| COLOR="green" | |
| elif (( $(echo "$COV >= 70" | bc -l) )); then | |
| COLOR="yellowgreen" | |
| elif (( $(echo "$COV >= 60" | bc -l) )); then | |
| COLOR="yellow" | |
| else | |
| COLOR="red" | |
| fi | |
| # Download badge SVG from shields.io | |
| curl -s "https://img.shields.io/badge/coverage-${COV}%25-${COLOR}" -o coverage-badge.svg | |
| - name: Push badge to badges branch | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| run: | | |
| # Save badge outside the working tree | |
| cp coverage-badge.svg /tmp/coverage-badge.svg | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git checkout --orphan badges-tmp | |
| git rm -rf . | |
| cp /tmp/coverage-badge.svg coverage-badge.svg | |
| git add coverage-badge.svg | |
| git commit -m "Update coverage badge: ${{ env.COVERAGE }}%" | |
| git push origin HEAD:badges --force | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.26' | |
| - name: golangci-lint | |
| uses: golangci/golangci-lint-action@v6 | |
| with: | |
| version: latest |