11name : Go Unit Tests
22
3- # Trigger the workflow on push and pull requests
43on :
54 push :
65 branches : [ main ]
@@ -12,48 +11,36 @@ jobs:
1211 runs-on : ubuntu-latest
1312
1413 steps :
15- # Step 1: Checkout the code
1614 - name : Checkout code
1715 uses : actions/checkout@v4
18-
19- # Step 2: Setup Go environment
16+
2017 - name : Set up Go
2118 uses : actions/setup-go@v4
2219 with :
23- go-version : ' 1.24.3' # Specify your Go version
24-
25- # Step 3: Cache Go modules for faster builds
20+ go-version : ' 1.24.3'
21+
2622 - name : Cache Go modules
2723 uses : actions/cache@v3
2824 with :
2925 path : ~/go/pkg/mod
30- key : ${{ runner.os }}-go-${{ hashFiles('services/bounty-service/go.sum', 'services/bounty-service/go.mod' ) }}
26+ key : ${{ runner.os }}-go-${{ hashFiles('services/bounty-service/go.sum') }}
3127 restore-keys : |
3228 ${{ runner.os }}-go-
33-
34- # Step 4: Download dependencies
29+
3530 - name : Download dependencies
31+ working-directory : services/bounty-service
3632 run : go mod download
37-
38- # Step 5: Run tests
33+
3934 - 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
35+ working-directory : services/bounty-service
36+ run : go test -v ./...
37+
4838 - name : Run tests with coverage
39+ working-directory : services/bounty-service
4940 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)
41+ go test -v -coverprofile=coverage.out ./...
42+ mv coverage.out ${{ github.workspace }}/coverage.out
43+
5744 - name : Upload coverage to Codecov
5845 uses : codecov/codecov-action@v3
5946 with :
7663 uses : golangci/golangci-lint-action@v3
7764 with :
7865 version : latest
66+ working-directory : services/bounty-service
7967 args : --timeout=5m
0 commit comments