Skip to content

Commit 0d2e0f4

Browse files
committed
feat(workflows): Add test.yml for testing and linting automation every push to main
1 parent c7ce837 commit 0d2e0f4

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

.github/workflows/test.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

0 commit comments

Comments
 (0)