-
Notifications
You must be signed in to change notification settings - Fork 1
242 lines (230 loc) · 7.21 KB
/
test.yml
File metadata and controls
242 lines (230 loc) · 7.21 KB
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: Test
on: [push, pull_request]
jobs:
pr-title-check:
name: Check PR title
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
# Refer to https://www.conventionalcommits.org/en/v1.0.0/ for commit message convention.
- uses: amannn/action-semantic-pull-request@v3.5.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
download-module:
name: Download go module
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ^1.17.x
- name: Clone repository
uses: actions/checkout@v2
- name: Download module
run: go mod download
- uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: go-module-${{ github.repository }}-${{ github.sha }}
restore-keys: |
go-module-${{ github.repository }}-${{ github.sha }}
code-linter:
name: Lint all codes and file format
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Validate migration file's name
run: make validate.migration
- name: Format proto files using clang-format
uses: DoozyX/clang-format-lint-action@v0.11
with:
source: '.'
extensions: 'proto'
clangFormatVersion: 11
- name: Lint proto files
uses: plexsystems/protolint-action@v0.2.0
with:
configDirectory: .
- name: Lint using golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.42.1
import-linter:
name: Lint import block
if: github.event_name == 'push'
runs-on: ubuntu-latest
container:
image: indrasaputra/protogen:2021-09-07
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Check import blocks
run: |
make format
make check.import
security-checking:
name: Semgrep scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: returntocorp/semgrep-action@v1
with:
publishToken: ${{ secrets.SEMGREP_APP_TOKEN }}
unit-test:
name: Unit test and coverage
needs: [download-module, code-linter, import-linter, security-checking]
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ^1.17.x
- name: Clone repository
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: go-module-${{ github.repository }}-${{ github.sha }}
restore-keys: |
go-module-${{ github.repository }}-${{ github.sha }}
- name: Run unit test and coverage
run: make test.cover
- name: Push coverage result to Codecov
uses: codecov/codecov-action@v1.0.13
compile-binary:
name: Compile go binary
if: github.event_name == 'push'
needs: [download-module, code-linter, import-linter, security-checking]
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ^1.17.x
- name: Clone repository
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: go-module-${{ github.repository }}-${{ github.sha }}
restore-keys: |
go-module-${{ github.repository }}-${{ github.sha }}
- name: Compile go binary
run: |
make compile
- name: Upload go binary
uses: actions/upload-artifact@v2
with:
name: go-binary-toggle-${{ github.sha }}
path: toggle
retention-days: 1
build-push-toggle:
name: Build and push toggle image
if: github.event_name == 'push'
needs: [compile-binary, unit-test]
uses: indrasaputra/toggle/.github/workflows/reusable-docker.yml@main
with:
image: toggle
dockerfile: ./dockerfile/toggle.dockerfile
need-go-binary: true
secrets:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
build-push-envoy:
name: Build and push envoy image
if: github.event_name == 'push'
uses: indrasaputra/toggle/.github/workflows/reusable-docker.yml@main
with:
image: toggle-envoy
dockerfile: ./dockerfile/envoy.dockerfile
secrets:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
build-push-elements:
name: Build and push elements image
if: github.event_name == 'push'
uses: indrasaputra/toggle/.github/workflows/reusable-docker.yml@main
with:
image: toggle-elements
dockerfile: ./dockerfile/elements.dockerfile
secrets:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
integration-test:
name: Integration test
if: github.event_name == 'push'
needs: [build-push-toggle]
runs-on: ubuntu-latest
container:
image: indrasaputra/golang:2021-09-07
services:
postgres:
image: postgres:13.4-alpine
env:
POSTGRES_USER: postgresuser
POSTGRES_PASSWORD: postgrespassword
POSTGRES_DB: toggle
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:6.2-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
toggle:
image: ${{ github.repository }}:${{ github.sha }}
env:
PORT_GRPC: 8080
PORT_GRPC_GATEWAY: 8081
POSTGRES_HOST: postgres
POSTGRES_PORT: 5432
POSTGRES_USER: postgresuser
POSTGRES_PASSWORD: postgrespassword
POSTGRES_NAME: toggle
POSTGRES_MAX_OPEN_CONNS: 50
POSTGRES_MAX_CONN_LIFETIME: 10m
POSTGRES_MAX_IDLE_LIFETIME: 5m
POSTGRES_SSL_MODE: disable
REDIS_ADDRESS: redis:6379
REDIS_TTL: 5
JAEGER_ENABLED: false
ports:
- 8080:8080
- 8081:8081
options: >-
--health-cmd "./wait-for -t 4 localhost:8081"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Run integration test using godog
env:
SERVER_URL: http://toggle:8081/v1/toggles
POSTGRES_HOST: postgres
POSTGRES_PORT: 5432
POSTGRES_USER: postgresuser
POSTGRES_PASSWORD: postgrespassword
POSTGRES_NAME: toggle
POSTGRES_SSL_MODE: disable
run: |
make migrate url="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_NAME}?sslmode=${POSTGRES_SSL_MODE}"
make test.integration