-
-
Notifications
You must be signed in to change notification settings - Fork 147
235 lines (187 loc) · 7.13 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
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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
paths-ignore:
- "api/docs/**"
- "build/charts/**"
- "design/**"
- "**/*.md"
- "**/*.txt"
- "**/.gitignore"
env:
GO_VERSION: "1.23"
jobs:
ci-target-check:
runs-on: ubuntu-latest
outputs:
build: ${{ steps.ci-target-check.outputs.build }}
bench: ${{ steps.ci-target-check.outputs.bench }}
complex-test: ${{ steps.ci-target-check.outputs.complex-test }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: CI target check by path
uses: dorny/paths-filter@v3
id: ci-target-check
with:
filters: |
build: '**'
bench:
- 'test/bench/**'
- 'pkg/**'
- 'server/**'
- 'client/**'
- 'admin/**'
- 'api/converter/**'
complex-test:
- 'test/complex/**'
- 'server/backend/database/**'
- 'pkg/document/**'
- 'client/**'
build:
name: build
runs-on: ubuntu-latest
needs: ci-target-check
if: ${{ github.ref == 'refs/heads/main' || needs.ci-target-check.outputs.build == 'true' }}
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Setup buf action
uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ github.token }}
- name: Check out code
uses: actions/checkout@v4
- name: Get tools dependencies
run: make tools
- name: Lint
run: make lint
- name: Lint proto files
uses: bufbuild/buf-lint-action@v1
- name: Build
run: make build
- name: Stack
run: docker compose -f build/docker/docker-compose.yml up --build -d
- name: Test
run: go test -tags integration -race -coverprofile=coverage.txt -covermode=atomic -v ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
bench:
name: bench
runs-on: ubuntu-latest
permissions: write-all
needs: ci-target-check
if: ${{ github.ref == 'refs/heads/main' || needs.ci-target-check.outputs.bench == 'true' }}
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Checkout current repository
uses: actions/checkout@v4
with:
path: repo
- name: Checkout benchmark branch
uses: actions/checkout@v4
with:
ref: yorkie-ci-benchmark
path: benchmark-repo
continue-on-error: true
- name: Read previous benchmark result
if: github.event_name == 'pull_request'
id: prev-bench
run: |
echo "PREV_BENCH_RESULT=null" >> $GITHUB_OUTPUT
echo "PREV_COMMIT=null" >> $GITHUB_OUTPUT
if [ -d "benchmark-repo" ] && [ -f "benchmark-repo/bench_result.txt" ]; then
content=$(cat benchmark-repo/bench_result.txt | jq -R -s .)
echo "PREV_BENCH_RESULT=$content" >> $GITHUB_OUTPUT
if [ -f "benchmark-repo/commit_hash.txt" ]; then
prev_commit=$(cat benchmark-repo/commit_hash.txt)
echo "PREV_COMMIT=$prev_commit" >> $GITHUB_OUTPUT
fi
fi
- name: Stack
run: docker compose -f repo/build/docker/docker-compose.yml up --build -d
- name: Bench
id: curr-bench
run: |
cd repo
make bench
content=$(cat output.txt | jq -R -s .)
echo "BENCH_RESULT=$content" >> $GITHUB_OUTPUT
- name: Trigger n8n webhook
if: github.event_name == 'pull_request'
run: |
curr_bench=$(cat output.txt | jq -R -s .)
response=$(curl -f -X POST ${{ secrets.N8N_WEBHOOK_URL }} \
-H "Content-Type: application/json" \
-d '{
"repo": "${{ github.repository }}",
"pr_number": "${{ github.event.pull_request.number }}",
"commit_id": "${{ github.sha }}",
"prev_commit_id": "${{ steps.prev-bench.outputs.PREV_COMMIT }}",
"bench_result": ${{ steps.curr-bench.outputs.BENCH_RESULT }},
"prev_bench_result": ${{ steps.prev-bench.outputs.PREV_BENCH_RESULT }}
}' || echo "CURL_ERROR")
if [ "$response" = "CURL_ERROR" ]; then
echo "::error::Failed to trigger n8n webhook"
exit 1
fi
- name: Store benchmark result
if: github.ref == 'refs/heads/main'
run: |
mkdir -p benchmark-repo
cp repo/output.txt benchmark-repo/bench_result.txt
echo "${{ github.sha }}" > benchmark-repo/commit_hash.txt
cd benchmark-repo
git config user.name "GitHub Actions"
git config user.email "[email protected]"
if [ ! -d ".git" ]; then
git init
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
fi
git add bench_result.txt
git add commit_hash.txt
TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
git diff --staged --quiet || git commit -m "Update benchmark results at $TIMESTAMP"
git checkout -B yorkie-ci-benchmark
git push -f origin yorkie-ci-benchmark
echo "Benchmark results have been pushed to yorkie-ci-benchmark branch"
complex-test:
name: complex-test
runs-on: ubuntu-latest
needs: ci-target-check
if: ${{ github.ref == 'refs/heads/main' || needs.ci-target-check.outputs.complex-test == 'true' }}
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Check out code
uses: actions/checkout@v4
- name: Check Docker Compose Version
run: docker compose --version
- name: Run the Config server, Shard 1 and Shard 2
run: docker compose -f build/docker/sharding/docker-compose.yml up --build -d --wait config1 shard1-1 shard2-1
- name: Initialize the Config server
run: docker compose -f build/docker/sharding/docker-compose.yml exec config1 mongosh test /scripts/init-config1.js
- name: Initialize the Shard 1
run: docker compose -f build/docker/sharding/docker-compose.yml exec shard1-1 mongosh test /scripts/init-shard1-1.js
- name: Initialize the Shard 2
run: docker compose -f build/docker/sharding/docker-compose.yml exec shard2-1 mongosh test /scripts/init-shard2-1.js
- name: Run the Mongos
run: docker compose -f build/docker/sharding/docker-compose.yml up --build -d --wait mongos1
- name: Initialize the Mongos
run: docker compose -f build/docker/sharding/docker-compose.yml exec mongos1 mongosh test /scripts/init-mongos1.js
- name: Run the tests with complex tag
run: go test -tags complex -race -v ./test/complex/...