File tree Expand file tree Collapse file tree 1 file changed +79
-0
lines changed
Expand file tree Collapse file tree 1 file changed +79
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Go Unit Tests
2+
3+ # Trigger the workflow on push and pull requests
4+ on :
5+ push :
6+ branches : [ main ]
7+ pull_request :
8+ branches : [ main ]
9+
10+ jobs :
11+ test :
12+ runs-on : ubuntu-latest
13+
14+ steps :
15+ # Step 1: Checkout the code
16+ - name : Checkout code
17+ uses : actions/checkout@v4
18+
19+ # Step 2: Setup Go environment
20+ - name : Set up Go
21+ uses : actions/setup-go@v4
22+ with :
23+ go-version : ' 1.24.3' # Specify your Go version
24+
25+ # Step 3: Cache Go modules for faster builds
26+ - name : Cache Go modules
27+ uses : actions/cache@v3
28+ with :
29+ path : ~/go/pkg/mod
30+ key : ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
31+ restore-keys : |
32+ ${{ runner.os }}-go-
33+
34+ # Step 4: Download dependencies
35+ - name : Download dependencies
36+ run : go mod download
37+
38+ # Step 5: Run tests
39+ - name : Run tests
40+ run : |
41+ #!/bin/bash
42+ for dir in ./services/*; do
43+ echo "Running tests in $dir"
44+ go test -v $dir/...
45+ done
46+
47+ # Step 6: Run tests with coverage
48+ - name : Run tests with coverage
49+ run : |
50+ #!/bin/bash
51+ for dir in ./services/*; do
52+ echo "Running tests with coverage in $dir"
53+ go test -v -coverprofile=coverage.out $dir/...
54+ done
55+
56+ # Step 7: Upload coverage to Codecov (optional)
57+ - name : Upload coverage to Codecov
58+ uses : codecov/codecov-action@v3
59+ with :
60+ file : ./coverage.out
61+ flags : unittests
62+ name : codecov-umbrella
63+
64+ lint :
65+ runs-on : ubuntu-latest
66+ steps :
67+ - name : Checkout code
68+ uses : actions/checkout@v4
69+
70+ - name : Set up Go
71+ uses : actions/setup-go@v4
72+ with :
73+ go-version : ' 1.24.3'
74+
75+ - name : Run golangci-lint
76+ uses : golangci/golangci-lint-action@v3
77+ with :
78+ version : latest
79+ args : --timeout=5m
You can’t perform that action at this time.
0 commit comments