fix: library improvements - bug fixes, tests, and coverage badge (#19) #64
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, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| go-version: ['1.21', '1.22', '1.23', '1.24'] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Set up Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| check-latest: true | |
| - name: Cache Go modules | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum', '**/go.mod') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go-${{ matrix.go-version }}- | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Run go vet | |
| run: go vet ./... | |
| - name: Check formatting | |
| run: | | |
| if [ "$(gofmt -s -l . | grep -v vendor | wc -l)" -gt 0 ]; then | |
| echo "Code is not formatted. Please run 'go fmt ./...'" | |
| gofmt -s -l . | grep -v vendor | |
| exit 1 | |
| fi | |
| - name: Run tests with coverage | |
| run: go test -short -race -coverprofile=coverage.out ./... | |
| - name: Extract coverage percentage | |
| if: github.ref == 'refs/heads/main' && matrix.go-version == '1.24' | |
| id: coverage | |
| run: | | |
| COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | tr -d '%') | |
| echo "percentage=$COVERAGE" >> "$GITHUB_OUTPUT" | |
| - name: Update coverage badge | |
| if: github.ref == 'refs/heads/main' && matrix.go-version == '1.24' | |
| uses: schneegans/dynamic-badges-action@v1.7.0 | |
| with: | |
| auth: ${{ secrets.GIST_TOKEN }} | |
| gistID: 2c608589294aed9aa900256daeec0fd4 | |
| filename: coverage.json | |
| label: coverage | |
| message: ${{ steps.coverage.outputs.percentage }}% | |
| valColorRange: ${{ steps.coverage.outputs.percentage }} | |
| minColorRange: 40 | |
| maxColorRange: 90 |