File tree Expand file tree Collapse file tree 1 file changed +18
-8
lines changed
Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change 1- name : Go Build, Test, and Format
1+ name : Go CI
22
33on :
44 push :
1212
1313jobs :
1414 build-test :
15- name : Build and Test on ${{ matrix.os }}
15+ name : Build, Test & Coverage on ${{ matrix.os }}
1616 runs-on : ${{ matrix.os }}
1717 strategy :
1818 matrix :
@@ -30,13 +30,23 @@ jobs:
3030 - name : Build
3131 run : go build ./...
3232
33- - name : Run Tests
34- run : go test ./...
33+ - name : Run Tests with Coverage
34+ run : |
35+ go test -coverprofile=coverage.out ./...
36+ go tool cover -func=coverage.out
37+ shell : bash
38+
39+ - name : Upload coverage report
40+ if : matrix.os == 'ubuntu-latest'
41+ uses : actions/upload-artifact@v4
42+ with :
43+ name : coverage-report
44+ path : coverage.out
3545
3646 format :
37- name : Format
47+ name : Auto-format with gofmt (Linux only)
3848 runs-on : ubuntu-latest
39- if : github.event_name == 'push' # only format on push events (not PRs from forks)
49+ if : github.event_name == 'push' && github.repository_owner == github.actor
4050
4151 steps :
4252 - name : Checkout code
@@ -47,11 +57,11 @@ jobs:
4757 with :
4858 go-version : ' 1.24.4'
4959
50- - name : Auto-format code with gofmt and commit changes
60+ - name : Run gofmt and commit changes if needed
5161 run : |
5262 gofmt -w .
5363 if [ -n "$(git status --porcelain)" ]; then
54- echo "Code was not formatted. Applying gofmt and committing changes..."
64+ echo "Code was not formatted. Committing changes..."
5565 git config user.name "github-actions"
5666 git config user.email "github-actions@github.com"
5767 git add .
You can’t perform that action at this time.
0 commit comments