Skip to content

Compute coverage for v2 (#13) #52

Compute coverage for v2 (#13)

Compute coverage for v2 (#13) #52

Workflow file for this run

name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
include:
- module: v1
path: .
- module: v2
path: v2
defaults:
run:
working-directory: ${{ matrix.path }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.24
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ubuntu-latest-go-1.24-${{ hashFiles(format('{0}/go.sum', matrix.path)) }}
restore-keys: |
ubuntu-latest-go-1.24-
- name: Download dependencies
run: go mod download
- name: Verify dependencies
run: go mod verify
- name: Run go vet
run: go vet ./...
- name: Run go fmt
shell: bash
run: |
unformatted=$(gofmt -s -l .)
if [ -n "$unformatted" ]; then
echo "The following files are not formatted:"
echo "$unformatted"
exit 1
fi
- name: Run tests
run: go test -v -race ./...
benchmark:
name: Benchmark
runs-on: ubuntu-latest
strategy:
matrix:
include:
- module: v1
path: .
- module: v2
path: v2
defaults:
run:
working-directory: ${{ matrix.path }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ubuntu-latest-go-1.24-${{ hashFiles(format('{0}/go.sum', matrix.path)) }}
restore-keys: |
ubunsu-latest-go-1.24-
- name: Download dependencies
run: go mod download
- name: Run benchmarks
run: go test -bench=. -benchmem -run=^$ ./...
coverage:
name: Coverage Check
runs-on: ubuntu-latest
strategy:
matrix:
include:
- module: v1
path: .
- module: v2
path: v2
defaults:
run:
working-directory: ${{ matrix.path }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ubuntu-latest-go-1.24-${{ hashFiles(format('{0}/go.sum', matrix.path)) }}
restore-keys: |
ubuntu-latest-go-1.24-
- name: Download dependencies
run: go mod download
- name: Run tests with coverage
run: go test -coverprofile=coverage.out ./...
- name: Calculate coverage
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
echo "Coverage: $COVERAGE%"
echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV
- name: Check coverage threshold
run: |
THRESHOLD=80
if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then
echo "Coverage $COVERAGE% is below threshold $THRESHOLD%"
exit 1
else
echo "Coverage $COVERAGE% meets threshold $THRESHOLD%"
fi
- name: Generate coverage report
run: go tool cover -html=coverage.out -o coverage.html
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
coverage.out
coverage.html
- name: Update coverage badge
uses: ncruces/go-coverage-report@main
with:
output-dir: ${{matrix.module}}
coverage-file: coverage.out
report: true
chart: true
amend: true
if: |
github.event_name == 'push'
continue-on-error: true
- name: Add coverage to PR comment
if: github.event_name == 'pull_request'
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
echo "## 📊 ${{matrix.module}} Coverage Report" > coverage_comment.md
echo "" >> coverage_comment.md
echo "**Total Coverage: $COVERAGE%**" >> coverage_comment.md
echo "" >> coverage_comment.md
echo "### Coverage Details" >> coverage_comment.md
echo '```' >> coverage_comment.md
go tool cover -func=coverage.out >> coverage_comment.md
echo '```' >> coverage_comment.md
# Create or update PR comment
gh pr comment ${{ github.event.number }} --body-file coverage_comment.md || \
gh pr comment ${{ github.event.number }} --body "$(cat coverage_comment.md)"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
matrix:
include:
- module: v1
path: .
- module: v2
path: v2
defaults:
run:
working-directory: ${{ matrix.path }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=5m