Skip to content

Commit 6a2846d

Browse files
feat: add CI/CD pipeline for testing Go modules and coverage reporting
1 parent aafba9b commit 6a2846d

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,65 @@ env:
1414
DOCKER_REPOSITORY: marcofontana17/cce_prototipo
1515

1616
jobs:
17+
test:
18+
runs-on: ubuntu-latest
19+
name: Run Tests
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: '1.24'
29+
check-latest: true
30+
31+
- name: Cache Go modules
32+
uses: actions/cache@v4
33+
with:
34+
path: |
35+
~/.cache/go-build
36+
~/go/pkg/mod
37+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
38+
restore-keys: |
39+
${{ runner.os }}-go-
40+
41+
- name: Download dependencies
42+
run: go mod download
43+
44+
- name: Verify dependencies
45+
run: go mod verify
46+
47+
- name: Run tests
48+
run: go test -v ./...
49+
50+
- name: Run tests with race detector
51+
run: go test -race -short ./...
52+
53+
- name: Run tests with coverage
54+
run: go test -coverprofile=coverage.out ./...
55+
56+
- name: Display coverage report
57+
run: go tool cover -func=coverage.out
58+
59+
- name: Check test coverage threshold
60+
run: |
61+
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
62+
echo "Total coverage: ${COVERAGE}%"
63+
64+
# - name: Upload coverage to Codecov (optional)
65+
# uses: codecov/codecov-action@v4
66+
# with:
67+
# file: ./coverage.out
68+
# flags: unittests
69+
# name: codecov-umbrella
70+
# continue-on-error: true
71+
1772
build-and-push:
1873
runs-on: ubuntu-latest
1974
name: Build and Push Docker Images
75+
needs: test
2076

2177
strategy:
2278
matrix:

0 commit comments

Comments
 (0)