Skip to content

Commit 0d51eae

Browse files
aryanmehrotraaryan-mehrotra-zsvipul-rawat-zsUmang01-hash
authored
Fix/gofr (#180)
* Update Workflow * Fixed Linters * Fixed Tests * Update to latest go version * Update module name --------- Co-authored-by: aryan-mehrotra-zs <[email protected]> Co-authored-by: vipul-rawat-zs <[email protected]> Co-authored-by: umang01-hash <[email protected]>
1 parent 64a375b commit 0d51eae

37 files changed

+380
-241
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/workflows/changes.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
filename="$1"
4+
5+
# Create or clear the coveragetable.md file
6+
touch build/coveragetable.md
7+
8+
# Append total coverage information to coveragetable.md
9+
echo -n "### Total coverage : " >> build/coveragetable.md
10+
# Filter and assign files to trimmed_content based on conditions:
11+
# - Files ending with ".go" are considered.
12+
# - Files with status "A" or "M" are included.
13+
# - Files with status "RXXX" are included, except for "R100".
14+
go tool cover -func build/coverage.out | grep 'total' | awk '{print $3}' >> build/coveragetable.md
15+
16+
# Extract changed file paths from the provided file
17+
trimmed_content=$(grep -E '\.go$' "$filename" | awk '{ if ($1 ~ /^R/ && $1 !~ /^R100/) print $3; else if ($1 ~ /^[AM]/) print $2 }')
18+
19+
if [[ -z "$trimmed_content" ]]; then
20+
echo "### No Files Are Changed." >> build/coveragetable.md
21+
else
22+
echo "List of changed files" >> build/coveragetable.md
23+
echo -e "\n" >> build/coveragetable.md
24+
echo "| Path | Function | Coverage |" >> build/coveragetable.md
25+
echo "|------|----------|----------|" >> build/coveragetable.md
26+
27+
while IFS= read -r line; do
28+
echo "$line"
29+
if [[ $line == *.go ]]; then
30+
# Extract coverage information for each changed file and append to coveragetable.md
31+
go tool cover -func=build/coverage.out | grep "$line" | awk 'BEGIN{OFS=" | "} {print "|" $1, $2, $3 "|"}' >> build/coveragetable.md
32+
fi
33+
done <<< "$trimmed_content"
34+
fi
35+
36+
# Append the content of coveragetable.md to the GITHUB_STEP_SUMMARY file
37+
cat build/coveragetable.md >> "$GITHUB_STEP_SUMMARY"

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

.github/workflows/go.yml

Lines changed: 159 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,178 @@
1-
name: Go
1+
name: Workflow-Pipeline
22

33
on:
44
push:
5-
branches: [ "main", "dev"]
5+
branches:
6+
- main
7+
- development
68
pull_request:
7-
branches: [ "main", "dev"]
9+
branches:
10+
- main
11+
- development
812

913
jobs:
10-
test:
11-
name: Test
14+
Example-Unit-Testing:
15+
name: Example Unit Testing🛠
1216
runs-on: ubuntu-latest
1317
services:
1418
redis:
15-
image: redis
19+
image: redis:7.0.5
1620
ports:
17-
- 6379:6379
18-
options: --entrypoint redis-server
21+
- "6379:6379"
22+
options: "--entrypoint redis-server"
23+
1924
mysql:
20-
image: mysql
25+
image: mysql:8.0.30
2126
ports:
22-
- 3306:3306
27+
- "3306:3306"
2328
env:
24-
MYSQL_ROOT_PASSWORD: password
25-
MYSQL_DATABASE: test
29+
MYSQL_ROOT_PASSWORD: "password"
30+
MYSQL_DATABASE: "test"
2631

2732
steps:
28-
- name: Set up Go 1.x
29-
uses: actions/setup-go@v2
30-
with:
31-
go-version: ^1.13
32-
id: go
33-
34-
- name: Check out code into the Go module directory
35-
uses: actions/checkout@v2
36-
37-
- name: Get dependencies
38-
run: |
39-
go get -v -t -d ./...
40-
41-
- name: Test
42-
run: |
43-
go test ./... -v -coverprofile profile.cov -coverpkg=./...
44-
go tool cover -func profile.cov
45-
46-
- name: Send coverage to coveralls
47-
uses: shogo82148/actions-goveralls@v1
48-
with:
49-
path-to-profile: profile.cov
50-
parallel: true
51-
52-
- name: Send coverage to CodeClimate
53-
uses: paambaati/[email protected]
54-
env:
55-
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
56-
with:
57-
debug: true
58-
coverageLocations: profile.cov:gocov
59-
prefix: github.com/vikash/gofr
60-
61-
code_quality:
62-
name: Code Quality
33+
- name: Checkout code into go module directory
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Set up Go 1.21
39+
uses: actions/setup-go@v4
40+
with:
41+
go-version: 1.21
42+
id: Go
43+
44+
- name: Get dependencies
45+
run: |
46+
go mod download
47+
48+
- name: Test
49+
run: |
50+
export GOFR_ENV=test
51+
go test gofr.dev/examples/... -v -short -coverprofile profile.cov -coverpkg=gofr.dev/examples/...
52+
go tool cover -func profile.cov
53+
54+
- name: Upload Test Coverage
55+
uses: actions/upload-artifact@v3
56+
with:
57+
name: Example-Test-Report
58+
path: profile.cov
59+
60+
PKG-Unit-Testing:
61+
name: PKG Unit Testing🛠
62+
runs-on: ubuntu-latest
63+
services:
64+
mysql:
65+
image: mysql:8.0.30
66+
ports:
67+
- "3306:3306"
68+
env:
69+
MYSQL_ROOT_PASSWORD: "password"
70+
71+
redis:
72+
image: redis:7.0.5
73+
ports:
74+
- "6379:6379"
75+
options: "--entrypoint redis-server"
76+
77+
steps:
78+
- name: Checkout code into go module directory
79+
uses: actions/checkout@v4
80+
with:
81+
fetch-depth: 0
82+
83+
- name: Set up Go 1.21
84+
uses: actions/setup-go@v4
85+
with:
86+
go-version: 1.21
87+
id: Go
88+
89+
- name: Get dependencies
90+
run: |
91+
go mod download
92+
93+
- name: Test
94+
run: |
95+
export GOFR_ENV=test
96+
go test gofr.dev/pkg/... -v -short -coverprofile profile.cov -coverpkg=gofr.dev/pkg/...
97+
go tool cover -func profile.cov
98+
99+
- name: Upload Test Coverage
100+
uses: actions/upload-artifact@v3
101+
with:
102+
name: PKG-Coverage-Report
103+
path: profile.cov
104+
105+
parse_coverage:
106+
name: Code Coverage
63107
runs-on: ubuntu-latest
64-
container: golangci/golangci-lint:v1.37.1
108+
needs: [Example-Unit-Testing,PKG-Unit-Testing]
65109
steps:
66-
- name: Checkout code
67-
uses: actions/checkout@v2
110+
- name: Check out code into the Go module directory
111+
uses: actions/checkout@v4
112+
113+
- name: Download Coverage Report
114+
uses: actions/download-artifact@v3
115+
with:
116+
path: artifacts
68117

69-
- name: golangci-lint
118+
- name: Merge Coverage Files
119+
working-directory: artifacts
120+
run: |
121+
awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./Example-Test-Report/profile.cov > merged_profile.cov
122+
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
123+
124+
- name: Parse code-coverage value
125+
working-directory: artifacts
126+
run: |
127+
codeCoverage=$(go tool cover -func=merged_profile.cov | grep total | awk '{print $3}')
128+
codeCoverage=${codeCoverage%?}
129+
echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV
130+
131+
# - name: Check if code-coverage is greater than threshold
132+
# run: |
133+
# codeCoverage=${{ env.CODE_COVERAGE }}
134+
# codeCoverage=${codeCoverage%??}
135+
# if [[ $codeCoverage -lt 92 ]]; then echo "code coverage cannot be less than 92%, currently its ${{ env.CODE_COVERAGE }}%" && exit 1; fi;
136+
137+
upload_coverage:
138+
name: Upload Coverage📊
139+
runs-on: ubuntu-latest
140+
needs: [Example-Unit-Testing,PKG-Unit-Testing]
141+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }}
142+
steps:
143+
- name: Check out code into the Go module directory
144+
uses: actions/checkout@v4
145+
146+
- name: Download Coverage Report
147+
uses: actions/download-artifact@v3
148+
with:
149+
path: artifacts
150+
151+
- name: Merge Coverage Files
152+
working-directory: artifacts
153+
run: |
154+
awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./CMD-Test-Report/profile.cov > merged_profile.cov
155+
tail -n +2 ./Example-Test-Report/profile.cov >> merged_profile.cov
156+
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
157+
158+
159+
- name: Upload
160+
uses: paambaati/[email protected]
161+
env:
162+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
163+
with:
164+
coverageLocations: artifacts/merged_profile.cov:gocov
165+
prefix: gofr.dev
166+
167+
code_quality:
168+
name: Code Quality🎖️
169+
runs-on: ubuntu-latest
170+
container: "golangci/golangci-lint:v1.55.2"
171+
steps:
172+
- name: Check out code into the Go module directory
173+
uses: actions/checkout@v4
174+
- name: Get dependencies
175+
run: go get -v -t -d ./...
176+
- name: GolangCI-Lint
70177
run: |
71-
golangci-lint run
178+
golangci-lint run --timeout 9m0s

.golangci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ linters-settings:
77
lines: 100
88
statements: 50
99
gci:
10-
local-prefixes: github.com/vikash/gofr
10+
local-prefixes: gofr.dev
1111
goconst:
1212
min-len: 2
1313
min-occurrences: 2
@@ -40,8 +40,8 @@ linters-settings:
4040
settings:
4141
printf:
4242
funcs:
43-
- (github.com/vikash/gofr/pkg/gofr/Logger).Logf
44-
- (github.com/vikash/gofr/pkg/gofr/Logger).Errorf
43+
- (gofr.dev/pkg/gofr/Logger).Logf
44+
- (gofr.dev/pkg/gofr/Logger).Errorf
4545
lll:
4646
line-length: 140
4747
maligned:
@@ -62,7 +62,6 @@ linters:
6262
- asciicheck
6363
- bodyclose
6464
- deadcode
65-
- depguard
6665
- dogsled
6766
- dupl
6867
- errcheck

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
FROM golang:1.16
22

3-
RUN mkdir -p /go/src/github.com/vikash/gofr
4-
WORKDIR /go/src/github.com/vikash/gofr
3+
RUN mkdir -p /go/src/gofr.dev
4+
WORKDIR /go/src/gofr.dev
55
COPY . .
66

77
RUN go build -ldflags "-linkmode external -extldflags -static" -a examples/simple-api/main.go
88

99
FROM alpine:latest
1010
RUN apk add --no-cache tzdata ca-certificates
11-
COPY --from=0 /go/src/github.com/vikash/gofr/main /main
11+
COPY --from=0 /go/src/gofr.dev/main /main
1212
EXPOSE 8000
1313
CMD ["/main"]

0 commit comments

Comments
 (0)