diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a98bfa8..382dd52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Go Build, Test, and Format +name: Go CI on: push: @@ -12,7 +12,7 @@ on: jobs: build-test: - name: Build and Test on ${{ matrix.os }} + name: Build, Test & Coverage on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: matrix: @@ -30,13 +30,23 @@ jobs: - name: Build run: go build ./... - - name: Run Tests - run: go test ./... + - name: Run Tests with Coverage + run: | + go test -coverprofile=coverage.out ./... + go tool cover -func=coverage.out + shell: bash + + - name: Upload coverage report + if: matrix.os == 'ubuntu-latest' + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage.out format: - name: Format + name: Auto-format with gofmt (Linux only) runs-on: ubuntu-latest - if: github.event_name == 'push' # only format on push events (not PRs from forks) + if: github.event_name == 'push' && github.repository_owner == github.actor steps: - name: Checkout code @@ -47,11 +57,11 @@ jobs: with: go-version: '1.24.4' - - name: Auto-format code with gofmt and commit changes + - name: Run gofmt and commit changes if needed run: | gofmt -w . if [ -n "$(git status --porcelain)" ]; then - echo "Code was not formatted. Applying gofmt and committing changes..." + echo "Code was not formatted. Committing changes..." git config user.name "github-actions" git config user.email "github-actions@github.com" git add .