-
Notifications
You must be signed in to change notification settings - Fork 232
211 lines (182 loc) · 6.1 KB
/
go.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
---
name: Workflow-Pipeline
on:
push:
branches:
- main
- development
paths-ignore:
- 'docs/**'
pull_request:
branches:
- main
- development
paths-ignore:
- 'docs/**'
jobs:
Example-Unit-Testing:
name: Example Unit Testing (v${{ matrix.go-version }})🛠
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.22', '1.21']
services:
kafka:
image: bitnami/kafka:3.4
ports:
- "9092:9092"
env:
KAFKA_ENABLE_KRAFT: yes
KAFKA_CFG_PROCESS_ROLES: broker,controller
KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_CFG_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:9092
KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true
KAFKA_BROKER_ID: 1
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: [email protected]:9093
ALLOW_PLAINTEXT_LISTENER: yes
KAFKA_CFG_NODE_ID: 1
redis:
image: redis:7.0.5
ports:
- "2002:6379"
options: "--entrypoint redis-server"
mysql:
image: mysql:8.2.0
ports:
- "2001:3306"
env:
MYSQL_ROOT_PASSWORD: "password"
MYSQL_DATABASE: "test"
steps:
- name: Checkout code into go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
id: Go
- name: Get dependencies
run: |
go mod download
- name: Start Zipkin
run: docker run -d -p 2005:9411 openzipkin/zipkin:latest
- name: Test
run: |
export APP_ENV=test
go test gofr.dev/examples/... -v -short -coverprofile packageWithpbgo.cov -coverpkg=gofr.dev/examples/...
grep -vE '^gofr\.dev\/.*\.pb\.go' packageWithpbgo.cov > profile.cov
go tool cover -func profile.cov
- name: Upload Test Coverage
if: ${{ matrix.go-version == '1.22'}}
uses: actions/upload-artifact@v4
with:
name: Example-Test-Report
path: profile.cov
PKG-Unit-Testing:
name: PKG Unit Testing (v${{ matrix.go-version }})🛠
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.22', '1.21']
steps:
- name: Checkout code into go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
id: Go
- name: Get dependencies
run: |
go mod download
- name: Test
run: |
export APP_ENV=test
go test gofr.dev/pkg/... -v -short -coverprofile package.cov -coverpkg=gofr.dev/pkg/...
grep -v '/mock_' package.cov > profile.cov
go tool cover -func profile.cov
- name: Upload Test Coverage
if: ${{ matrix.go-version == '1.22'}}
uses: actions/upload-artifact@v4
with:
name: PKG-Coverage-Report
path: profile.cov
parse_coverage:
name: Code Coverage
runs-on: ubuntu-latest
needs: [ Example-Unit-Testing,PKG-Unit-Testing]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Download Coverage Report
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Merge Coverage Files
working-directory: artifacts
run: |
awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./Example-Test-Report/profile.cov > merged_profile.cov
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
- name: Parse code-coverage value
working-directory: artifacts
run: |
codeCoverage=$(go tool cover -func=merged_profile.cov | grep total | awk '{print $3}')
codeCoverage=${codeCoverage%?}
echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV
# - name: Check if code-coverage is greater than threshold
# run: |
# codeCoverage=${{ env.CODE_COVERAGE }}
# codeCoverage=${codeCoverage%??}
# if [[ $codeCoverage -lt 92 ]]; then echo "code coverage cannot be less than 92%, currently its ${{ env.CODE_COVERAGE }}%" && exit 1; fi;
upload_coverage:
name: Upload Coverage📊
runs-on: ubuntu-latest
needs: [Example-Unit-Testing,PKG-Unit-Testing]
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development'}}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Download Coverage Report
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Merge Coverage Files
working-directory: artifacts
run: |
awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./Example-Test-Report/profile.cov > merged_profile.cov
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
- name: Upload
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageLocations: artifacts/merged_profile.cov:gocov
prefix: gofr.dev
code_quality:
name: Code Quality🎖️
runs-on: ubuntu-latest
container: "golangci/golangci-lint:v1.59.1"
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Get dependencies
run: go get -v -t -d ./...
- name: GolangCI-Lint
run: |
golangci-lint run --timeout 9m0s
linting_party:
name: Linting Party🥳
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Check for file names errors
uses: ls-lint/[email protected]
with:
config: .ls-lint.yml