-
Notifications
You must be signed in to change notification settings - Fork 23
177 lines (152 loc) Β· 5.68 KB
/
ci.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
name: Go
on:
push:
branches:
- main
pull_request:
workflow_call: # allows this workflow to be called from another workflow
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.1
cache: true
cache-dependency-path: go.sum
- name: golangci-lint
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # version v6.1.1
with:
version: v1.56.2 # this is the golangci-lint version
args: --timeout 5m0s
- name: Run ./gomod.sh
run: ./gomod.sh
run: |
go install github.com/nishanths/exhaustive/cmd/[email protected]
go install golang.org/x/tools/cmd/[email protected]
go install golang.org/x/tools/cmd/[email protected]
- name: Run `exhaustive`
run: exhaustive -default-signifies-exhaustive ./...
- name: Run `deadcode`
run: |
output=$(deadcode -test ./...)
if [[ -n "$output" ]]; then
echo "π¨ Deadcode found:"
echo "$output"
exit 1
else
echo "β
No deadcode found"
fi
- name: Run `goimports`
run: |
# Find all .go files excluding paths containing 'mock' and run goimports
non_compliant_files=$(find . -type f -name "*.go" ! -path "*mock*" | xargs goimports -local "github.com/stellar/stellar-disbursement-platform-backend" -l)
if [ -n "$non_compliant_files" ]; then
echo "π¨ The following files are not compliant with goimports:"
echo "$non_compliant_files"
exit 1
else
echo "β
All files are compliant with goimports."
fi
check-helm-readme:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install NodeJs
uses: actions/setup-node@v4
with:
node-version: 14
- name: Install Helm Readme Generator (@bitnami/readme-generator-for-helm)
run: npm install -g @bitnami/readme-generator-for-helm
- name: Generate README.md for comparison
run: readme-generator -v helmchart/sdp/values.yaml -r helmchart/sdp/README.md
- name: Check if helmchart/sdp/README.md is in sync with helmchart/sdp/values.yaml
run: |
if git diff --exit-code --stat helmchart/sdp/README.md; then
echo "β
helmchart/sdp/README.md is in sync with helmchart/sdp/values.yaml"
else
echo "π¨ helmchart/sdp/README.md needs to be re-generated!"
echo "Run 'readme-generator -v helmchart/sdp/values.yaml -r helmchart/sdp/README.md' locally and commit the changes."
echo "Refer to https://github.com/bitnami/readme-generator-for-helm for more information."
exit 1
fi
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.1
cache: true
cache-dependency-path: go.sum
- name: Build Project
run: go build ./...
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12-alpine
env:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
PGHOST: localhost
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
env:
PGHOST: localhost
PGPORT: 5432
PGUSER: postgres
PGPASSWORD: postgres
PGDATABASE: postgres
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22.1
cache: true
cache-dependency-path: go.sum
- name: Install [email protected]
run: go install gotest.tools/[email protected]
- name: Run tests
run: gotestsum --format-hide-empty-pkg --format pkgname-and-test-fails -- -coverprofile=c.out ./... -timeout 3m -coverpkg ./...
- name: Validate Test Coverage Threshold
env:
TESTCOVERAGE_THRESHOLD: 84 # percentage
run: |
echo "Quality Gate: Checking if test coverage is above threshold..."
echo "Threshold: $TESTCOVERAGE_THRESHOLD%"
totalCoverage=`./scripts/exclude_from_coverage.sh && go tool cover -func=c.out | grep total: | grep -Eo '[0-9]+\.[0-9]+'`
echo "Test Coverage: $totalCoverage%"
echo "-------------------------"
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 >= $2)}') )); then
echo " $totalCoverage% > $TESTCOVERAGE_THRESHOLD%"
echo "Current test coverage is above threshold πππ! Please keep up the good work!"
else
echo " $totalCoverage% < $TESTCOVERAGE_THRESHOLD%"
echo "π¨ Current test coverage is below threshold π±! Please add more unit tests or adjust threshold to a lower value."
echo "Failed π"
exit 1
fi
complete:
if: always()
needs: [check, check-helm-readme, build, test]
runs-on: ubuntu-latest
steps:
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1