Skip to content

Commit 2f1da56

Browse files
committed
added code coverage
1 parent c5bd1a9 commit 2f1da56

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Go Build, Test, and Format
1+
name: Go CI
22

33
on:
44
push:
@@ -11,8 +11,8 @@ on:
1111
- 'v[0-9]+.[0-9]+.[0-9]+'
1212

1313
jobs:
14-
build-test:
15-
name: Build and Test on ${{ matrix.os }}
14+
test-matrix:
15+
name: Test on ${{ matrix.os }}
1616
runs-on: ${{ matrix.os }}
1717
strategy:
1818
matrix:
@@ -33,10 +33,33 @@ jobs:
3333
- name: Run Tests
3434
run: go test ./...
3535

36+
coverage:
37+
name: Code Coverage
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v4
43+
44+
- name: Set up Go
45+
uses: actions/setup-go@v5
46+
with:
47+
go-version: '1.24.4'
48+
49+
- name: Run tests with coverage
50+
run: |
51+
go test -coverprofile=coverage.out ./...
52+
go tool cover -func=coverage.out
53+
54+
- name: Upload coverage artifact
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: coverage-report
58+
path: coverage.out
59+
3660
format:
37-
name: Format
61+
name: Format
3862
runs-on: ubuntu-latest
39-
if: github.event_name == 'push' # only format on push events (not PRs from forks)
4063

4164
steps:
4265
- name: Checkout code
@@ -47,16 +70,15 @@ jobs:
4770
with:
4871
go-version: '1.24.4'
4972

50-
- name: Auto-format code with gofmt and commit changes
73+
- name: Auto-format code and commit changes
5174
run: |
5275
gofmt -w .
5376
if [ -n "$(git status --porcelain)" ]; then
54-
echo "Code was not formatted. Applying gofmt and committing changes..."
77+
echo "Formatting changes detected. Committing..."
5578
git config user.name "github-actions"
5679
git config user.email "github-actions@github.com"
5780
git add .
5881
git commit -m "chore: auto-format Go code via gofmt"
5982
git push
6083
else
61-
echo "Code already properly formatted."
62-
fi
84+
echo "Code is already formatted. No changes needed."

0 commit comments

Comments
 (0)