forked from LambdaTest/test-at-scale
-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (111 loc) · 3.95 KB
/
main.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
name: Go report card & Test coverage
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
Unit_Test_Cases:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Checkout code
uses: actions/checkout@v2
- name: Unit Test Cases
env:
ENV: "dev"
run: go test ./... -parallel 4
Performance_Test_Cases:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Checkout code
uses: actions/checkout@v2
- name: Performance Test Cases
env:
ENV: "dev"
run: go test ./... -parallel 4 -bench=. -benchmem
Test_Coverage:
runs-on: ubuntu-latest
needs: [ Unit_Test_Cases, Performance_Test_Cases ]
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Checkout code
uses: actions/checkout@v2
- name: Test Code Coverage
env:
ENV: "dev"
run: |
go test -parallel 4 -coverpkg=./... -coverprofile=profile.cov ./...
go tool cover -func profile.cov
Go_Report_Card:
runs-on: ubuntu-latest
needs: [ Unit_Test_Cases, Performance_Test_Cases ]
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Checkout code
uses: actions/checkout@v2
- name: Run Go Report Card
run: |
issues_threshold=13
gofmt_score_threshold=100
go_vet_score_threshold=100
golint_score_threshold=98
gocyclo_score_threshold=91
git clone https://github.com/gojp/goreportcard.git
cd goreportcard
make install
go install ./cmd/goreportcard-cli
cd ..
rm -rf goreportcard
goreportcard-cli | tee reportcard.txt
files=$(cat reportcard.txt| grep 'Files:' | awk '{print $2}' | tr -d \%)
issues=$(cat reportcard.txt| grep 'Issues:' | awk '{print $2}' | tr -d \%)
gofmt_score=$(cat reportcard.txt| grep 'gofmt:' | awk '{print $2}' | tr -d \%)
go_vet_score=$(cat reportcard.txt| grep 'go_vet:' | awk '{print $2}' | tr -d \%)
golint_score=$(cat reportcard.txt| grep 'golint:' | awk '{print $2}' | tr -d \%)
gocyclo_score=$(cat reportcard.txt| grep 'gocyclo:' | awk '{print $2}' | tr -d \%)
rm reportcard.txt
failed_checks=0
failure_reason=""
if [[ $issues -gt $issues_threshold ]]; then
failure_reason="${failure_reason}\nIssues: $issues. Threshold was: $issues_threshold."
((failed_checks+=1))
fi
if [[ $gofmt_score -lt $gofmt_score_threshold ]]; then
failure_reason="${failure_reason}\ngo-fmt score: $gofmt_score. Threshold was: $gofmt_score_threshold."
((failed_checks+=1))
fi
if [[ $go_vet_score -lt $go_vet_score_threshold ]]; then
failure_reason="${failure_reason}\ngo-vet score: $go_vet_score. Threshold was: $go_vet_score_threshold."
((failed_checks+=1))
fi
if [[ $golint_score -lt $golint_score_threshold ]]; then
failure_reason="${failure_reason}\ngo-lint score: $golint_score. Threshold was: $golint_score_threshold."
((failed_checks+=1))
fi
if [[ $gocyclo_score -lt $gocyclo_score_threshold ]]; then
failure_reason="${failure_reason}\ngo-cyclo score: $gocyclo_score. Threshold was: $gocyclo_score_threshold."
((failed_checks+=1))
fi
if [[ $failed_checks -gt 0 ]]; then
goreportcard-cli -v
printf "\n\n\n${failure_reason}\nFrom the above output, filter out issues in your touched files and fix them."
exit 1
else
exit 0
fi